The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[BREAKING_CHANGE] feat(billing): move billing plans config to BILLING_PLANS (#28552)
Etienne2f1857d4cec6
diff --git a/.github/workflows/ci-server.yaml b/.github/workflows/ci-server.yamlindex f3c5acf5b09..9fd93632688 100644--- a/.github/workflows/ci-server.yaml+++ b/.github/workflows/ci-server.yaml@@ -337,6 +337,7 @@ jobs:echo "BILLING_STRIPE_BASE_PLAN_PRODUCT_ID=test-base-plan-product-id" >> .env.testecho "BILLING_STRIPE_WEBHOOK_SECRET=test-webhook-secret" >> .env.testecho "BILLING_PLAN_REQUIRED_LINK=http://localhost:3001/stripe-redirection" >> .env.test+ echo 'BILLING_PLANS={"PRO":{"isDefault":true,"upgradePlanKeys":["ENTERPRISE"]},"ENTERPRISE":{"downgradePlanKeys":["PRO"]}}' >> .env.test- name: Restore server build cacheuses: ./.github/actions/restore-cachewith:diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphqlindex c62ba1b5ca0..f901251fb32 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql@@ -820,6 +820,7 @@ type BillingPaymentIntent {type BillingPlan {baseProducts: [BillingLicensedProduct!]!downgradePlanKeys: [BillingPlanKey!]!+ isCheckoutDefault: Boolean!isSellable: Boolean!meteredProducts: [BillingMeteredProduct!]!planKey: BillingPlanKey!@@ -3038,7 +3039,7 @@ type Mutation {cancelSwitchResourceCreditPrice: BillingUpdate!checkCustomDomainValidRecords: DomainValidRecordscheckPublicDomainValidRecords(domain: String!): DomainValidRecords- checkoutSession(plan: BillingPlanKey! = PRO, recurringInterval: SubscriptionInterval!, requirePaymentMethod: Boolean! = true, successUrlPath: String): BillingSession!+ checkoutSession(plan: BillingPlanKey!, recurringInterval: SubscriptionInterval!, requirePaymentMethod: Boolean! = true, successUrlPath: String): BillingSession!claimApplicationRegistrationOwnership(applicationRegistrationId: String!): ApplicationRegistration!completeAppTarballUpload(fileId: UUID!): ApplicationRegistration!completeApplicationFileUploads(applicationUniversalIdentifier: String!, fileIds: [UUID!]!): CompleteApplicationFileUploadsResult!@@ -3082,7 +3083,7 @@ type Mutation {createPublicDomain(applicationId: String!, domain: String!): PublicDomain!createSAMLIdentityProvider(input: SetupSAMLSsoInput!): SetupSso!createSkill(input: CreateSkillInput!): Skill!- createSubscriptionPaymentIntent(idempotencyKey: String!, plan: BillingPlanKey! = PRO, recurringInterval: SubscriptionInterval!, requirePaymentMethod: Boolean! = true, successUrlPath: String): BillingPaymentIntent!+ createSubscriptionPaymentIntent(idempotencyKey: String!, plan: BillingPlanKey!, recurringInterval: SubscriptionInterval!, requirePaymentMethod: Boolean! = true, successUrlPath: String): BillingPaymentIntent!createUnsubscribeTopic(input: CreateUnsubscribeTopicInput!): UnsubscribeTopic!createUsageLimit(input: CreateUsageLimitInput!): UsageLimit!createValidationRule(input: CreateValidationRuleInput!): ValidationRule!diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.tsindex 7da39fe3f4e..f5a76c782d0 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts@@ -729,6 +729,7 @@ export interface BillingPaymentIntent {export interface BillingPlan {baseProducts: BillingLicensedProduct[]downgradePlanKeys: BillingPlanKey[]+ isCheckoutDefault: Scalars['Boolean']isSellable: Scalars['Boolean']meteredProducts: BillingMeteredProduct[]planKey: BillingPlanKey@@ -4778,6 +4779,7 @@ export interface BillingPaymentIntentGenqlSelection{export interface BillingPlanGenqlSelection{baseProducts?: BillingLicensedProductGenqlSelectiondowngradePlanKeys?: boolean | number+ isCheckoutDefault?: boolean | numberisSellable?: boolean | numbermeteredProducts?: BillingMeteredProductGenqlSelectionplanKey?: boolean | numberdiff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.tsindex f62902b00ce..8595917370f 100644--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts@@ -1802,6 +1802,9 @@ export default {"downgradePlanKeys": [92],+ "isCheckoutDefault": [+ 4+ ],"isSellable": [4],diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.tsindex 9563947c3c7..75c706840a6 100644--- a/packages/twenty-front/src/generated-metadata/graphql.ts+++ b/packages/twenty-front/src/generated-metadata/graphql.ts@@ -896,6 +896,7 @@ export type BillingPlan = {__typename?: 'BillingPlan';baseProducts: Array<BillingLicensedProduct>;downgradePlanKeys: Array<BillingPlanKey>;+ isCheckoutDefault: Scalars['Boolean']['output'];isSellable: Scalars['Boolean']['output'];meteredProducts: Array<BillingMeteredProduct>;planKey: BillingPlanKey;@@ -3541,7 +3542,7 @@ export type MutationCheckPublicDomainValidRecordsArgs = {export type MutationCheckoutSessionArgs = {- plan?: BillingPlanKey;+ plan: BillingPlanKey;recurringInterval: SubscriptionInterval;requirePaymentMethod?: Scalars['Boolean']['input'];successUrlPath?: InputMaybe<Scalars['String']['input']>;@@ -3770,7 +3771,7 @@ export type MutationCreateSkillArgs = {export type MutationCreateSubscriptionPaymentIntentArgs = {idempotencyKey: Scalars['String']['input'];- plan?: BillingPlanKey;+ plan: BillingPlanKey;recurringInterval: SubscriptionInterval;requirePaymentMethod?: Scalars['Boolean']['input'];successUrlPath?: InputMaybe<Scalars['String']['input']>;@@ -10206,7 +10207,7 @@ export type GetResourceCreditUsageQuery = { __typename?: 'Query', getResourceCreexport type ListPlansQueryVariables = Exact<{ [key: string]: never; }>;-export type ListPlansQuery = { __typename?: 'Query', listPlans: Array<{ __typename?: 'BillingPlan', planKey: BillingPlanKey, isSellable: boolean, upgradePlanKeys: Array<BillingPlanKey>, downgradePlanKeys: Array<BillingPlanKey>, baseProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, resourceCreditProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, meteredProducts: Array<{ __typename?: 'BillingMeteredProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceMetered', priceUsageType: BillingUsageType, recurringInterval: SubscriptionInterval, stripePriceId: string, tiers: Array<{ __typename?: 'BillingPriceTier', flatAmount?: number | null, unitAmount?: number | null, upTo?: number | null }> }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }> }> };+export type ListPlansQuery = { __typename?: 'Query', listPlans: Array<{ __typename?: 'BillingPlan', planKey: BillingPlanKey, isSellable: boolean, isCheckoutDefault: boolean, upgradePlanKeys: Array<BillingPlanKey>, downgradePlanKeys: Array<BillingPlanKey>, baseProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, resourceCreditProducts: Array<{ __typename?: 'BillingLicensedProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceLicensed', stripePriceId: string, unitAmount: number, recurringInterval: SubscriptionInterval, priceUsageType: BillingUsageType, creditAmount?: number | null, isSellable: boolean }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }>, meteredProducts: Array<{ __typename?: 'BillingMeteredProduct', name: string, description: string, images?: Array<string> | null, prices?: Array<{ __typename?: 'BillingPriceMetered', priceUsageType: BillingUsageType, recurringInterval: SubscriptionInterval, stripePriceId: string, tiers: Array<{ __typename?: 'BillingPriceTier', flatAmount?: number | null, unitAmount?: number | null, upTo?: number | null }> }> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }> }> };export type UsageQuotaDefinitionsQueryVariables = Exact<{ [key: string]: never; }>;@@ -11273,7 +11274,7 @@ export const SwitchSubscriptionIntervalDocument = {"kind":"Document","definitionexport const UpdateUsageLimitDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateUsageLimit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateUsageLimitInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateUsageLimit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<UpdateUsageLimitMutation, UpdateUsageLimitMutationVariables>;export const BillingPortalSessionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"BillingPortalSession"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"returnUrlPath"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"forPaymentMethodUpdate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"billingPortalSession"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"returnUrlPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"returnUrlPath"}}},{"kind":"Argument","name":{"kind":"Name","value":"forPaymentMethodUpdate"},"value":{"kind":"Variable","name":{"kind":"Name","value":"forPaymentMethodUpdate"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"url"}}]}}]}}]} as unknown as DocumentNode<BillingPortalSessionQuery, BillingPortalSessionQueryVariables>;export const GetResourceCreditUsageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetResourceCreditUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getResourceCreditUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsUsed"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsGranted"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsGrantedForSeats"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsSeats"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsExtraGranted"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCreditsTotalGranted"}},{"kind":"Field","name":{"kind":"Name","value":"unitPriceCents"}}]}}]}}]} as unknown as DocumentNode<GetResourceCreditUsageQuery, GetResourceCreditUsageQueryVariables>;-export const ListPlansDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"isSellable"}},{"kind":"Field","name":{"kind":"Name","value":"upgradePlanKeys"}},{"kind":"Field","name":{"kind":"Name","value":"downgradePlanKeys"}},{"kind":"Field","name":{"kind":"Name","value":"baseProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"resourceCreditProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"meteredProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingMeteredProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceMeteredFragment"}}]}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceLicensedFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceLicensed"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"isSellable"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceMeteredFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceMetered"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"tiers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"flatAmount"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"upTo"}}]}}]}}]} as unknown as DocumentNode<ListPlansQuery, ListPlansQueryVariables>;+export const ListPlansDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"listPlans"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"isSellable"}},{"kind":"Field","name":{"kind":"Name","value":"isCheckoutDefault"}},{"kind":"Field","name":{"kind":"Name","value":"upgradePlanKeys"}},{"kind":"Field","name":{"kind":"Name","value":"downgradePlanKeys"}},{"kind":"Field","name":{"kind":"Name","value":"baseProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"resourceCreditProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingLicensedProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceLicensedFragment"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"meteredProducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}},{"kind":"Field","name":{"kind":"Name","value":"isLegacy"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingMeteredProduct"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prices"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingPriceMeteredFragment"}}]}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceLicensedFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceLicensed"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"isSellable"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingPriceMeteredFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPriceMetered"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"priceUsageType"}},{"kind":"Field","name":{"kind":"Name","value":"recurringInterval"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"tiers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"flatAmount"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"upTo"}}]}}]}}]} as unknown as DocumentNode<ListPlansQuery, ListPlansQueryVariables>;export const UsageQuotaDefinitionsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotaDefinitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotaDefinitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"definitions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"resourceType"}},{"kind":"Field","name":{"kind":"Name","value":"allowedOperations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"operationType"}},{"kind":"Field","name":{"kind":"Name","value":"allowedUnits"}}]}},{"kind":"Field","name":{"kind":"Name","value":"allowedSpenderTypes"}},{"kind":"Field","name":{"kind":"Name","value":"operatorOnlyScopes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"operationType"}},{"kind":"Field","name":{"kind":"Name","value":"spenderType"}},{"kind":"Field","name":{"kind":"Name","value":"unit"}},{"kind":"Field","name":{"kind":"Name","value":"periodUnit"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"isIntraWorkspaceLimitEntitled"}},{"kind":"Field","name":{"kind":"Name","value":"hasAllowancePeriod"}}]}}]}}]} as unknown as DocumentNode<UsageQuotaDefinitionsQuery, UsageQuotaDefinitionsQueryVariables>;export const UsageQuotaScopeConsumptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotaScopeConsumption"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UsageQuotaScopeInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotaScopeConsumption"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodStart"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}}]}}]}}]} as unknown as DocumentNode<UsageQuotaScopeConsumptionQuery, UsageQuotaScopeConsumptionQueryVariables>;export const UsageQuotasWithConsumptionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UsageQuotasWithConsumption"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"usageQuotasWithConsumption"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"resourceType"}},{"kind":"Field","name":{"kind":"Name","value":"operationType"}},{"kind":"Field","name":{"kind":"Name","value":"spenderType"}},{"kind":"Field","name":{"kind":"Name","value":"spenderId"}},{"kind":"Field","name":{"kind":"Name","value":"spenderLabel"}},{"kind":"Field","name":{"kind":"Name","value":"periodUnit"}},{"kind":"Field","name":{"kind":"Name","value":"unit"}},{"kind":"Field","name":{"kind":"Name","value":"limitValue"}},{"kind":"Field","name":{"kind":"Name","value":"isEnforced"}},{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"remainingValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodStart"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}}]}}]}}]} as unknown as DocumentNode<UsageQuotasWithConsumptionQuery, UsageQuotasWithConsumptionQueryVariables>;diff --git a/packages/twenty-front/src/modules/app/hooks/useInitializeQueryParamState.ts b/packages/twenty-front/src/modules/app/hooks/useInitializeQueryParamState.tsindex 74bb5684e54..e3eadbe080a 100644--- a/packages/twenty-front/src/modules/app/hooks/useInitializeQueryParamState.ts+++ b/packages/twenty-front/src/modules/app/hooks/useInitializeQueryParamState.ts@@ -25,7 +25,6 @@ export const useInitializeQueryParamState = () => {if (typeof parsedValue === 'object' &&parsedValue !== null &&- 'plan' in parsedValue &&'interval' in parsedValue &&'requirePaymentMethod' in parsedValue &&!isDeeplyEqual(billingCheckoutSession, parsedValue)diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithMicrosoft.test.ts b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithMicrosoft.test.tsindex ff89f2bcfe0..87d58e73793 100644--- a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithMicrosoft.test.ts+++ b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithMicrosoft.test.ts@@ -20,7 +20,6 @@ describe('useSignInWithMicrosoft', () => {});const mockBillingCheckoutSession = {- plan: 'PRO',interval: 'Month',requirePaymentMethod: true,};diff --git a/packages/twenty-front/src/modules/auth/types/BillingCheckoutSession.ts b/packages/twenty-front/src/modules/auth/types/BillingCheckoutSession.tsindex 777fcd71cab..5e72a646761 100644--- a/packages/twenty-front/src/modules/auth/types/BillingCheckoutSession.ts+++ b/packages/twenty-front/src/modules/auth/types/BillingCheckoutSession.ts@@ -4,7 +4,7 @@ import {} from '~/generated-metadata/graphql';export type BillingCheckoutSession = {- plan: BillingPlanKey;+ plan?: BillingPlanKey;interval: SubscriptionInterval;requirePaymentMethod: boolean;};diff --git a/packages/twenty-front/src/modules/information-banner/components/billing/InformationBannerNoBillingSubscription.tsx b/packages/twenty-front/src/modules/information-banner/components/billing/InformationBannerNoBillingSubscription.tsxindex 354e69eb218..2f2e3e41aaf 100644--- a/packages/twenty-front/src/modules/information-banner/components/billing/InformationBannerNoBillingSubscription.tsx+++ b/packages/twenty-front/src/modules/information-banner/components/billing/InformationBannerNoBillingSubscription.tsx@@ -1,16 +1,27 @@import { BILLING_CHECKOUT_SESSION_DEFAULT_VALUE } from '@/settings/billing/constants/BillingCheckoutSessionDefaultValue';import { useHandleCheckoutSession } from '@/settings/billing/hooks/useHandleCheckoutSession';+import { usePlans } from '@/settings/billing/hooks/usePlans';+import { getCheckoutPlanKeyOrThrow } from '@/settings/billing/utils/getCheckoutPlanKeyOrThrow';import { InformationBanner } from '@/information-banner/components/InformationBanner';import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';import { t } from '@lingui/core/macro';import { SettingsPath } from 'twenty-shared/types';import { getSettingsPath } from 'twenty-shared/utils';-import { PermissionFlagType } from '~/generated-metadata/graphql';+import {+ type BillingPlanKey,+ PermissionFlagType,+} from '~/generated-metadata/graphql';-export const InformationBannerNoBillingSubscription = () => {+type InformationBannerNoBillingSubscriptionContentProps = {+ planKey: BillingPlanKey;+};++const InformationBannerNoBillingSubscriptionContent = ({+ planKey,+}: InformationBannerNoBillingSubscriptionContentProps) => {const { handleCheckoutSession, isSubmitting } = useHandleCheckoutSession({recurringInterval: BILLING_CHECKOUT_SESSION_DEFAULT_VALUE.interval,- plan: BILLING_CHECKOUT_SESSION_DEFAULT_VALUE.plan,+ plan: planKey,requirePaymentMethod: true,successUrlPath: getSettingsPath(SettingsPath.Billing),});@@ -35,3 +46,17 @@ export const InformationBannerNoBillingSubscription = () => {/>);};++export const InformationBannerNoBillingSubscription = () => {+ const { isPlansLoaded, listPlans } = usePlans();++ if (!isPlansLoaded) {+ return null;+ }++ return (+ <InformationBannerNoBillingSubscriptionContent+ planKey={getCheckoutPlanKeyOrThrow({ plans: listPlans() })}+ />+ );+};diff --git a/packages/twenty-front/src/modules/settings/billing/constants/BillingCheckoutSessionDefaultValue.ts b/packages/twenty-front/src/modules/settings/billing/constants/BillingCheckoutSessionDefaultValue.tsindex f83ac9aaf8a..675c2776bd0 100644--- a/packages/twenty-front/src/modules/settings/billing/constants/BillingCheckoutSessionDefaultValue.ts+++ b/packages/twenty-front/src/modules/settings/billing/constants/BillingCheckoutSessionDefaultValue.ts@@ -1,11 +1,7 @@import { type BillingCheckoutSession } from '@/auth/types/BillingCheckoutSession';-import {- BillingPlanKey,- SubscriptionInterval,-} from '~/generated-metadata/graphql';+import { SubscriptionInterval } from '~/generated-metadata/graphql';export const BILLING_CHECKOUT_SESSION_DEFAULT_VALUE: BillingCheckoutSession = {- plan: BillingPlanKey.PRO,interval: SubscriptionInterval.Month,requirePaymentMethod: true,};diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/queries/listPlans.ts b/packages/twenty-front/src/modules/settings/billing/graphql/queries/listPlans.tsindex 1eddd23d9a9..7a4d7e8b1f9 100644--- a/packages/twenty-front/src/modules/settings/billing/graphql/queries/listPlans.ts+++ b/packages/twenty-front/src/modules/settings/billing/graphql/queries/listPlans.ts@@ -7,6 +7,7 @@ export const LIST_PLANS = gql`listPlans {planKeyisSellable+ isCheckoutDefaultupgradePlanKeysdowngradePlanKeysbaseProducts {diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getCheckoutPlanKeyOrThrow.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getCheckoutPlanKeyOrThrow.test.tsnew file mode 100644index 00000000000..6badc2d1912--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getCheckoutPlanKeyOrThrow.test.ts@@ -0,0 +1,54 @@+import { getCheckoutPlanKeyOrThrow } from '@/settings/billing/utils/getCheckoutPlanKeyOrThrow';+import { BillingPlanKey } from '~/generated-metadata/graphql';++const plans = [+ {+ planKey: BillingPlanKey.PRO,+ isSellable: false,+ isCheckoutDefault: false,+ },+ {+ planKey: BillingPlanKey.PRO_V2,+ isSellable: true,+ isCheckoutDefault: true,+ },+ {+ planKey: BillingPlanKey.ORGANIZATION_V2,+ isSellable: true,+ isCheckoutDefault: false,+ },+];++describe('getCheckoutPlanKeyOrThrow', () => {+ it('returns the requested plan when it is on sale', () => {+ expect(+ getCheckoutPlanKeyOrThrow({+ plans,+ requestedPlanKey: BillingPlanKey.ORGANIZATION_V2,+ }),+ ).toBe(BillingPlanKey.ORGANIZATION_V2);+ });++ it.each([undefined, BillingPlanKey.PRO])(+ 'returns the default checkout plan when %s is requested',+ (requestedPlanKey) => {+ expect(getCheckoutPlanKeyOrThrow({ plans, requestedPlanKey })).toBe(+ BillingPlanKey.PRO_V2,+ );+ },+ );++ it('throws when no plan is the default checkout plan', () => {+ expect(() =>+ getCheckoutPlanKeyOrThrow({+ plans: [+ {+ planKey: BillingPlanKey.PRO,+ isSellable: false,+ isCheckoutDefault: false,+ },+ ],+ }),+ ).toThrow();+ });+});diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getCheckoutPlanKeyOrThrow.ts b/packages/twenty-front/src/modules/settings/billing/utils/getCheckoutPlanKeyOrThrow.tsnew file mode 100644index 00000000000..b8bc5fa3365--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/utils/getCheckoutPlanKeyOrThrow.ts@@ -0,0 +1,28 @@+import { doNotTranslate } from 'twenty-shared/i18n';+import { findOrThrow, isDefined } from 'twenty-shared/utils';+import {+ type BillingPlan,+ type BillingPlanKey,+} from '~/generated-metadata/graphql';++export const getCheckoutPlanKeyOrThrow = ({+ plans,+ requestedPlanKey,+}: {+ plans: Pick<BillingPlan, 'isCheckoutDefault' | 'isSellable' | 'planKey'>[];+ requestedPlanKey?: BillingPlanKey;+}): BillingPlanKey => {+ const requestedPlan = plans.find(+ (plan) => plan.planKey === requestedPlanKey && plan.isSellable,+ );++ if (isDefined(requestedPlan)) {+ return requestedPlan.planKey;+ }++ return findOrThrow(+ plans,+ (plan) => plan.isCheckoutDefault,+ new Error(doNotTranslate('No default checkout billing plan')),+ ).planKey;+};diff --git a/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx b/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsxindex 004f03c6f6b..a3133cf0cf1 100644--- a/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx+++ b/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx@@ -20,9 +20,11 @@ import { onboardingCreditsProgressSelector } from '@/onboarding/states/selectorsimport { formatOnboardingCredits } from '@/onboarding/utils/formatOnboardingCredits';import { useBaseLicensedPriceByPlanKeyAndInterval } from '@/settings/billing/hooks/useBaseLicensedPriceByPlanKeyAndInterval';import { useHandleCheckoutSession } from '@/settings/billing/hooks/useHandleCheckoutSession';+import { usePlans } from '@/settings/billing/hooks/usePlans';import { useStripeAppearance } from '@/settings/billing/hooks/useStripeAppearance';import { useStripePromise } from '@/settings/billing/hooks/useStripePromise';import { useSubmitSubscriptionPayment } from '@/settings/billing/hooks/useSubmitSubscriptionPayment';+import { getCheckoutPlanKeyOrThrow } from '@/settings/billing/utils/getCheckoutPlanKeyOrThrow';import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';@@ -116,12 +118,14 @@ const UpgradeFreeTrialSubmitButton = ({type UpgradeFreeTrialContentProps = {billing: Billing;+ planKey: BillingPlanKey;isPaymentAvailable: boolean;trialDuration?: number;};const UpgradeFreeTrialContent = ({billing,+ planKey,isPaymentAvailable,trialDuration,}: UpgradeFreeTrialContentProps) => {@@ -147,9 +151,8 @@ const UpgradeFreeTrialContent = ({const { signOut } = useAuth();- const currentPlanKey = billingCheckoutSession.plan;const baseProductPrice = getBaseLicensedPriceByPlanKeyAndInterval(- currentPlanKey,+ planKey,billingCheckoutSession.interval,);@@ -161,7 +164,7 @@ const UpgradeFreeTrialContent = ({const { handleCheckoutSession, isSubmitting: isCheckoutSubmitting } =useHandleCheckoutSession({recurringInterval: billingCheckoutSession.interval,- plan: billingCheckoutSession.plan,+ plan: planKey,requirePaymentMethod: billingCheckoutSession.requirePaymentMethod,successUrlPath: AppPath.PlanRequiredSuccess,});@@ -186,7 +189,7 @@ const UpgradeFreeTrialContent = ({billingCheckoutSession.requirePaymentMethod !== withCreditCard) {setBillingCheckoutSession({- plan: currentPlanKey,+ plan: planKey,interval: baseProductPrice.recurringInterval,requirePaymentMethod: withCreditCard,});@@ -270,7 +273,7 @@ const UpgradeFreeTrialContent = ({<StyledFooter>{requirePaymentMethod && isPaymentAvailable ? (<UpgradeFreeTrialSubmitButton- plan={billingCheckoutSession.plan}+ plan={planKey}recurringInterval={billingCheckoutSession.interval}creditsReward={upgradeCreditsReward}/>@@ -310,6 +313,12 @@ export const UpgradeFreeTrial = ({ billing }: UpgradeFreeTrialProps) => {useBaseLicensedPriceByPlanKeyAndInterval();const billingCheckoutSession = useAtomStateValue(billingCheckoutSessionState);+ const { listPlans } = usePlans();++ const planKey = getCheckoutPlanKeyOrThrow({+ plans: listPlans(),+ requestedPlanKey: billingCheckoutSession.plan,+ });const [verifyEmailRedirectPath, setVerifyEmailRedirectPath] = useAtomState(verifyEmailRedirectPathState,@@ -322,7 +331,7 @@ export const UpgradeFreeTrial = ({ billing }: UpgradeFreeTrialProps) => {const appearance = useStripeAppearance();const baseProductPrice = getBaseLicensedPriceByPlanKeyAndInterval(- billingCheckoutSession.plan,+ planKey,billingCheckoutSession.interval,);@@ -369,6 +378,7 @@ export const UpgradeFreeTrial = ({ billing }: UpgradeFreeTrialProps) => {><UpgradeFreeTrialContentbilling={billing}+ planKey={planKey}isPaymentAvailabletrialDuration={trialDuration}/>@@ -376,6 +386,7 @@ export const UpgradeFreeTrial = ({ billing }: UpgradeFreeTrialProps) => {) : (<UpgradeFreeTrialContentbilling={billing}+ planKey={planKey}isPaymentAvailable={false}trialDuration={trialDuration}/>diff --git a/packages/twenty-front/src/testing/mock-data/billing-plans.ts b/packages/twenty-front/src/testing/mock-data/billing-plans.tsindex fa30bfaf8db..e523f7394dd 100644--- a/packages/twenty-front/src/testing/mock-data/billing-plans.ts+++ b/packages/twenty-front/src/testing/mock-data/billing-plans.ts@@ -6,6 +6,7 @@ export const mockBillingPlans = {__typename: 'BillingPlan',planKey: 'PRO',isSellable: true,+ isCheckoutDefault: true,upgradePlanKeys: ['ENTERPRISE'],downgradePlanKeys: [],baseProducts: [@@ -306,6 +307,7 @@ export const mockBillingPlans = {__typename: 'BillingPlan',planKey: 'ENTERPRISE',isSellable: true,+ isCheckoutDefault: false,upgradePlanKeys: [],downgradePlanKeys: ['PRO'],baseProducts: [@@ -606,6 +608,7 @@ export const mockBillingPlans = {__typename: 'BillingPlan',planKey: 'PRO_V2',isSellable: false,+ isCheckoutDefault: false,upgradePlanKeys: [],downgradePlanKeys: [],baseProducts: [],@@ -616,6 +619,7 @@ export const mockBillingPlans = {__typename: 'BillingPlan',planKey: 'ORGANIZATION_V2',isSellable: false,+ isCheckoutDefault: false,upgradePlanKeys: [],downgradePlanKeys: [],baseProducts: [],diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.exampleindex fe0ef447c1c..bd7502c9494 100644--- a/packages/twenty-server/.env.example+++ b/packages/twenty-server/.env.example@@ -22,6 +22,7 @@ FRONTEND_URL=http://localhost:3001# CALENDAR_PROVIDER_MICROSOFT_ENABLED=false# IS_BILLING_ENABLED=false# BILLING_PLAN_REQUIRED_LINK=https://twenty.com/stripe-redirection+# BILLING_PLANS={"PRO":{"isDefault":true,"upgradePlanKeys":["ENTERPRISE"]},"ENTERPRISE":{"downgradePlanKeys":["PRO"]}}# AUTH_PASSWORD_ENABLED=false# IS_MULTIWORKSPACE_ENABLED=false# AUTH_MICROSOFT_ENABLED=falsediff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.tsindex 8473b49151e..7ed91509610 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.resolver.ts@@ -32,7 +32,6 @@ import { BillingSubscriptionService } from 'src/engine/core-modules/billing/servimport { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';import { BillingService } from 'src/engine/core-modules/billing/services/billing.service';import { formatBillingDatabaseProductToGraphqlDTO } from 'src/engine/core-modules/billing/utils/format-database-product-to-graphql-dto.util';-import { getCheckoutPlanKeyOrThrow } from 'src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util';import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';import { toDisplayCredits } from 'src/engine/core-modules/usage/utils/to-display-credits.util';@@ -140,13 +139,13 @@ export class BillingResolver {user,workspace,successUrlPath,- plan: getCheckoutPlanKeyOrThrow({ planKey: plan }),+ plan,requirePaymentMethod,};const billingPricesPerPlan =- await this.billingPlanService.getPricesPerPlanByInterval({- planKey: checkoutSessionParams.plan,+ await this.billingPlanService.getSellablePlanPricesByIntervalOrThrow({+ planKey: plan,interval: recurringInterval,});@@ -205,18 +204,16 @@ export class BillingResolver {workspaceActivationStatus: workspace.activationStatus,});- const checkoutPlanKey = getCheckoutPlanKeyOrThrow({ planKey: plan });-const billingPricesPerPlan =- await this.billingPlanService.getPricesPerPlanByInterval({- planKey: checkoutPlanKey,+ await this.billingPlanService.getSellablePlanPricesByIntervalOrThrow({+ planKey: plan,interval: recurringInterval,});return this.billingPortalWorkspaceService.createSubscriptionPaymentIntent({user,workspace,- plan: checkoutPlanKey,+ plan,billingPricesPerPlan,idempotencyKey,});diff --git a/packages/twenty-server/src/engine/core-modules/billing/constants/billing-plan-switches.constant.ts b/packages/twenty-server/src/engine/core-modules/billing/constants/billing-plan-switches.constant.tsdeleted file mode 100644index 12de010fe26..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/constants/billing-plan-switches.constant.ts+++ /dev/null@@ -1,23 +0,0 @@-/* @license Enterprise */--import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';-import { type BillingPlanSwitches } from 'src/engine/core-modules/billing/types/billing-plan-switches.type';--export const BILLING_PLAN_SWITCHES: BillingPlanSwitches = {- [BillingPlanKey.PRO]: {- upgradePlanKeys: [BillingPlanKey.ENTERPRISE],- downgradePlanKeys: [],- },- [BillingPlanKey.ENTERPRISE]: {- upgradePlanKeys: [],- downgradePlanKeys: [BillingPlanKey.PRO],- },- [BillingPlanKey.PRO_V2]: {- upgradePlanKeys: [],- downgradePlanKeys: [],- },- [BillingPlanKey.ORGANIZATION_V2]: {- upgradePlanKeys: [],- downgradePlanKeys: [],- },-};diff --git a/packages/twenty-server/src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant.ts b/packages/twenty-server/src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant.tsdeleted file mode 100644index 3ffa92dd10e..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant.ts+++ /dev/null@@ -1,8 +0,0 @@-/* @license Enterprise */--import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';--export const BILLING_SELLABLE_PLAN_KEYS: [BillingPlanKey, BillingPlanKey] = [- BillingPlanKey.PRO,- BillingPlanKey.ENTERPRISE,-];diff --git a/packages/twenty-server/src/engine/core-modules/billing/decorators/__tests__/is-billing-plans-config.decorator.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/decorators/__tests__/is-billing-plans-config.decorator.spec.tsnew file mode 100644index 00000000000..67731e54a89--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/decorators/__tests__/is-billing-plans-config.decorator.spec.ts@@ -0,0 +1,90 @@+/* @license Enterprise */++import { validateSync } from 'class-validator';++import { IsBillingPlansConfig } from 'src/engine/core-modules/billing/decorators/is-billing-plans-config.decorator';++describe('IsBillingPlansConfig', () => {+ class ConfigVariables {+ @IsBillingPlansConfig()+ plansConfig: unknown;+ }++ const validate = (plansConfig: unknown) =>+ validateSync(Object.assign(new ConfigVariables(), { plansConfig }));++ it.each([+ {+ PRO: { isDefault: true, upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { upgradePlanKeys: ['PRO_V2', 'ORGANIZATION_V2'] },+ ENTERPRISE: {+ upgradePlanKeys: ['ORGANIZATION_V2'],+ downgradePlanKeys: ['PRO_V2'],+ },+ PRO_V2: { isDefault: true, upgradePlanKeys: ['ORGANIZATION_V2'] },+ ORGANIZATION_V2: { isDefault: false, downgradePlanKeys: ['PRO_V2'] },+ },+ ])('accepts %j', (plansConfig) => {+ expect(validate(plansConfig)).toHaveLength(0);+ });++ it.each<unknown>([+ [],+ 'PRO',+ {},+ { PRO: { isDefault: true, upgradePlanKeys: ['ENTERPRISE'] } },+ {+ PRO: { upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { isDefault: true, downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgradePlanKeys: ['PRO_V2', 'ORGANIZATION_V2'] },+ PRO_V2: { upgradePlanKeys: ['ORGANIZATION_V2'] },+ ORGANIZATION_V2: { downgradePlanKeys: ['PRO_V2'] },+ },+ {+ PRO: { isDefault: 'true', upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ PRO_V2: { upgradePlanKeys: ['ORGANIZATION_V2'] },+ ORGANIZATION_V2: { downgradePlanKeys: ['PRO_V2'] },+ },+ {+ UNKNOWN: { isDefault: true, upgradePlanKeys: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgradePlanKeys: ['ENTERPRSE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgradePlanKeys: 'ENTERPRISE' },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ {+ PRO: { isDefault: true, upgrades: ['ENTERPRISE'] },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ { PRO: ['ENTERPRISE'], ENTERPRISE: { downgradePlanKeys: ['PRO'] } },+ {+ PRO: {+ isDefault: true,+ upgradePlanKeys: ['ENTERPRISE'],+ toString: ['ENTERPRISE'],+ },+ ENTERPRISE: { downgradePlanKeys: ['PRO'] },+ },+ ])('refuses %j', (plansConfig) => {+ expect(validate(plansConfig)).toHaveLength(1);+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/billing/decorators/is-billing-plans-config.decorator.ts b/packages/twenty-server/src/engine/core-modules/billing/decorators/is-billing-plans-config.decorator.tsnew file mode 100644index 00000000000..ea2c8999697--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/decorators/is-billing-plans-config.decorator.ts@@ -0,0 +1,87 @@+/* @license Enterprise */++import {+ registerDecorator,+ type ValidationArguments,+ type ValidationOptions,+ ValidatorConstraint,+ type ValidatorConstraintInterface,+} from 'class-validator';+import { isBoolean } from '@sniptt/guards';+import { isDefined, isPlainObject } from 'twenty-shared/utils';++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import {+ type BillingPlanConfig,+ type BillingPlansConfig,+} from 'src/engine/core-modules/billing/types/billing-plans-config.type';+import { findDefaultPlanKey } from 'src/engine/core-modules/billing/utils/find-default-plan-key.util';+import { getSellablePlanKeys } from 'src/engine/core-modules/billing/utils/get-sellable-plan-keys.util';++const BILLING_PLAN_KEYS = Object.values(BillingPlanKey);++const isBillingPlanKey = (value: unknown): value is BillingPlanKey =>+ BILLING_PLAN_KEYS.some((planKey) => planKey === value);++const isBillingPlanKeyList = (value: unknown): boolean =>+ Array.isArray(value) && value.every(isBillingPlanKey);++const PLAN_CONFIG_VALUE_CHECKS: Record<+ keyof BillingPlanConfig,+ (value: unknown) => boolean+> = {+ isDefault: isBoolean,+ upgradePlanKeys: isBillingPlanKeyList,+ downgradePlanKeys: isBillingPlanKeyList,+};++const isPlanConfigKey = (key: string): key is keyof BillingPlanConfig =>+ Object.prototype.hasOwnProperty.call(PLAN_CONFIG_VALUE_CHECKS, key);++const isPlanConfigEntryValid = ([key, value]: [string, unknown]): boolean =>+ isPlanConfigKey(key) && PLAN_CONFIG_VALUE_CHECKS[key](value);++const isBillingPlansConfigShape = (+ value: unknown,+): value is BillingPlansConfig =>+ isPlainObject(value) &&+ Object.entries(value).every(+ ([planKey, planConfig]) =>+ isBillingPlanKey(planKey) &&+ isPlainObject(planConfig) &&+ Object.entries(planConfig).every(isPlanConfigEntryValid),+ );++@ValidatorConstraint({ async: false })+export class IsBillingPlansConfigValidator implements ValidatorConstraintInterface {+ validate(plansConfig: unknown) {+ if (!isBillingPlansConfigShape(plansConfig)) {+ return false;+ }++ const sellablePlanKeys = getSellablePlanKeys(plansConfig);+ const defaultPlanKey = findDefaultPlanKey(plansConfig);++ return (+ sellablePlanKeys.length === 2 &&+ isDefined(defaultPlanKey) &&+ sellablePlanKeys.includes(defaultPlanKey)+ );+ }++ defaultMessage(args: ValidationArguments) {+ return `${args.property} must map billing plan keys to { isDefault?, upgradePlanKeys?, downgradePlanKeys? }, with exactly two plans reachable by a switch and exactly one of them marked isDefault`;+ }+}++export const IsBillingPlansConfig =+ (validationOptions?: ValidationOptions) =>+ (object: object, propertyName: string) => {+ registerDecorator({+ target: object.constructor,+ propertyName: propertyName,+ options: validationOptions,+ constraints: [],+ validator: IsBillingPlansConfigValidator,+ });+ };diff --git a/packages/twenty-server/src/engine/core-modules/billing/dtos/billing-plan.dto.ts b/packages/twenty-server/src/engine/core-modules/billing/dtos/billing-plan.dto.tsindex d9a33f45ee2..2c2b3b81209 100644--- a/packages/twenty-server/src/engine/core-modules/billing/dtos/billing-plan.dto.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/dtos/billing-plan.dto.ts@@ -16,6 +16,9 @@ export class BillingPlanDTO {@Field(() => Boolean)isSellable: boolean;+ @Field(() => Boolean)+ isCheckoutDefault: boolean;+@Field(() => [BillingPlanKey])upgradePlanKeys: BillingPlanKey[];diff --git a/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-checkout-session.input.ts b/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-checkout-session.input.tsindex 02d3fd78323..0dd42f60e65 100644--- a/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-checkout-session.input.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-checkout-session.input.ts@@ -10,7 +10,6 @@ import {IsString,} from 'class-validator';-import { BILLING_SELLABLE_PLAN_KEYS } from 'src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant';import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { SubscriptionInterval } from 'src/engine/core-modules/billing/enums/billing-subscription-interval.enum';@@ -21,10 +20,10 @@ export class BillingCheckoutSessionInput {@IsNotEmpty()recurringInterval: SubscriptionInterval;- @Field(() => BillingPlanKey, { defaultValue: BILLING_SELLABLE_PLAN_KEYS[0] })+ @Field(() => BillingPlanKey)@IsEnum(BillingPlanKey)- @IsOptional()- plan?: BillingPlanKey;+ @IsNotEmpty()+ plan: BillingPlanKey;@Field(() => Boolean, { defaultValue: true })@IsBoolean()diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.tsindex 19f5035864a..3480d7b5a9a 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-plan.service.ts@@ -9,8 +9,6 @@ import {BillingException,BillingExceptionCode,} from 'src/engine/core-modules/billing/billing.exception';-import { BILLING_PLAN_SWITCHES } from 'src/engine/core-modules/billing/constants/billing-plan-switches.constant';-import { BILLING_SELLABLE_PLAN_KEYS } from 'src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant';import { BillingProductEntity } from 'src/engine/core-modules/billing/entities/billing-product.entity';import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { BillingProductKey } from 'src/engine/core-modules/billing/enums/billing-product-key.enum';@@ -18,6 +16,11 @@ import { type SubscriptionInterval } from 'src/engine/core-modules/billing/enumsimport { BillingUsageType } from 'src/engine/core-modules/billing/enums/billing-usage-type.enum';import { type BillingGetPlanResult } from 'src/engine/core-modules/billing/types/billing-get-plan-result.type';import { type BillingGetPricesPerPlanResult } from 'src/engine/core-modules/billing/types/billing-get-prices-per-plan-result.type';+import { assertPlanIsSellableOrThrow } from 'src/engine/core-modules/billing/utils/assert-plan-is-sellable-or-throw.util';+import { findDefaultPlanKey } from 'src/engine/core-modules/billing/utils/find-default-plan-key.util';+import { getBillingPlanConfig } from 'src/engine/core-modules/billing/utils/get-billing-plan-config.util';+import { getSellablePlanKeys } from 'src/engine/core-modules/billing/utils/get-sellable-plan-keys.util';+import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';@Injectable()export class BillingPlanService {@@ -25,9 +28,13 @@ export class BillingPlanService {constructor(@InjectRepository(BillingProductEntity)private readonly billingProductRepository: Repository<BillingProductEntity>,+ private readonly twentyConfigService: TwentyConfigService,) {}async listPlans(): Promise<BillingGetPlanResult[]> {+ const plansConfig = this.twentyConfigService.get('BILLING_PLANS');+ const sellablePlanKeys = getSellablePlanKeys(plansConfig);+ const defaultPlanKey = findDefaultPlanKey(plansConfig);const planKeys = Object.values(BillingPlanKey);const products = await this.billingProductRepository.find({@@ -57,12 +64,17 @@ export class BillingPlanService {(product) =>product.metadata.productKey === BillingProductKey.RESOURCE_CREDIT,);+ const { upgradePlanKeys, downgradePlanKeys } = getBillingPlanConfig({+ plansConfig,+ planKey,+ });return {planKey,- isSellable: BILLING_SELLABLE_PLAN_KEYS.includes(planKey),- upgradePlanKeys: BILLING_PLAN_SWITCHES[planKey].upgradePlanKeys,- downgradePlanKeys: BILLING_PLAN_SWITCHES[planKey].downgradePlanKeys,+ isSellable: sellablePlanKeys.includes(planKey),+ isCheckoutDefault: planKey === defaultPlanKey,+ upgradePlanKeys,+ downgradePlanKeys,meteredProducts,baseProducts,resourceCreditProducts,@@ -70,13 +82,20 @@ export class BillingPlanService {});}- async getPricesPerPlanByInterval({+ async getSellablePlanPricesByIntervalOrThrow({planKey,interval,}: {planKey: BillingPlanKey;interval: SubscriptionInterval;}): Promise<BillingGetPricesPerPlanResult> {+ assertPlanIsSellableOrThrow({+ planKey,+ sellablePlanKeys: getSellablePlanKeys(+ this.twentyConfigService.get('BILLING_PLANS'),+ ),+ });+const plans = await this.listPlans();const plan = plans.find((plan) => plan.planKey === planKey);diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.tsindex 47ed556fa3a..99dbea44ec8 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription-update.service.ts@@ -18,7 +18,6 @@ import {BillingExceptionCode,} from 'src/engine/core-modules/billing/billing.exception';import { billingValidator } from 'src/engine/core-modules/billing/billing.validate';-import { BILLING_PLAN_SWITCHES } from 'src/engine/core-modules/billing/constants/billing-plan-switches.constant';import { BillingPriceEntity } from 'src/engine/core-modules/billing/entities/billing-price.entity';import { BillingSubscriptionEntity } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';@@ -43,6 +42,7 @@ import { isResourceCreditPriceForSubscription } from 'src/engine/core-modules/biimport { isSellableCatalogPrice } from 'src/engine/core-modules/billing/utils/is-sellable-catalog-price.util';import { isSendInvoiceSubscription } from 'src/engine/core-modules/billing/utils/is-send-invoice-subscription.util';import { getBaseProductSubscriptionItemOrThrow } from 'src/engine/core-modules/billing/utils/get-base-product-subscription-item-or-throw.util';+import { getBillingPlanConfig } from 'src/engine/core-modules/billing/utils/get-billing-plan-config.util';import { getPlanSwitchOrThrow } from 'src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util';import { getCurrentResourceCreditSubscriptionItemOrThrow } from 'src/engine/core-modules/billing/utils/get-resource-credit-subscription-item-or-throw.util';import { normalizePriceRef } from 'src/engine/core-modules/billing/utils/normalize-price-ref.utils';@@ -51,6 +51,7 @@ import { buildSubscriptionItemsUpdate } from 'src/engine/core-modules/billing/utimport { isSamePhaseSignature } from 'src/engine/core-modules/billing/utils/is-same-phase-signature.util';import { toPhaseUpdateParams } from 'src/engine/core-modules/billing/utils/to-phase-update-params.util';import { type SubscriptionStripePrices } from 'src/engine/core-modules/billing/types/subscription-stripe-prices.type';+import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';@@ -73,6 +74,7 @@ export class BillingSubscriptionUpdateService {private readonly stripeSubscriptionScheduleService: StripeSubscriptionScheduleService,private readonly billingSubscriptionService: BillingSubscriptionService,private readonly workspaceOrmManager: WorkspaceOrmManager,+ private readonly twentyConfigService: TwentyConfigService,) {}async changeResourceCreditPrice(@@ -207,7 +209,11 @@ export class BillingSubscriptionUpdateService {assertIsDefinedOrThrow(currentPlanKey);- const planSwitch = getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey });+ const planSwitch = getPlanSwitchOrThrow({+ currentPlanKey,+ targetPlanKey,+ plansConfig: this.twentyConfigService.get('BILLING_PLANS'),+ });await this.updateSubscription(workspaceId, billingSubscription.id, {type: SubscriptionUpdateType.PLAN,@@ -613,9 +619,10 @@ export class BillingSubscriptionUpdateService {const isDowngrade =isDefined(currentPlan) &&- BILLING_PLAN_SWITCHES[currentPlan].downgradePlanKeys.includes(- update.newPlan,- );+ getBillingPlanConfig({+ plansConfig: this.twentyConfigService.get('BILLING_PLANS'),+ planKey: currentPlan,+ }).downgradePlanKeys.includes(update.newPlan);return isDowngrade;}diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-checkout.service.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-checkout.service.tsindex 322b725782e..66cac9fe18f 100644--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-checkout.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-checkout.service.ts@@ -6,7 +6,6 @@ import { isDefined } from 'twenty-shared/utils';import type Stripe from 'stripe';-import { BILLING_SELLABLE_PLAN_KEYS } from 'src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant';import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { StripeCustomerService } from 'src/engine/core-modules/billing/stripe/services/stripe-customer.service';import { StripeSDKService } from 'src/engine/core-modules/billing/stripe/stripe-sdk/services/stripe-sdk.service';@@ -39,7 +38,7 @@ export class StripeCheckoutService {successUrl,cancelUrl,stripeCustomerId,- plan = BILLING_SELLABLE_PLAN_KEYS[0],+ plan,requirePaymentMethod = true,withTrialPeriod,}: {@@ -49,7 +48,7 @@ export class StripeCheckoutService {successUrl?: string;cancelUrl?: string;stripeCustomerId?: string;- plan?: BillingPlanKey;+ plan: BillingPlanKey;requirePaymentMethod?: boolean;withTrialPeriod: boolean;}): Promise<Stripe.Checkout.Session> {@@ -89,7 +88,7 @@ export class StripeCheckoutService {workspace,stripeSubscriptionLineItems,stripeCustomerId,- plan = BILLING_SELLABLE_PLAN_KEYS[0],+ plan,requirePaymentMethod = false,withTrialPeriod,idempotencyKey,@@ -98,7 +97,7 @@ export class StripeCheckoutService {workspace: Pick<WorkspaceEntity, 'id' | 'displayName'>;stripeSubscriptionLineItems: Stripe.Checkout.SessionCreateParams.LineItem[];stripeCustomerId?: string;- plan?: BillingPlanKey;+ plan: BillingPlanKey;requirePaymentMethod?: boolean;withTrialPeriod: boolean;idempotencyKey: string;@@ -139,7 +138,7 @@ export class StripeCheckoutService {workspace,stripeSubscriptionLineItems,stripeCustomerId,- plan = BILLING_SELLABLE_PLAN_KEYS[0],+ plan,withTrialPeriod,idempotencyKey,}: {@@ -147,7 +146,7 @@ export class StripeCheckoutService {workspace: Pick<WorkspaceEntity, 'id' | 'displayName'>;stripeSubscriptionLineItems: Stripe.Checkout.SessionCreateParams.LineItem[];stripeCustomerId?: string;- plan?: BillingPlanKey;+ plan: BillingPlanKey;withTrialPeriod: boolean;idempotencyKey: string;}): Promise<Stripe.Subscription> {diff --git a/packages/twenty-server/src/engine/core-modules/billing/types/billing-get-plan-result.type.ts b/packages/twenty-server/src/engine/core-modules/billing/types/billing-get-plan-result.type.tsindex 7838635a8f6..f60a80738f8 100644--- a/packages/twenty-server/src/engine/core-modules/billing/types/billing-get-plan-result.type.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/types/billing-get-plan-result.type.ts@@ -6,6 +6,7 @@ import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billiexport type BillingGetPlanResult = {planKey: BillingPlanKey;isSellable: boolean;+ isCheckoutDefault: boolean;upgradePlanKeys: BillingPlanKey[];downgradePlanKeys: BillingPlanKey[];meteredProducts: BillingProductEntity[];diff --git a/packages/twenty-server/src/engine/core-modules/billing/types/billing-plan-switches.type.ts b/packages/twenty-server/src/engine/core-modules/billing/types/billing-plan-switches.type.tsdeleted file mode 100644index 17b1a330e40..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/types/billing-plan-switches.type.ts+++ /dev/null@@ -1,8 +0,0 @@-/* @license Enterprise */--import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';--export type BillingPlanSwitches = Record<- BillingPlanKey,- { upgradePlanKeys: BillingPlanKey[]; downgradePlanKeys: BillingPlanKey[] }->;diff --git a/packages/twenty-server/src/engine/core-modules/billing/types/billing-plans-config.type.ts b/packages/twenty-server/src/engine/core-modules/billing/types/billing-plans-config.type.tsnew file mode 100644index 00000000000..08c3725d6db--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/types/billing-plans-config.type.ts@@ -0,0 +1,13 @@+/* @license Enterprise */++import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';++export type BillingPlanConfig = {+ isDefault: boolean;+ upgradePlanKeys: BillingPlanKey[];+ downgradePlanKeys: BillingPlanKey[];+};++export type BillingPlansConfig = Partial<+ Record<BillingPlanKey, Partial<BillingPlanConfig>>+>;diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/assert-plan-is-sellable-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/assert-plan-is-sellable-or-throw.util.spec.tsnew file mode 100644index 00000000000..2ef2e141e3c--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/assert-plan-is-sellable-or-throw.util.spec.ts@@ -0,0 +1,34 @@+/* @license Enterprise */++import { BillingExceptionCode } from 'src/engine/core-modules/billing/billing.exception';+import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { assertPlanIsSellableOrThrow } from 'src/engine/core-modules/billing/utils/assert-plan-is-sellable-or-throw.util';++const sellablePlanKeys = [+ BillingPlanKey.PRO_V2,+ BillingPlanKey.ORGANIZATION_V2,+];++describe('assertPlanIsSellableOrThrow', () => {+ it('accepts a plan on sale', () => {+ expect(() =>+ assertPlanIsSellableOrThrow({+ planKey: BillingPlanKey.ORGANIZATION_V2,+ sellablePlanKeys,+ }),+ ).not.toThrow();+ });++ it('refuses a plan that is not on sale', () => {+ expect(() =>+ assertPlanIsSellableOrThrow({+ planKey: BillingPlanKey.PRO,+ sellablePlanKeys,+ }),+ ).toThrow(+ expect.objectContaining({+ code: BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ }),+ );+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/find-default-plan-key.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/find-default-plan-key.util.spec.tsnew file mode 100644index 00000000000..782f06724de--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/find-default-plan-key.util.spec.ts@@ -0,0 +1,31 @@+/* @license Enterprise */++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { findDefaultPlanKey } from 'src/engine/core-modules/billing/utils/find-default-plan-key.util';++describe('findDefaultPlanKey', () => {+ it('returns the plan marked isDefault', () => {+ expect(+ findDefaultPlanKey({+ [BillingPlanKey.PRO]: { upgradePlanKeys: [BillingPlanKey.ENTERPRISE] },+ [BillingPlanKey.ENTERPRISE]: {+ isDefault: true,+ downgradePlanKeys: [BillingPlanKey.PRO],+ },+ }),+ ).toBe(BillingPlanKey.ENTERPRISE);+ });++ it.each([+ {},+ {+ [BillingPlanKey.PRO]: { isDefault: true },+ [BillingPlanKey.ENTERPRISE]: { isDefault: true },+ },+ ])(+ 'returns undefined unless exactly one plan is marked isDefault',+ (plansConfig) => {+ expect(findDefaultPlanKey(plansConfig)).toBeUndefined();+ },+ );+});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-checkout-plan-key-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-checkout-plan-key-or-throw.util.spec.tsdeleted file mode 100644index 2f1798c5ea3..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-checkout-plan-key-or-throw.util.spec.ts+++ /dev/null@@ -1,17 +0,0 @@-/* @license Enterprise */--import { BillingExceptionCode } from 'src/engine/core-modules/billing/billing.exception';-import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';-import { getCheckoutPlanKeyOrThrow } from 'src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util';--describe('getCheckoutPlanKeyOrThrow', () => {- it('refuses a plan that is not on sale', () => {- expect(() =>- getCheckoutPlanKeyOrThrow({ planKey: BillingPlanKey.PRO_V2 }),- ).toThrow(- expect.objectContaining({- code: BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,- }),- );- });-});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-plan-switch-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-plan-switch-or-throw.util.spec.tsindex 33e18b16136..4aed3a1bf14 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-plan-switch-or-throw.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-plan-switch-or-throw.util.spec.ts@@ -2,28 +2,56 @@import { BillingExceptionCode } from 'src/engine/core-modules/billing/billing.exception';import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { type BillingPlansConfig } from 'src/engine/core-modules/billing/types/billing-plans-config.type';import { getPlanSwitchOrThrow } from 'src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util';+const plansConfig: BillingPlansConfig = {+ [BillingPlanKey.PRO]: {+ upgradePlanKeys: [BillingPlanKey.ENTERPRISE, BillingPlanKey.PRO_V2],+ },+ [BillingPlanKey.ENTERPRISE]: { downgradePlanKeys: [BillingPlanKey.PRO] },+};+describe('getPlanSwitchOrThrow', () => {it.each([[BillingPlanKey.PRO, BillingPlanKey.ENTERPRISE],+ [BillingPlanKey.PRO, BillingPlanKey.PRO_V2],[BillingPlanKey.ENTERPRISE, BillingPlanKey.PRO],])('allows %s to %s', (currentPlanKey, targetPlanKey) => {- expect(getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey })).toEqual({- targetPlanKey,- });+ expect(+ getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey, plansConfig }),+ ).toEqual({ targetPlanKey });});- it('refuses a plan outside the current plan switches', () => {- expect(() =>+ it('uses the single allowed switch when no target is given', () => {+ expect(getPlanSwitchOrThrow({- currentPlanKey: BillingPlanKey.PRO,- targetPlanKey: BillingPlanKey.PRO_V2,- }),- ).toThrow(- expect.objectContaining({- code: BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ currentPlanKey: BillingPlanKey.ENTERPRISE,+ plansConfig,}),- );+ ).toEqual({ targetPlanKey: BillingPlanKey.PRO });});++ it.each([+ {+ currentPlanKey: BillingPlanKey.PRO,+ targetPlanKey: BillingPlanKey.ORGANIZATION_V2,+ },+ {+ currentPlanKey: BillingPlanKey.PRO_V2,+ targetPlanKey: BillingPlanKey.ORGANIZATION_V2,+ },+ { currentPlanKey: BillingPlanKey.PRO, targetPlanKey: undefined },+ ])(+ 'refuses $currentPlanKey to $targetPlanKey',+ ({ currentPlanKey, targetPlanKey }) => {+ expect(() =>+ getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey, plansConfig }),+ ).toThrow(+ expect.objectContaining({+ code: BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ }),+ );+ },+ );});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-sellable-plan-keys.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-sellable-plan-keys.util.spec.tsnew file mode 100644index 00000000000..26a61300cc1--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-sellable-plan-keys.util.spec.ts@@ -0,0 +1,29 @@+/* @license Enterprise */++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { getSellablePlanKeys } from 'src/engine/core-modules/billing/utils/get-sellable-plan-keys.util';++describe('getSellablePlanKeys', () => {+ it('returns the plans some plan can switch to', () => {+ expect(+ getSellablePlanKeys({+ [BillingPlanKey.PRO]: {+ upgradePlanKeys: [+ BillingPlanKey.PRO_V2,+ BillingPlanKey.ORGANIZATION_V2,+ ],+ },+ [BillingPlanKey.PRO_V2]: {+ upgradePlanKeys: [BillingPlanKey.ORGANIZATION_V2],+ },+ [BillingPlanKey.ORGANIZATION_V2]: {+ downgradePlanKeys: [BillingPlanKey.PRO_V2],+ },+ }),+ ).toEqual([BillingPlanKey.PRO_V2, BillingPlanKey.ORGANIZATION_V2]);+ });++ it('returns no plan without switches', () => {+ expect(getSellablePlanKeys({})).toEqual([]);+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/assert-plan-is-sellable-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/assert-plan-is-sellable-or-throw.util.tsnew file mode 100644index 00000000000..7093cc5a64d--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/assert-plan-is-sellable-or-throw.util.ts@@ -0,0 +1,22 @@+/* @license Enterprise */++import {+ BillingException,+ BillingExceptionCode,+} from 'src/engine/core-modules/billing/billing.exception';+import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';++export const assertPlanIsSellableOrThrow = ({+ planKey,+ sellablePlanKeys,+}: {+ planKey: BillingPlanKey;+ sellablePlanKeys: BillingPlanKey[];+}): void => {+ if (!sellablePlanKeys.includes(planKey)) {+ throw new BillingException(+ `Plan ${planKey} is not on sale`,+ BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ );+ }+};diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/find-default-plan-key.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/find-default-plan-key.util.tsnew file mode 100644index 00000000000..761b78464d7--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/find-default-plan-key.util.ts@@ -0,0 +1,15 @@+/* @license Enterprise */++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { type BillingPlansConfig } from 'src/engine/core-modules/billing/types/billing-plans-config.type';+import { getBillingPlanConfig } from 'src/engine/core-modules/billing/utils/get-billing-plan-config.util';++export const findDefaultPlanKey = (+ plansConfig: BillingPlansConfig,+): BillingPlanKey | undefined => {+ const defaultPlanKeys = Object.values(BillingPlanKey).filter(+ (planKey) => getBillingPlanConfig({ plansConfig, planKey }).isDefault,+ );++ return defaultPlanKeys.length === 1 ? defaultPlanKeys[0] : undefined;+};diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/format-database-product-to-graphql-dto.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/format-database-product-to-graphql-dto.util.tsindex 109877ab404..eed81266eee 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/format-database-product-to-graphql-dto.util.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/format-database-product-to-graphql-dto.util.ts@@ -18,6 +18,7 @@ export const formatBillingDatabaseProductToGraphqlDTO = (return {planKey: plan.planKey,isSellable: plan.isSellable,+ isCheckoutDefault: plan.isCheckoutDefault,upgradePlanKeys: plan.upgradePlanKeys,downgradePlanKeys: plan.downgradePlanKeys,baseProducts: plan.baseProducts.map((product) => {diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-plan-config.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-plan-config.util.tsnew file mode 100644index 00000000000..10cdbfe7889--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-plan-config.util.ts@@ -0,0 +1,19 @@+/* @license Enterprise */++import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import {+ type BillingPlanConfig,+ type BillingPlansConfig,+} from 'src/engine/core-modules/billing/types/billing-plans-config.type';++export const getBillingPlanConfig = ({+ plansConfig,+ planKey,+}: {+ plansConfig: BillingPlansConfig;+ planKey: BillingPlanKey;+}): BillingPlanConfig => ({+ isDefault: plansConfig[planKey]?.isDefault ?? false,+ upgradePlanKeys: plansConfig[planKey]?.upgradePlanKeys ?? [],+ downgradePlanKeys: plansConfig[planKey]?.downgradePlanKeys ?? [],+});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util.tsdeleted file mode 100644index 8c0d4e9d171..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util.ts+++ /dev/null@@ -1,25 +0,0 @@-/* @license Enterprise */--import {- BillingException,- BillingExceptionCode,-} from 'src/engine/core-modules/billing/billing.exception';-import { BILLING_SELLABLE_PLAN_KEYS } from 'src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant';-import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';--export const getCheckoutPlanKeyOrThrow = ({- planKey,-}: {- planKey?: BillingPlanKey | null;-}): BillingPlanKey => {- const checkoutPlanKey = planKey ?? BILLING_SELLABLE_PLAN_KEYS[0];-- if (!BILLING_SELLABLE_PLAN_KEYS.includes(checkoutPlanKey)) {- throw new BillingException(- `Plan ${checkoutPlanKey} is not on sale`,- BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,- );- }-- return checkoutPlanKey;-};diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util.tsindex 4fb6c830da5..99f724b0df8 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util.ts@@ -6,18 +6,23 @@ import {BillingException,BillingExceptionCode,} from 'src/engine/core-modules/billing/billing.exception';-import { BILLING_PLAN_SWITCHES } from 'src/engine/core-modules/billing/constants/billing-plan-switches.constant';import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { type BillingPlansConfig } from 'src/engine/core-modules/billing/types/billing-plans-config.type';+import { getBillingPlanConfig } from 'src/engine/core-modules/billing/utils/get-billing-plan-config.util';export const getPlanSwitchOrThrow = ({currentPlanKey,targetPlanKey,+ plansConfig,}: {currentPlanKey: BillingPlanKey;targetPlanKey?: BillingPlanKey;+ plansConfig: BillingPlansConfig;}): { targetPlanKey: BillingPlanKey } => {- const { upgradePlanKeys, downgradePlanKeys } =- BILLING_PLAN_SWITCHES[currentPlanKey];+ const { upgradePlanKeys, downgradePlanKeys } = getBillingPlanConfig({+ plansConfig,+ planKey: currentPlanKey,+ });const allowedTargetPlanKeys = [...upgradePlanKeys, ...downgradePlanKeys];if (!isDefined(targetPlanKey) && allowedTargetPlanKeys.length !== 1) {diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-sellable-plan-keys.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-sellable-plan-keys.util.tsnew file mode 100644index 00000000000..1cac36f2484--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-sellable-plan-keys.util.ts@@ -0,0 +1,19 @@+/* @license Enterprise */++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+import { type BillingPlansConfig } from 'src/engine/core-modules/billing/types/billing-plans-config.type';++export const getSellablePlanKeys = (+ plansConfig: BillingPlansConfig,+): BillingPlanKey[] => {+ const switchTargetPlanKeys = Object.values(plansConfig).flatMap(+ (planConfig) => [+ ...(planConfig?.upgradePlanKeys ?? []),+ ...(planConfig?.downgradePlanKeys ?? []),+ ],+ );++ return Object.values(BillingPlanKey).filter((planKey) =>+ switchTargetPlanKeys.includes(planKey),+ );+};diff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.tsindex 2d48cb2710c..87189714d08 100644--- a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts+++ b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts@@ -28,6 +28,8 @@ import { type AwsRegion } from 'src/engine/core-modules/twenty-config/interfacesimport { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';import { SupportDriver } from 'src/engine/core-modules/twenty-config/interfaces/support.interface';+import { IsBillingPlansConfig } from 'src/engine/core-modules/billing/decorators/is-billing-plans-config.decorator';+import { type BillingPlansConfig } from 'src/engine/core-modules/billing/types/billing-plans-config.type';import { CaptchaDriverType } from 'src/engine/core-modules/captcha/interfaces';import { CodeInterpreterDriverType } from 'src/engine/core-modules/code-interpreter/code-interpreter.interface';import { DpaRegion } from 'src/engine/core-modules/dpa/enums/dpa-region.enum';@@ -969,6 +971,17 @@ export class ConfigVariables {@ValidateIf((env) => env.IS_BILLING_ENABLED === true)BILLING_PLAN_REQUIRED_LINK: string;+ @ConfigVariablesMetadata({+ group: ConfigVariablesGroup.BILLING_CONFIG,+ description:+ 'Required when billing is enabled. How each billing plan is sold, as {"PRO":{"isDefault":true,"upgradePlanKeys":["ENTERPRISE"]},"ENTERPRISE":{"downgradePlanKeys":["PRO"]}}. Upgrades apply now with proration, downgrades at period end. A plan left out has no switch. The plans some plan can switch to are the two plans on sale, and the one marked isDefault is the default plan at signup',+ isHiddenInAdminPanel: true,+ type: ConfigVariableType.JSON,+ })+ @IsBillingPlansConfig()+ @ValidateIf((env) => env.IS_BILLING_ENABLED === true)+ BILLING_PLANS: BillingPlansConfig = {};+@ConfigVariablesMetadata({group: ConfigVariablesGroup.BILLING_CONFIG,description: 'Duration of free trial with credit card in days',diff --git a/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/failing-delegated-application-role-intersection.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/failing-delegated-application-role-intersection.integration-spec.tsindex d174c3eeb23..c2d17a6d4df 100644--- a/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/failing-delegated-application-role-intersection.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/failing-delegated-application-role-intersection.integration-spec.ts@@ -34,6 +34,7 @@ import {eachTestingContextFilter,} from 'twenty-shared/testing';+import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { type BaseGraphQLError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';@@ -86,7 +87,7 @@ const testCases: EachTestingContext<TestContext>[] = [context: {attempt: (token) =>checkoutSession({- input: { recurringInterval: 'Month' },+ input: { recurringInterval: 'Month', plan: BillingPlanKey.PRO },token,expectToFail: true,}),diff --git a/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/successful-delegated-application-role-intersection.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/successful-delegated-application-role-intersection.integration-spec.tsindex f7433b7ffdb..9072d30548d 100644--- a/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/successful-delegated-application-role-intersection.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/application-role-intersection/successful-delegated-application-role-intersection.integration-spec.ts@@ -25,6 +25,7 @@ import { updateOneView } from 'test/integration/metadata/suites/view/utils/updatimport { isDefined } from 'twenty-shared/utils';+import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { PermissionsExceptionMessage } from 'src/engine/metadata-modules/permissions/permissions.exception';import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';@@ -135,7 +136,7 @@ describe('A delegated application holding the flag acts like the session', () =>// downstream either way. What matters is that it is no longer the gate.it('should clear the billing checkout permission gate', async () => {const { errors } = await checkoutSession({- input: { recurringInterval: 'Month' },+ input: { recurringInterval: 'Month', plan: BillingPlanKey.PRO },token: token(),expectToFail: true,});diff --git a/packages/twenty-server/test/integration/graphql/suites/user-session/successful-user-session-and-application-access.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/user-session/successful-user-session-and-application-access.integration-spec.tsindex 691d67c8259..7e6eb19f005 100644--- a/packages/twenty-server/test/integration/graphql/suites/user-session/successful-user-session-and-application-access.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/user-session/successful-user-session-and-application-access.integration-spec.ts@@ -20,6 +20,7 @@ import {} from 'test/integration/metadata/suites/application/utils/setup-application-with-variable.util';import { SystemPermissionFlag } from 'twenty-shared/constants';+import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { SubscriptionInterval } from 'src/engine/core-modules/billing/enums/billing-subscription-interval.enum';import { AUTH_PRINCIPAL_REFUSED_MESSAGE } from 'src/engine/guards/constants/auth-principal-refused-message.constant';import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';@@ -357,7 +358,10 @@ describe('User session operations and application access that must keep working'// stopped it, leaving checkoutSession on its permission path.it('should reach the checkout session permission path', async () => {const { errors } = await checkoutSession({- input: { recurringInterval: SubscriptionInterval.Month },+ input: {+ recurringInterval: SubscriptionInterval.Month,+ plan: BillingPlanKey.PRO,+ },token: workspaceMembersApplicationToken,expectToFail: null,});diff --git a/packages/twenty-server/test/integration/graphql/suites/user-session/utils/checkout-session-query-factory.util.ts b/packages/twenty-server/test/integration/graphql/suites/user-session/utils/checkout-session-query-factory.util.tsindex 442e7d44891..9549a313935 100644--- a/packages/twenty-server/test/integration/graphql/suites/user-session/utils/checkout-session-query-factory.util.ts+++ b/packages/twenty-server/test/integration/graphql/suites/user-session/utils/checkout-session-query-factory.util.ts@@ -1,8 +1,11 @@import gql from 'graphql-tag';import { type PerformMetadataQueryParams } from 'test/integration/metadata/types/perform-metadata-query.type';+import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+export type CheckoutSessionFactoryInput = {recurringInterval: string;+ plan: BillingPlanKey;successUrlPath?: string;};@@ -12,10 +15,12 @@ export const checkoutSessionQueryFactory = ({query: gql`mutation CheckoutSession($recurringInterval: SubscriptionInterval!+ $plan: BillingPlanKey!$successUrlPath: String) {checkoutSession(recurringInterval: $recurringInterval+ plan: $plansuccessUrlPath: $successUrlPath) {url@@ -24,6 +29,7 @@ export const checkoutSessionQueryFactory = ({`,variables: {recurringInterval: input.recurringInterval,+ plan: input.plan,successUrlPath: input.successUrlPath,},});