The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(billing): support more than two billing plans with server-declared plan switches (#28080)
Etienne874ce93d109f
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphqlindex 3a112d2e9a2..2b70b5560c7 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql@@ -797,15 +797,20 @@ type BillingPaymentIntent {type BillingPlan {baseProducts: [BillingLicensedProduct!]!+ downgradePlanKeys: [BillingPlanKey!]!+ isSellable: Boolean!meteredProducts: [BillingMeteredProduct!]!planKey: BillingPlanKey!resourceCreditProducts: [BillingLicensedProduct!]!+ upgradePlanKeys: [BillingPlanKey!]!}"""The different billing plans available"""enum BillingPlanKey {ENTERPRISE+ ORGANIZATION_V2PRO+ PRO_V2}type BillingPriceLicensed {@@ -3166,7 +3171,7 @@ type Mutation {startWorkspaceSetupChat(companyContext: JSON, personContext: JSON): StartWorkspaceSetupChatResult!stopAgentChatStream(threadId: UUID!): Boolean!stopImpersonation: StopImpersonation!- switchBillingPlan: BillingUpdate!+ switchBillingPlan(plan: BillingPlanKey): BillingUpdate!switchSubscriptionInterval: BillingUpdate!syncApplication(dryRun: Boolean, inferDeletionFromMissingEntities: Boolean, manifest: JSON!): WorkspaceMigration!syncMarketplaceCatalog: Boolean!diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.tsindex 9f6c1b01e40..bde07e7a6c8 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts@@ -703,15 +703,18 @@ export interface BillingPaymentIntent {export interface BillingPlan {baseProducts: BillingLicensedProduct[]+ downgradePlanKeys: BillingPlanKey[]+ isSellable: Scalars['Boolean']meteredProducts: BillingMeteredProduct[]planKey: BillingPlanKeyresourceCreditProducts: BillingLicensedProduct[]+ upgradePlanKeys: BillingPlanKey[]__typename: 'BillingPlan'}/** The different billing plans available */-export type BillingPlanKey = 'ENTERPRISE' | 'PRO'+export type BillingPlanKey = 'ENTERPRISE' | 'ORGANIZATION_V2' | 'PRO' | 'PRO_V2'export interface BillingPriceLicensed {creditAmount?: Scalars['Float']@@ -4681,9 +4684,12 @@ export interface BillingPaymentIntentGenqlSelection{export interface BillingPlanGenqlSelection{baseProducts?: BillingLicensedProductGenqlSelection+ downgradePlanKeys?: boolean | number+ isSellable?: boolean | numbermeteredProducts?: BillingMeteredProductGenqlSelectionplanKey?: boolean | numberresourceCreditProducts?: BillingLicensedProductGenqlSelection+ upgradePlanKeys?: boolean | number__typename?: boolean | number__scalar?: boolean | number}@@ -6423,7 +6429,7 @@ export interface MutationGenqlSelection{startWorkspaceSetupChat?: (StartWorkspaceSetupChatResultGenqlSelection & { __args?: {companyContext?: (Scalars['JSON'] | null), personContext?: (Scalars['JSON'] | null)} })stopAgentChatStream?: { __args: {threadId: Scalars['UUID']} }stopImpersonation?: StopImpersonationGenqlSelection- switchBillingPlan?: BillingUpdateGenqlSelection+ switchBillingPlan?: (BillingUpdateGenqlSelection & { __args?: {plan?: (BillingPlanKey | null)} })switchSubscriptionInterval?: BillingUpdateGenqlSelectionsyncApplication?: (WorkspaceMigrationGenqlSelection & { __args: {dryRun?: (Scalars['Boolean'] | null), inferDeletionFromMissingEntities?: (Scalars['Boolean'] | null), manifest: Scalars['JSON']} })syncMarketplaceCatalog?: boolean | number@@ -11334,7 +11340,9 @@ export const enumBillingEntitlementKey = {export const enumBillingPlanKey = {ENTERPRISE: 'ENTERPRISE' as const,- PRO: 'PRO' as const+ ORGANIZATION_V2: 'ORGANIZATION_V2' as const,+ PRO: 'PRO' as const,+ PRO_V2: 'PRO_V2' as const}export const enumBillingProductKey = {diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.tsindex 7fe142b3bc4..fe453ecd397 100644--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts@@ -1741,6 +1741,12 @@ export default {"baseProducts": [86],+ "downgradePlanKeys": [+ 90+ ],+ "isSellable": [+ 4+ ],"meteredProducts": [87],@@ -1750,6 +1756,9 @@ export default {"resourceCreditProducts": [86],+ "upgradePlanKeys": [+ 90+ ],"__typename": [1]@@ -7890,7 +7899,12 @@ export default {463],"switchBillingPlan": [- 106+ 106,+ {+ "plan": [+ 90+ ]+ }],"switchSubscriptionInterval": [106diff --git a/packages/twenty-front/scripts/mock-data/generate-billing-plans.ts b/packages/twenty-front/scripts/mock-data/generate-billing-plans.tsindex c35d0dd1885..728fc32c9f6 100644--- a/packages/twenty-front/scripts/mock-data/generate-billing-plans.ts+++ b/packages/twenty-front/scripts/mock-data/generate-billing-plans.ts@@ -5,6 +5,9 @@ const LIST_PLANS_QUERY = `query listPlans {listPlans {planKey+ isSellable+ upgradePlanKeys+ downgradePlanKeyslicensedProducts {namedescriptiondiff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.tsindex 592b0e24c44..7ca0436e385 100644--- a/packages/twenty-front/src/generated-metadata/graphql.ts+++ b/packages/twenty-front/src/generated-metadata/graphql.ts@@ -869,15 +869,20 @@ export type BillingPaymentIntent = {export type BillingPlan = {__typename?: 'BillingPlan';baseProducts: Array<BillingLicensedProduct>;+ downgradePlanKeys: Array<BillingPlanKey>;+ isSellable: Scalars['Boolean']['output'];meteredProducts: Array<BillingMeteredProduct>;planKey: BillingPlanKey;resourceCreditProducts: Array<BillingLicensedProduct>;+ upgradePlanKeys: Array<BillingPlanKey>;};/** The different billing plans available */export enum BillingPlanKey {ENTERPRISE = 'ENTERPRISE',- PRO = 'PRO'+ ORGANIZATION_V2 = 'ORGANIZATION_V2',+ PRO = 'PRO',+ PRO_V2 = 'PRO_V2'}export type BillingPriceLicensed = {@@ -4378,6 +4383,11 @@ export type MutationStopAgentChatStreamArgs = {};+export type MutationSwitchBillingPlanArgs = {+ plan?: InputMaybe<BillingPlanKey>;+};++export type MutationSyncApplicationArgs = {dryRun?: InputMaybe<Scalars['Boolean']['input']>;inferDeletionFromMissingEntities?: InputMaybe<Scalars['Boolean']['input']>;@@ -10009,7 +10019,9 @@ export type SetResourceCreditSubscriptionPriceMutation = { __typename?: 'Mutatio| { __typename?: 'BillingMeteredProduct', name: string, description: string, images?: Array<string> | null, metadata: { __typename?: 'BillingProductMetadata', productKey: BillingProductKey, planKey: BillingPlanKey, priceUsageBased: BillingUsageType, isLegacy?: string | null } }}> | null }, billingSubscriptions: Array<{ __typename?: 'BillingSubscription', id: string, status: SubscriptionStatus, metadata: any, cancelAt?: string | null, phases: Array<{ __typename?: 'BillingSubscriptionSchedulePhase', start_date: number, end_date: number, items: Array<{ __typename?: 'BillingSubscriptionSchedulePhaseItem', price: string, quantity?: number | null }> }> }> } };-export type SwitchBillingPlanMutationVariables = Exact<{ [key: string]: never; }>;+export type SwitchBillingPlanMutationVariables = Exact<{+ plan?: InputMaybe<BillingPlanKey>;+}>;export type SwitchBillingPlanMutation = { __typename?: 'Mutation', switchBillingPlan: { __typename?: 'BillingUpdate', currentBillingSubscription: { __typename?: 'BillingSubscription', id: string, status: SubscriptionStatus, interval?: SubscriptionInterval | null, metadata: any, currentPeriodEnd?: string | null, cancelAt?: string | null, collectionMethod?: BillingSubscriptionCollectionMethod | null, phases: Array<{ __typename?: 'BillingSubscriptionSchedulePhase', start_date: number, end_date: number, items: Array<{ __typename?: 'BillingSubscriptionSchedulePhaseItem', price: string, quantity?: number | null }> }>, billingSubscriptionItems?: Array<{ __typename?: 'BillingSubscriptionItem', id: string, hasReachedCurrentPeriodCap: boolean, quantity?: number | null, stripePriceId: string, unitAmount?: number | null, creditAmount?: number | null, billingProduct:@@ -10048,7 +10060,7 @@ export type GetResourceCreditUsageQuery = { __typename?: 'Query', getResourceCreexport type ListPlansQueryVariables = Exact<{ [key: string]: never; }>;-export type ListPlansQuery = { __typename?: 'Query', listPlans: Array<{ __typename?: 'BillingPlan', planKey: 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, 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; }>;@@ -11105,12 +11117,12 @@ export const CreateUsageLimitDocument = {"kind":"Document","definitions":[{"kindexport const DeleteUsageLimitDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteUsageLimit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"usageLimitId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteUsageLimit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"usageLimitId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"usageLimitId"}}}]}]}}]} as unknown as DocumentNode<DeleteUsageLimitMutation, DeleteUsageLimitMutationVariables>;export const EndSubscriptionTrialPeriodDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"EndSubscriptionTrialPeriod"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"endSubscriptionTrialPeriod"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"hasPaymentMethod"}},{"kind":"Field","name":{"kind":"Name","value":"billingPortalUrl"}},{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"collectionMethod"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"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":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<EndSubscriptionTrialPeriodMutation, EndSubscriptionTrialPeriodMutationVariables>;export const SetResourceCreditSubscriptionPriceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SetResourceCreditSubscriptionPrice"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"priceId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"setResourceCreditSubscriptionPrice"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"priceId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"priceId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"collectionMethod"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"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":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SetResourceCreditSubscriptionPriceMutation, SetResourceCreditSubscriptionPriceMutationVariables>;-export const SwitchBillingPlanDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SwitchBillingPlan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"switchBillingPlan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"collectionMethod"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"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":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SwitchBillingPlanMutation, SwitchBillingPlanMutationVariables>;+export const SwitchBillingPlanDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SwitchBillingPlan"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"plan"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"BillingPlanKey"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"switchBillingPlan"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"plan"},"value":{"kind":"Variable","name":{"kind":"Name","value":"plan"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"collectionMethod"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"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":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SwitchBillingPlanMutation, SwitchBillingPlanMutationVariables>;export const SwitchSubscriptionIntervalDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SwitchSubscriptionInterval"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"switchSubscriptionInterval"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"collectionMethod"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"unitAmount"}},{"kind":"Field","name":{"kind":"Name","value":"creditAmount"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"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":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}}]} as unknown as DocumentNode<SwitchSubscriptionIntervalMutation, SwitchSubscriptionIntervalMutationVariables>;export 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":"usedCredits"}},{"kind":"Field","name":{"kind":"Name","value":"grantedCredits"}},{"kind":"Field","name":{"kind":"Name","value":"rolloverCredits"}},{"kind":"Field","name":{"kind":"Name","value":"totalGrantedCredits"}},{"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":"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":"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/auth/sign-in-up/hooks/__tests__/useSignInWithGoogle.test.ts b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithGoogle.test.tsindex 48dfe7965f0..a644e3dfcdf 100644--- a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithGoogle.test.ts+++ b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInWithGoogle.test.ts@@ -1,11 +1,8 @@import { useAuth } from '@/auth/hooks/useAuth';import { useSignInWithGoogle } from '@/auth/sign-in-up/hooks/useSignInWithGoogle';+import { BILLING_CHECKOUT_SESSION_DEFAULT_VALUE } from '@/settings/billing/constants/BillingCheckoutSessionDefaultValue';import { renderHook } from '@testing-library/react';import { useParams, useSearchParams } from 'react-router-dom';-import {- BillingPlanKey,- SubscriptionInterval,-} from '~/generated-metadata/graphql';import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper';jest.mock('react-router-dom', () => ({@@ -19,12 +16,6 @@ jest.mock('@/auth/hooks/useAuth', () => ({}));describe('useSignInWithGoogle', () => {- const mockBillingCheckoutSession = {- plan: BillingPlanKey.PRO,- interval: SubscriptionInterval.Month,- requirePaymentMethod: true,- };-const Wrapper = getJestMetadataAndApolloMocksWrapper({apolloMocks: [],});@@ -54,7 +45,7 @@ describe('useSignInWithGoogle', () => {action: 'join-workspace',workspaceInviteHash: 'testHash',workspacePersonalInviteToken: 'testToken',- billingCheckoutSession: mockBillingCheckoutSession,+ billingCheckoutSession: BILLING_CHECKOUT_SESSION_DEFAULT_VALUE,});});@@ -80,7 +71,7 @@ describe('useSignInWithGoogle', () => {action: 'join-workspace',workspaceInviteHash: 'testHash',workspacePersonalInviteToken: undefined,- billingCheckoutSession: mockBillingCheckoutSession,+ billingCheckoutSession: BILLING_CHECKOUT_SESSION_DEFAULT_VALUE,});});});diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInWithGoogle.ts b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInWithGoogle.tsindex e742589afd3..7c5ba8b0224 100644--- a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInWithGoogle.ts+++ b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInWithGoogle.ts@@ -1,23 +1,14 @@import { useParams, useSearchParams } from 'react-router-dom';import { useAuth } from '@/auth/hooks/useAuth';-import { type BillingCheckoutSession } from '@/auth/types/BillingCheckoutSession';import { type SocialSsoSignInUpActionType } from '@/auth/types/SocialSsoSignInUpActionType';-import {- BillingPlanKey,- SubscriptionInterval,-} from '~/generated-metadata/graphql';+import { BILLING_CHECKOUT_SESSION_DEFAULT_VALUE } from '@/settings/billing/constants/BillingCheckoutSessionDefaultValue';export const useSignInWithGoogle = () => {const workspaceInviteHash = useParams().workspaceInviteHash;const [searchParams] = useSearchParams();const workspacePersonalInviteToken =searchParams.get('inviteToken') ?? undefined;- const billingCheckoutSession = {- plan: BillingPlanKey.PRO,- interval: SubscriptionInterval.Month,- requirePaymentMethod: true,- } as BillingCheckoutSession;const { signInWithGoogle } = useAuth();@@ -26,7 +17,7 @@ export const useSignInWithGoogle = () => {signInWithGoogle({workspaceInviteHash,workspacePersonalInviteToken,- billingCheckoutSession,+ billingCheckoutSession: BILLING_CHECKOUT_SESSION_DEFAULT_VALUE,action,}),};diff --git a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceBillingContent.tsx b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceBillingContent.tsxindex 7d647141a36..ba0a9b5475a 100644--- a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceBillingContent.tsx+++ b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceBillingContent.tsx@@ -104,11 +104,9 @@ const STATUS_LABELS: Record<SubscriptionStatus, MessageDescriptor> = {};const toBillingPlanKey = (planKey: string): BillingPlanKey | null =>- planKey === BillingPlanKey.PRO- ? BillingPlanKey.PRO- : planKey === BillingPlanKey.ENTERPRISE- ? BillingPlanKey.ENTERPRISE- : null;+ Object.values(BillingPlanKey).find(+ (billingPlanKey) => billingPlanKey === planKey,+ ) ?? null;const StripeLink = ({path,diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansContent.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansContent.tsxindex 2f08647f73f..5d5596d8cb0 100644--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansContent.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansContent.tsx@@ -2,7 +2,9 @@ import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { SettingsBillingPlansWithSubscription } from '@/settings/billing/components/internal/SettingsBillingPlansWithSubscription';import { SettingsBillingPlansWithoutSubscription } from '@/settings/billing/components/internal/SettingsBillingPlansWithoutSubscription';import { useFormatPrices } from '@/settings/billing/hooks/useFormatPrices';+import { usePlans } from '@/settings/billing/hooks/usePlans';import { type SettingsBillingPlanInterval } from '@/settings/billing/types/SettingsBillingPlanComparison';+import { getComparedBillingPlanKeysOrThrow } from '@/settings/billing/utils/getComparedBillingPlanKeysOrThrow';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useState } from 'react';import { isDefined } from 'twenty-shared/utils';@@ -12,6 +14,7 @@ import { SubscriptionInterval } from '~/generated-metadata/graphql';export const SettingsBillingPlansContent = () => {const currentWorkspace = useAtomStateValue(currentWorkspaceState);const { formatPrices: planPrices } = useFormatPrices();+ const { listPlans } = usePlans();const [billingInterval, setBillingInterval] =useState<SettingsBillingPlanInterval>(SubscriptionInterval.Year);@@ -19,6 +22,8 @@ export const SettingsBillingPlansContent = () => {currentWorkspace?.currentBillingSubscription,);+ const comparedPlanKeys = getComparedBillingPlanKeysOrThrow(listPlans());+if (!isDefined(currentPlanKey) ||!isDefined(currentWorkspace?.currentBillingSubscription)@@ -26,6 +31,7 @@ export const SettingsBillingPlansContent = () => {return (<SettingsBillingPlansWithoutSubscriptionbillingInterval={billingInterval}+ comparedPlanKeys={comparedPlanKeys}onBillingIntervalChange={setBillingInterval}planPrices={planPrices}/>@@ -35,6 +41,7 @@ export const SettingsBillingPlansContent = () => {return (<SettingsBillingPlansWithSubscriptionbillingInterval={billingInterval}+ comparedPlanKeys={comparedPlanKeys}currentPlanKey={currentPlanKey}onBillingIntervalChange={setBillingInterval}planPrices={planPrices}diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingSubscriptionInfo.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingSubscriptionInfo.tsxindex 70afa72d42d..144f72c72d0 100644--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingSubscriptionInfo.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingSubscriptionInfo.tsx@@ -30,12 +30,11 @@ import { CombinedGraphQLErrors } from '@apollo/client/errors';import { useMutation } from '@apollo/client/react';import { useLingui } from '@lingui/react/macro';import { useState } from 'react';-import { isDefined } from 'twenty-shared/utils';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';import { useToast } from 'twenty-ui/components/feedback';import { Section } from 'twenty-ui/components/layout';import { IconClockPlay, IconCoins, IconTag } from 'twenty-ui/icon';import {- BillingPlanKey,CancelSwitchResourceCreditPriceDocument,PermissionFlagType,SubscriptionInterval,@@ -74,8 +73,7 @@ export const SettingsBillingSubscriptionInfo = ({const { currentResourceCreditBillingPrice } = useCurrentResourceCredit();const { currentPlan } = useCurrentPlan();- const { isEnterprisePlan, isYearlyPlan, isMonthlyPlan, isProPlan } =- useCurrentBillingFlags();+ const { isYearlyPlan, isMonthlyPlan } = useCurrentBillingFlags();const { splitedPhaseItemsInPrices } = useSplitPhaseItemsInPrices();const { nextBillingPhase } = useNextBillingPhase();@@ -197,21 +195,15 @@ export const SettingsBillingSubscriptionInfo = ({: t`Next charge ${totalRenewDate}. Invoice amount may vary if you add members or credits between periods`: t`Invoice amount may vary if you add members or credits between periods`;- const planLabel =- currentPlan.planKey === BillingPlanKey.PRO- ? t`Pro plan`- : t`Organization plan`;- const planName =- currentPlan.planKey === BillingPlanKey.PRO- ? t`pro plan`- : t`organization plan`;+ const billingPlanLabel = getBillingPlanLabel(currentPlan.planKey);+ const planLabel = t`${billingPlanLabel} plan`;const intervalUnit =currentInterval === SubscriptionInterval.Month ? t`month` : t`year`;const startSubscriptionSubtitle = isSendInvoice- ? t`We will activate your ${planName} and email your invoice now. Do you want to proceed?`+ ? t`We will activate your ${planLabel} and email your invoice now. Do you want to proceed?`: isDefined(perSeatPriceDisplay)- ? t`We will activate your $${perSeatPriceDisplay}/user/${intervalUnit} ${planName}. Do you want to proceed?`- : t`We will activate your ${planName}. Do you want to proceed?`;+ ? t`We will activate your $${perSeatPriceDisplay}/user/${intervalUnit} ${planLabel}. Do you want to proceed?`+ : t`We will activate your ${planLabel}. Do you want to proceed?`;const statusDescriptor = (() => {if (isCancellationScheduled) {@@ -282,9 +274,11 @@ export const SettingsBillingSubscriptionInfo = ({!shouldUpdatePayment &&isYearlyPlan &&(!nextInterval || currentInterval === nextInterval);+ const hasPlanUpgrade = isNonEmptyArray(currentPlan.upgradePlanKeys);+ const hasPlanSwitch =+ hasPlanUpgrade || isNonEmptyArray(currentPlan.downgradePlanKeys);const canComparePlans =- (isProPlan || isEnterprisePlan) &&- (!nextPlan || currentPlan.planKey === nextPlan.planKey);+ hasPlanSwitch && (!nextPlan || currentPlan.planKey === nextPlan.planKey);const canCancelIntervalSwitch =isDefined(nextInterval) && currentInterval !== nextInterval;const canStartSubscription = isTrialPeriod && hasPermissionToEndTrialPeriod;@@ -414,7 +408,7 @@ export const SettingsBillingSubscriptionInfo = ({canCancelPlanSwitch={canCancelPlanSwitch}canComparePlans={canComparePlans}canStartSubscription={canStartSubscription}- isComparePlansActionPrimary={isProPlan && !isTrialPeriod}+ isComparePlansActionPrimary={hasPlanUpgrade && !isTrialPeriod}isCancellationScheduled={isCancellationScheduled}isEndTrialPeriodDisabled={isEndTrialPeriodLoading || isAnyActionLoadingdiff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingTrialNoPaymentMethodBanner.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingTrialNoPaymentMethodBanner.tsxindex b1dae39e118..9141e7a7a5d 100644--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingTrialNoPaymentMethodBanner.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingTrialNoPaymentMethodBanner.tsx@@ -1,6 +1,7 @@import { ToastOnQueryErrorEffect } from '@/apollo/components/ToastOnQueryErrorEffect';import { type CurrentWorkspace } from '@/auth/states/currentWorkspaceState';import { useRedirect } from '@/domain-manager/hooks/useRedirect';+import { BILLING_PLAN_LABELS } from '@/settings/billing/constants/BillingPlanLabels';import { getSubscriptionPlanKey } from '@/settings/billing/utils/getSubscriptionPlanKey';import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';import { useQuery } from '@apollo/client/react';@@ -9,7 +10,6 @@ import { SettingsPath } from 'twenty-shared/types';import { getSettingsPath, isDefined } from 'twenty-shared/utils';import { InlineBanner } from 'twenty-ui/components/feedback';import {- BillingPlanKey,BillingPortalSessionDocument,PermissionFlagType,} from '~/generated-metadata/graphql';@@ -44,10 +44,13 @@ export const SettingsBillingTrialNoPaymentMethodBanner = ({}};- const planName =- getSubscriptionPlanKey(currentBillingSubscription) === BillingPlanKey.PRO- ? t`pro plan`- : t`organization plan`;+ const planKey = getSubscriptionPlanKey(currentBillingSubscription);+ const billingPlanLabel = isDefined(planKey)+ ? t(BILLING_PLAN_LABELS[planKey])+ : undefined;+ const planName = isDefined(billingPlanLabel)+ ? t`${billingPlanLabel} plan`+ : t`current plan`;const trialEndDate = isDefined(currentBillingSubscription.currentPeriodEnd)? formatDate(currentBillingSubscription.currentPeriodEnd, 'MMM dd')diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/PlansTags.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/PlansTags.tsxindex be6b3f02e92..334753c8f33 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/PlansTags.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/PlansTags.tsx@@ -1,7 +1,9 @@import React from 'react';import { Tag } from 'twenty-ui/primitives/data-display';import { t } from '@lingui/core/macro';-import { BillingPlanKey } from '~/generated-metadata/graphql';+import { BILLING_PLAN_LABELS } from '@/settings/billing/constants/BillingPlanLabels';+import { BILLING_PLAN_TAG_COLORS } from '@/settings/billing/constants/BillingPlanTagColors';+import { type BillingPlanKey } from '~/generated-metadata/graphql';import { styled } from '@linaria/react';import { themeCssVariables } from 'twenty-ui/theme';@@ -20,14 +22,11 @@ const StyledTrialTag = styled(Tag)``;export const PlansTags = ({ plan, isTrialPeriod = false }: PlansTagsProps) => {- const planDescriptor =- plan === BillingPlanKey.PRO- ? { color: 'sky' as const, label: t`Pro` }- : { color: 'purple' as const, label: t`Organization` };-return (<StyledTagsWrapper>- <Tag color={planDescriptor.color}>{planDescriptor.label}</Tag>+ <Tag color={BILLING_PLAN_TAG_COLORS[plan]}>+ {t(BILLING_PLAN_LABELS[plan])}+ </Tag>{isTrialPeriod && (<StyledTrialTag color="blue" truncate={false}>{t`Trial`}diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsxindex fee1e21a93f..d955fca3743 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTable.tsx@@ -1,9 +1,9 @@import { isDefined } from 'twenty-shared/utils';import { AnimatedFormattedNumber } from '@/settings/billing/components/internal/AnimatedFormattedNumber';import { SettingsBillingPlanComparisonTableRow } from '@/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow';-import { SETTINGS_BILLING_COMPARED_PLAN_KEYS } from '@/settings/billing/constants/SettingsBillingComparedPlanKeys';+import { BILLING_PLAN_LABELS } from '@/settings/billing/constants/BillingPlanLabels';import { SETTINGS_BILLING_PLAN_COMPARISON_ROWS } from '@/settings/billing/constants/SettingsBillingPlanComparisonRows';-import { type SettingsBillingPlanAction } from '@/settings/billing/types/SettingsBillingPlanAction';+import { type SettingsBillingComparedPlan } from '@/settings/billing/types/SettingsBillingComparedPlan';import {type SettingsBillingPlanInterval,type SettingsBillingPlanPrices,@@ -18,16 +18,16 @@ import {import { Button } from 'twenty-ui/primitives/input';import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme';import {- BillingPlanKey,+ type BillingPlanKey,SubscriptionInterval,} from '~/generated-metadata/graphql';type SettingsBillingPlanComparisonTableProps = {billingInterval: SettingsBillingPlanInterval;+ comparedPlans: SettingsBillingComparedPlan[];onBillingIntervalChange: (billingInterval: SettingsBillingPlanInterval,) => void;- planActions: Record<BillingPlanKey, SettingsBillingPlanAction>;planPrices: SettingsBillingPlanPrices;};@@ -196,8 +196,8 @@ const StyledActionSlot = styled.div`export const SettingsBillingPlanComparisonTable = ({billingInterval,+ comparedPlans,onBillingIntervalChange,- planActions,planPrices,}: SettingsBillingPlanComparisonTableProps) => {const { t } = useLingui();@@ -207,7 +207,7 @@ export const SettingsBillingPlanComparisonTable = ({formatNumber(Math.max(0, value));const getPlanTitle = (planKey: BillingPlanKey) =>- planKey === BillingPlanKey.PRO ? t`Pro plan` : t`Organization`;+ t(BILLING_PLAN_LABELS[planKey]);const billingIntervalOptions = [{@@ -243,8 +243,7 @@ export const SettingsBillingPlanComparisonTable = ({/></StyledHeaderCell>- {SETTINGS_BILLING_COMPARED_PLAN_KEYS.map((planKey) => {- const action = planActions[planKey];+ {comparedPlans.map(({ action, planKey }) => {const price = planPrices[planKey][billingInterval];return (@@ -284,7 +283,7 @@ export const SettingsBillingPlanComparisonTable = ({</StyledStickyHeaderContainer><StyledMobilePlanNamesGrid aria-hidden>- {SETTINGS_BILLING_COMPARED_PLAN_KEYS.map((planKey) => (+ {comparedPlans.map(({ planKey }) => (<StyledMobilePlanName key={planKey}>{getPlanTitle(planKey)}</StyledMobilePlanName>@@ -296,6 +295,7 @@ export const SettingsBillingPlanComparisonTable = ({<SettingsBillingPlanComparisonTableRowkey={`row-${rowIndex}`}hasTopBorder={rowIndex > 0}+ planKeys={comparedPlans.map(({ planKey }) => planKey)}row={row}/>))}diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsxindex 7bdedc36a3b..c028d2f04a5 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlanComparisonTableRow.tsx@@ -1,4 +1,3 @@-import { SETTINGS_BILLING_COMPARED_PLAN_KEYS } from '@/settings/billing/constants/SettingsBillingComparedPlanKeys';import {type SettingsBillingPlanComparisonCell,type SettingsBillingPlanComparisonRow,@@ -7,6 +6,7 @@ import { useLingui } from '@lingui/react/macro';import { styled } from '@linaria/react';import { IconCheck, IconX } from 'twenty-ui/icon';import { MOBILE_VIEWPORT, themeCssVariables, useTheme } from 'twenty-ui/theme';+import { type BillingPlanKey } from '~/generated-metadata/graphql';const StyledFeatureCell = styled.div<{hasTopBorder?: boolean;@@ -120,9 +120,11 @@ const SettingsBillingPlanComparisonCellContent = ({export const SettingsBillingPlanComparisonTableRow = ({hasTopBorder = false,+ planKeys,row,}: {hasTopBorder?: boolean;+ planKeys: BillingPlanKey[];row: SettingsBillingPlanComparisonRow;}) => {const { i18n } = useLingui();@@ -140,7 +142,7 @@ export const SettingsBillingPlanComparisonTableRow = ({<StyledFeatureLabelCell hasTopBorder={hasTopBorder} isLabel><StyledCellText>{i18n._(row.featureLabel)}</StyledCellText></StyledFeatureLabelCell>- {SETTINGS_BILLING_COMPARED_PLAN_KEYS.map((planKey) => (+ {planKeys.map((planKey) => (<StyledFeatureCell hasTopBorder={hasTopBorder} key={planKey}><SettingsBillingPlanComparisonCellContent cell={row.plans[planKey]} /></StyledFeatureCell>diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithSubscription.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithSubscription.tsxindex 039231100e6..db24b6acfec 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithSubscription.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithSubscription.tsx@@ -5,6 +5,7 @@ import { useBillingPlanActions } from '@/settings/billing/hooks/useBillingPlanAcimport { useBillingSubscriptionChangeWording } from '@/settings/billing/hooks/useBillingSubscriptionChangeWording';import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';import {+ type SettingsBillingComparedPlanKeys,type SettingsBillingPlanInterval,type SettingsBillingPlanPrices,} from '@/settings/billing/types/SettingsBillingPlanComparison';@@ -18,6 +19,7 @@ import { type BillingPlanKey } from '~/generated-metadata/graphql';type SettingsBillingPlansWithSubscriptionProps = {billingInterval: SettingsBillingPlanInterval;+ comparedPlanKeys: SettingsBillingComparedPlanKeys;currentPlanKey: BillingPlanKey;onBillingIntervalChange: (billingInterval: SettingsBillingPlanInterval,@@ -27,6 +29,7 @@ type SettingsBillingPlansWithSubscriptionProps = {export const SettingsBillingPlansWithSubscription = ({billingInterval,+ comparedPlanKeys,currentPlanKey,onBillingIntervalChange,planPrices,@@ -41,8 +44,9 @@ export const SettingsBillingPlansWithSubscription = ({} = useApplyBillingSubscriptionChange();const { getBillingSubscriptionChangeWording } =useBillingSubscriptionChangeWording();- const { planActions } = useBillingPlanActions({+ const { comparedPlans } = useBillingPlanActions({billingInterval,+ comparedPlanKeys,currentPlanKey,isApplyingBillingSubscriptionChange,onBillingSubscriptionChangeRequested: (change) => {@@ -62,8 +66,8 @@ export const SettingsBillingPlansWithSubscription = ({<SettingsPageContainer overflow="visible"><SettingsBillingPlanComparisonTablebillingInterval={billingInterval}+ comparedPlans={comparedPlans}onBillingIntervalChange={onBillingIntervalChange}- planActions={planActions}planPrices={planPrices}/>{isDefined(pendingChange) && isDefined(pendingChangeWording) && (diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithoutSubscription.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithoutSubscription.tsxindex 46d5eca8d30..3ccca87823a 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithoutSubscription.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/SettingsBillingPlansWithoutSubscription.tsx@@ -1,7 +1,9 @@import { SettingsBillingPlanComparisonTable } from '@/settings/billing/components/internal/SettingsBillingPlanComparisonTable';import { useHandleCheckoutSession } from '@/settings/billing/hooks/useHandleCheckoutSession';import { type SettingsBillingPlanAction } from '@/settings/billing/types/SettingsBillingPlanAction';+import { type SettingsBillingComparedPlan } from '@/settings/billing/types/SettingsBillingComparedPlan';import {+ type SettingsBillingComparedPlanKeys,type SettingsBillingPlanInterval,type SettingsBillingPlanPrices,} from '@/settings/billing/types/SettingsBillingPlanComparison';@@ -9,10 +11,10 @@ import { SettingsPageContainer } from '@/settings/components/SettingsPageContainimport { useLingui } from '@lingui/react/macro';import { SettingsPath } from 'twenty-shared/types';import { getSettingsPath } from 'twenty-shared/utils';-import { BillingPlanKey } from '~/generated-metadata/graphql';type SettingsBillingPlansWithoutSubscriptionProps = {billingInterval: SettingsBillingPlanInterval;+ comparedPlanKeys: SettingsBillingComparedPlanKeys;onBillingIntervalChange: (billingInterval: SettingsBillingPlanInterval,) => void;@@ -21,25 +23,27 @@ type SettingsBillingPlansWithoutSubscriptionProps = {export const SettingsBillingPlansWithoutSubscription = ({billingInterval,+ comparedPlanKeys,onBillingIntervalChange,planPrices,}: SettingsBillingPlansWithoutSubscriptionProps) => {const { t } = useLingui();+ const [firstPlanKey, secondPlanKey] = comparedPlanKeys;const {- handleCheckoutSession: handleProCheckoutSession,- isSubmitting: isProCheckoutSessionSubmitting,+ handleCheckoutSession: handleFirstPlanCheckoutSession,+ isSubmitting: isFirstPlanCheckoutSessionSubmitting,} = useHandleCheckoutSession({recurringInterval: billingInterval,- plan: BillingPlanKey.PRO,+ plan: firstPlanKey,requirePaymentMethod: true,successUrlPath: getSettingsPath(SettingsPath.Billing),});const {- handleCheckoutSession: handleEnterpriseCheckoutSession,- isSubmitting: isEnterpriseCheckoutSessionSubmitting,+ handleCheckoutSession: handleSecondPlanCheckoutSession,+ isSubmitting: isSecondPlanCheckoutSessionSubmitting,} = useHandleCheckoutSession({recurringInterval: billingInterval,- plan: BillingPlanKey.ENTERPRISE,+ plan: secondPlanKey,requirePaymentMethod: true,successUrlPath: getSettingsPath(SettingsPath.Billing),});@@ -62,27 +66,34 @@ export const SettingsBillingPlansWithoutSubscription = ({});const isAnyCheckoutSessionSubmitting =- isProCheckoutSessionSubmitting || isEnterpriseCheckoutSessionSubmitting;+ isFirstPlanCheckoutSessionSubmitting ||+ isSecondPlanCheckoutSessionSubmitting;- const planActions: Record<BillingPlanKey, SettingsBillingPlanAction> = {- [BillingPlanKey.PRO]: createChoosePlanAction({- handleCheckoutSession: handleProCheckoutSession,- isDisabled: isAnyCheckoutSessionSubmitting,- isLoading: isProCheckoutSessionSubmitting,- }),- [BillingPlanKey.ENTERPRISE]: createChoosePlanAction({- handleCheckoutSession: handleEnterpriseCheckoutSession,- isDisabled: isAnyCheckoutSessionSubmitting,- isLoading: isEnterpriseCheckoutSessionSubmitting,- }),- };+ const comparedPlans: SettingsBillingComparedPlan[] = [+ {+ planKey: firstPlanKey,+ action: createChoosePlanAction({+ handleCheckoutSession: handleFirstPlanCheckoutSession,+ isDisabled: isAnyCheckoutSessionSubmitting,+ isLoading: isFirstPlanCheckoutSessionSubmitting,+ }),+ },+ {+ planKey: secondPlanKey,+ action: createChoosePlanAction({+ handleCheckoutSession: handleSecondPlanCheckoutSession,+ isDisabled: isAnyCheckoutSessionSubmitting,+ isLoading: isSecondPlanCheckoutSessionSubmitting,+ }),+ },+ ];return (<SettingsPageContainer overflow="visible"><SettingsBillingPlanComparisonTablebillingInterval={billingInterval}+ comparedPlans={comparedPlans}onBillingIntervalChange={onBillingIntervalChange}- planActions={planActions}planPrices={planPrices}/></SettingsPageContainer>diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsxindex fc9f805785a..fe9b0d88cba 100644--- a/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/SettingsBillingPlanComparisonTable.stories.tsx@@ -34,13 +34,16 @@ const meta = {args: {billingInterval: SubscriptionInterval.Year,onBillingIntervalChange: fn(),- planActions: {- [BillingPlanKey.PRO]: { title: 'Choose Pro', variant: 'solid' },- [BillingPlanKey.ENTERPRISE]: {- title: 'Choose Organization',- variant: 'outline',+ comparedPlans: [+ {+ action: { title: 'Choose Pro', variant: 'solid' },+ planKey: BillingPlanKey.PRO,},- },+ {+ action: { title: 'Choose Organization', variant: 'outline' },+ planKey: BillingPlanKey.ENTERPRISE,+ },+ ],planPrices: {[BillingPlanKey.PRO]: {[SubscriptionInterval.Year]: 9,@@ -50,6 +53,14 @@ const meta = {[SubscriptionInterval.Year]: 19,[SubscriptionInterval.Month]: 25,},+ [BillingPlanKey.PRO_V2]: {+ [SubscriptionInterval.Year]: 9,+ [SubscriptionInterval.Month]: 12,+ },+ [BillingPlanKey.ORGANIZATION_V2]: {+ [SubscriptionInterval.Year]: 19,+ [SubscriptionInterval.Month]: 25,+ },},},render: (args) => <BillingComparison {...args} />,diff --git a/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanLabels.ts b/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanLabels.tsnew file mode 100644index 00000000000..d500944b5d2--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanLabels.ts@@ -0,0 +1,11 @@+import { type MessageDescriptor } from '@lingui/core';+import { msg } from '@lingui/core/macro';++import { BillingPlanKey } from '~/generated-metadata/graphql';++export const BILLING_PLAN_LABELS: Record<BillingPlanKey, MessageDescriptor> = {+ [BillingPlanKey.PRO]: msg`Pro`,+ [BillingPlanKey.ENTERPRISE]: msg`Organization`,+ [BillingPlanKey.PRO_V2]: msg`Pro`,+ [BillingPlanKey.ORGANIZATION_V2]: msg`Organization`,+};diff --git a/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanTagColors.ts b/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanTagColors.tsnew file mode 100644index 00000000000..c0d53d9a343--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/constants/BillingPlanTagColors.ts@@ -0,0 +1,10 @@+import { type TagColor } from 'twenty-ui/primitives/data-display';++import { BillingPlanKey } from '~/generated-metadata/graphql';++export const BILLING_PLAN_TAG_COLORS: Record<BillingPlanKey, TagColor> = {+ [BillingPlanKey.PRO]: 'sky',+ [BillingPlanKey.ENTERPRISE]: 'purple',+ [BillingPlanKey.PRO_V2]: 'sky',+ [BillingPlanKey.ORGANIZATION_V2]: 'purple',+};diff --git a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingComparedPlanKeys.ts b/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingComparedPlanKeys.tsdeleted file mode 100644index c41eae44d98..00000000000--- a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingComparedPlanKeys.ts+++ /dev/null@@ -1,6 +0,0 @@-import { BillingPlanKey } from '~/generated-metadata/graphql';--export const SETTINGS_BILLING_COMPARED_PLAN_KEYS = [- BillingPlanKey.PRO,- BillingPlanKey.ENTERPRISE,-] as const;diff --git a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanComparisonRows.ts b/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanComparisonRows.tsindex efed9a54225..22c58562011 100644--- a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanComparisonRows.ts+++ b/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanComparisonRows.ts@@ -8,7 +8,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Seats limit`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -17,7 +19,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom objects`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -25,7 +29,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom fields`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -33,7 +39,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom views`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -44,10 +52,18 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [kind: 'text',text: msg`Table, Kanban, Calendar`,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ kind: 'text',+ text: msg`Table, Kanban, Calendar`,+ },[BillingPlanKey.PRO]: {kind: 'text',text: msg`Table, Kanban, Calendar`,},+ [BillingPlanKey.PRO_V2]: {+ kind: 'text',+ text: msg`Table, Kanban, Calendar`,+ },},type: 'feature',},@@ -55,7 +71,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom layout`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -63,7 +81,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Records`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -71,7 +91,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`CSV import & export`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -79,7 +101,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Languages`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`30+` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`30+` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`30+` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`30+` },},type: 'feature',},@@ -88,7 +112,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Number of dashboards`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -97,7 +123,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Internet accounts per user`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -105,7 +133,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Folder/Label import`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -116,7 +146,12 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [kind: 'text',text: msg`Fully customizable`,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ kind: 'text',+ text: msg`Fully customizable`,+ },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Fully customizable` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Fully customizable` },},type: 'feature',},@@ -125,7 +160,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Workflows`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -133,7 +170,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`AI agents`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -142,7 +181,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Two-factor authentication`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -150,7 +191,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`User roles`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -158,7 +201,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Read/Edit/Delete permissions`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -166,7 +211,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Field-level permissions`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -174,7 +221,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Row-level permissions`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -182,7 +231,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`SSO`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -190,7 +241,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Encryption key rotation`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -198,7 +251,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Record change logs`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -206,7 +261,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Audit logs`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -217,7 +274,12 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [kind: 'text',text: msg`Custom, up to 3 years`,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ kind: 'text',+ text: msg`Custom, up to 3 years`,+ },[BillingPlanKey.PRO]: { kind: 'text', text: msg`2 hours` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`2 hours` },},type: 'feature',},@@ -228,7 +290,12 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [kind: 'text',text: msg`Local, Production`,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ kind: 'text',+ text: msg`Local, Production`,+ },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Local, Production` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Local, Production` },},type: 'feature',},@@ -236,7 +303,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Impersonate users`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -245,7 +314,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Community`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -253,7 +324,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Help center`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -261,7 +334,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Email and Chat`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -269,7 +344,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Priority support`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -277,7 +354,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Onboarding Packs`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -285,7 +364,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Implementation partners`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -294,7 +375,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom apps`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'text', text: msg`Unlimited` },[BillingPlanKey.PRO]: { kind: 'text', text: msg`Unlimited` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`Unlimited` },},type: 'feature',},@@ -302,7 +385,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Subdomain (yourco.twenty.com)`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -310,7 +395,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Custom domain (crm.yourco.com)`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -319,7 +406,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`REST & GraphQL API`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -327,7 +416,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Webhooks`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -335,7 +426,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`MCP server`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -343,7 +436,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`App logs`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'included' },+ [BillingPlanKey.PRO_V2]: { kind: 'included' },},type: 'feature',},@@ -351,7 +446,9 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`Install shared tarball app`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'included' },+ [BillingPlanKey.ORGANIZATION_V2]: { kind: 'included' },[BillingPlanKey.PRO]: { kind: 'excluded' },+ [BillingPlanKey.PRO_V2]: { kind: 'excluded' },},type: 'feature',},@@ -359,7 +456,12 @@ export const SETTINGS_BILLING_PLAN_COMPARISON_ROWS = [featureLabel: msg`API calls`,plans: {[BillingPlanKey.ENTERPRISE]: { kind: 'text', text: msg`100 per minute` },+ [BillingPlanKey.ORGANIZATION_V2]: {+ kind: 'text',+ text: msg`100 per minute`,+ },[BillingPlanKey.PRO]: { kind: 'text', text: msg`50 per minute` },+ [BillingPlanKey.PRO_V2]: { kind: 'text', text: msg`50 per minute` },},type: 'feature',},diff --git a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanPriceFallbacks.ts b/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanPriceFallbacks.tsindex 2682d92ad29..029ef2360e0 100644--- a/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanPriceFallbacks.ts+++ b/packages/twenty-front/src/modules/settings/billing/constants/SettingsBillingPlanPriceFallbacks.ts@@ -14,4 +14,12 @@ export const SETTINGS_BILLING_PLAN_PRICE_FALLBACKS = {[SubscriptionInterval.Month]: 25,[SubscriptionInterval.Year]: 19,},+ [BillingPlanKey.PRO_V2]: {+ [SubscriptionInterval.Month]: 12,+ [SubscriptionInterval.Year]: 9,+ },+ [BillingPlanKey.ORGANIZATION_V2]: {+ [SubscriptionInterval.Month]: 25,+ [SubscriptionInterval.Year]: 19,+ },} satisfies SettingsBillingPlanPrices;diff --git a/packages/twenty-front/src/modules/settings/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.ts b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.tsindex d2723f9b6ed..4091eff0ca4 100644--- a/packages/twenty-front/src/modules/settings/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.ts+++ b/packages/twenty-front/src/modules/settings/billing/graphql/mutations/switchSubscriptionToEnterprisePlan.ts@@ -1,8 +1,8 @@import { gql } from '@apollo/client';export const SWITCH_BILLING_PLAN = gql`- mutation SwitchBillingPlan {- switchBillingPlan {+ mutation SwitchBillingPlan($plan: BillingPlanKey) {+ switchBillingPlan(plan: $plan) {currentBillingSubscription {...CurrentBillingSubscriptionFragment}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 2f62b580fb6..1eddd23d9a9 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@@ -6,6 +6,9 @@ export const LIST_PLANS = gql`query listPlans {listPlans {planKey+ isSellable+ upgradePlanKeys+ downgradePlanKeysbaseProducts {namedescriptiondiff --git a/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/useFormatPrices.test.ts b/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/useFormatPrices.test.tsindex 11a5988ad95..684615f14cc 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/useFormatPrices.test.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/useFormatPrices.test.ts@@ -1,4 +1,8 @@import { useFormatPrices } from '@/settings/billing/hooks/useFormatPrices';+import {+ type SettingsBillingPlanInterval,+ type SettingsBillingPlanPrices,+} from '@/settings/billing/types/SettingsBillingPlanComparison';import {BillingPlanKey,SubscriptionInterval,@@ -16,22 +20,34 @@ jest.mock(}),);+const UNIT_AMOUNTS: SettingsBillingPlanPrices = {+ [BillingPlanKey.PRO]: {+ [SubscriptionInterval.Month]: 1200,+ [SubscriptionInterval.Year]: 10800,+ },+ [BillingPlanKey.ENTERPRISE]: {+ [SubscriptionInterval.Month]: 2500,+ [SubscriptionInterval.Year]: 22800,+ },+ [BillingPlanKey.PRO_V2]: {+ [SubscriptionInterval.Month]: 1500,+ [SubscriptionInterval.Year]: 14400,+ },+ [BillingPlanKey.ORGANIZATION_V2]: {+ [SubscriptionInterval.Month]: 3000,+ [SubscriptionInterval.Year]: 28800,+ },+};+describe('useFormatPrices', () => {beforeEach(() => {mockGetBaseLicensedPriceByPlanKeyAndInterval.mockReset();});- it('formats monthly prices from Stripe unit amounts', () => {+ it('formats monthly prices from Stripe unit amounts for every plan', () => {mockGetBaseLicensedPriceByPlanKeyAndInterval.mockImplementation(- (planKey: BillingPlanKey, interval: SubscriptionInterval) => ({- unitAmount:- planKey === BillingPlanKey.PRO- ? interval === SubscriptionInterval.Year- ? 10800- : 1200- : interval === SubscriptionInterval.Year- ? 22800- : 2500,+ (planKey: BillingPlanKey, interval: SettingsBillingPlanInterval) => ({+ unitAmount: UNIT_AMOUNTS[planKey][interval],}),);@@ -42,10 +58,18 @@ describe('useFormatPrices', () => {[SubscriptionInterval.Month]: 25,[SubscriptionInterval.Year]: 19,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ [SubscriptionInterval.Month]: 30,+ [SubscriptionInterval.Year]: 24,+ },[BillingPlanKey.PRO]: {[SubscriptionInterval.Month]: 12,[SubscriptionInterval.Year]: 9,},+ [BillingPlanKey.PRO_V2]: {+ [SubscriptionInterval.Month]: 15,+ [SubscriptionInterval.Year]: 12,+ },});});@@ -61,10 +85,18 @@ describe('useFormatPrices', () => {[SubscriptionInterval.Month]: 25,[SubscriptionInterval.Year]: 19,},+ [BillingPlanKey.ORGANIZATION_V2]: {+ [SubscriptionInterval.Month]: 25,+ [SubscriptionInterval.Year]: 19,+ },[BillingPlanKey.PRO]: {[SubscriptionInterval.Month]: 12,[SubscriptionInterval.Year]: 9,},+ [BillingPlanKey.PRO_V2]: {+ [SubscriptionInterval.Month]: 12,+ [SubscriptionInterval.Year]: 9,+ },});});});diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useApplyBillingSubscriptionChange.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useApplyBillingSubscriptionChange.tsindex d64bf8c4a0c..88316640324 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useApplyBillingSubscriptionChange.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useApplyBillingSubscriptionChange.ts@@ -1,5 +1,6 @@import { useApplyCurrentWorkspaceBillingUpdate } from '@/settings/billing/hooks/useApplyCurrentWorkspaceBillingUpdate';import { useBillingWording } from '@/settings/billing/hooks/useBillingWording';+import { useCurrentPlan } from '@/settings/billing/hooks/useCurrentPlan';import { useGetResourceCreditUsage } from '@/settings/billing/hooks/useGetResourceCreditUsage';import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';import { isBillingSubscriptionChangeImmediate } from '@/settings/billing/utils/isBillingSubscriptionChangeImmediate';@@ -26,6 +27,7 @@ export const useApplyBillingSubscriptionChange = () => {useApplyCurrentWorkspaceBillingUpdate();const { refetchResourceCreditUsage } = useGetResourceCreditUsage();const { getBeautifiedRenewDate, getBillingPlanLabel } = useBillingWording();+ const { currentPlan } = useCurrentPlan();const [switchBillingPlanMutation] = useMutation(SwitchBillingPlanDocument);const [switchSubscriptionIntervalMutation] = useMutation(@@ -48,7 +50,9 @@ export const useApplyBillingSubscriptionChange = () => {) => {switch (change.type) {case 'SWITCH_PLAN': {- const { data } = await switchBillingPlanMutation();+ const { data } = await switchBillingPlanMutation({+ variables: { plan: change.targetPlanKey },+ });return data?.switchBillingPlan;}@@ -75,6 +79,7 @@ export const useApplyBillingSubscriptionChange = () => {const getSuccessMessage = (change: BillingSubscriptionChange) => {const isImmediate = isBillingSubscriptionChangeImmediate({change,+ currentPlan,subscriptionStatus,});@@ -82,6 +87,13 @@ export const useApplyBillingSubscriptionChange = () => {case 'SWITCH_PLAN': {const planLabel = getBillingPlanLabel(change.targetPlanKey);+ if (+ isImmediate &&+ planLabel === getBillingPlanLabel(currentPlan.planKey)+ ) {+ return t`Subscription has been moved to the new ${planLabel} plan.`;+ }+return isImmediate? t`Subscription has been switched to ${planLabel} Plan.`: t`Subscription will be switched to ${planLabel} Plan the ${getBeautifiedRenewDate()}.`;diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.tsindex d5f63647967..ac1aa06cecc 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingPlanActions.ts@@ -1,10 +1,16 @@import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { useBillingPortalSession } from '@/settings/billing/hooks/useBillingPortalSession';+import { useBillingWording } from '@/settings/billing/hooks/useBillingWording';import { useNextInterval } from '@/settings/billing/hooks/useNextInterval';import { useNextPlan } from '@/settings/billing/hooks/useNextPlan';+import { usePlanByPlanKey } from '@/settings/billing/hooks/usePlanByPlanKey';import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';+import { type SettingsBillingComparedPlan } from '@/settings/billing/types/SettingsBillingComparedPlan';import { type SettingsBillingPlanAction } from '@/settings/billing/types/SettingsBillingPlanAction';-import { type SettingsBillingPlanInterval } from '@/settings/billing/types/SettingsBillingPlanComparison';+import {+ type SettingsBillingComparedPlanKeys,+ type SettingsBillingPlanInterval,+} from '@/settings/billing/types/SettingsBillingPlanComparison';import { getBillingPlanCell } from '@/settings/billing/utils/getBillingPlanCell';import { isBillingSubscriptionChangeUpgrade } from '@/settings/billing/utils/isBillingSubscriptionChangeUpgrade';import { isSubscriptionPaymentOverdue } from '@/settings/billing/utils/isSubscriptionPaymentOverdue';@@ -25,7 +31,7 @@ import {IconCircleX,} from 'twenty-ui/icon';import {- BillingPlanKey,+ type BillingPlanKey,PermissionFlagType,SubscriptionInterval,SubscriptionStatus,@@ -33,6 +39,7 @@ import {type UseBillingPlanActionsParams = {billingInterval: SettingsBillingPlanInterval;+ comparedPlanKeys: SettingsBillingComparedPlanKeys;currentPlanKey: BillingPlanKey;isApplyingBillingSubscriptionChange: boolean;onBillingSubscriptionChangeRequested: (@@ -42,11 +49,15 @@ type UseBillingPlanActionsParams = {export const useBillingPlanActions = ({billingInterval,+ comparedPlanKeys,currentPlanKey,isApplyingBillingSubscriptionChange,onBillingSubscriptionChangeRequested,}: UseBillingPlanActionsParams) => {const { t } = useLingui();+ const { getBillingPlanLabel } = useBillingWording();+ const { getPlanByPlanKey } = usePlanByPlanKey();+ const currentPlan = getPlanByPlanKey(currentPlanKey);const currentWorkspace = useAtomStateValue(currentWorkspaceState);const subscriptionStatus = useSubscriptionStatus();const { nextPlan } = useNextPlan();@@ -85,12 +96,35 @@ export const useBillingPlanActions = ({variant: 'outline',});- const getChangeTitle = (change: BillingSubscriptionChange) => {+ const getSwitchPlanTitle = ({+ isUpgrade,+ targetPlanKey,+ }: {+ isUpgrade: boolean;+ targetPlanKey: BillingPlanKey;+ }) => {+ const planLabel = getBillingPlanLabel(targetPlanKey);++ if (planLabel === getBillingPlanLabel(currentPlanKey)) {+ return t`Move to the new ${planLabel} plan`;+ }++ return isUpgrade ? t`Upgrade to ${planLabel}` : t`Switch to ${planLabel}`;+ };++ const getChangeTitle = ({+ change,+ isUpgrade,+ }: {+ change: BillingSubscriptionChange;+ isUpgrade: boolean;+ }) => {switch (change.type) {case 'SWITCH_PLAN':- return change.targetPlanKey === BillingPlanKey.ENTERPRISE- ? t`Upgrade to Organization`- : t`Switch to Pro`;+ return getSwitchPlanTitle({+ isUpgrade,+ targetPlanKey: change.targetPlanKey,+ });case 'SWITCH_INTERVAL':return change.targetInterval === SubscriptionInterval.Year? t`Upgrade to annual`@@ -133,7 +167,7 @@ export const useBillingPlanActions = ({Icon: getChangeIcon({ change, isUpgrade }),isLoading: isApplyingBillingSubscriptionChange,onClick: () => onBillingSubscriptionChangeRequested(change),- title: getChangeTitle(change),+ title: getChangeTitle({ change, isUpgrade }),variant: isUpgrade ? 'solid' : 'outline',});@@ -172,6 +206,18 @@ export const useBillingPlanActions = ({};}+ if (+ cell.change.type === 'SWITCH_PLAN' &&+ !currentPlan.upgradePlanKeys.includes(planKey) &&+ !currentPlan.downgradePlanKeys.includes(planKey)+ ) {+ return {+ disabled: true,+ title: t`Unavailable`,+ variant: 'outline',+ };+ }+if (shouldUpdatePayment) {return createBillingPortalAction(t`Update payment`);}@@ -192,16 +238,16 @@ export const useBillingPlanActions = ({change: cell.change,isUpgrade: isBillingSubscriptionChangeUpgrade({change: cell.change,+ currentPlan,upcomingInterval,upcomingPlanKey,}),});};- return {- planActions: {- [BillingPlanKey.PRO]: getPlanAction(BillingPlanKey.PRO),- [BillingPlanKey.ENTERPRISE]: getPlanAction(BillingPlanKey.ENTERPRISE),- },- };+ const comparedPlans: SettingsBillingComparedPlan[] = comparedPlanKeys.map(+ (planKey) => ({ action: getPlanAction(planKey), planKey }),+ );++ return { comparedPlans };};diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingSubscriptionChangeWording.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingSubscriptionChangeWording.tsindex 784e3c63f14..826bf6a6006 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingSubscriptionChangeWording.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingSubscriptionChangeWording.ts@@ -9,6 +9,7 @@ import { type BillingSubscriptionChange } from '@/settings/billing/types/Billingimport { type BillingSubscriptionChangeWording } from '@/settings/billing/types/BillingSubscriptionChangeWording';import { type SettingsBillingPlanInterval } from '@/settings/billing/types/SettingsBillingPlanComparison';import { isBillingSubscriptionChangeImmediate } from '@/settings/billing/utils/isBillingSubscriptionChangeImmediate';+import { isBillingSubscriptionChangeUpgrade } from '@/settings/billing/utils/isBillingSubscriptionChangeUpgrade';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';import { useLingui } from '@lingui/react/macro';@@ -18,7 +19,7 @@ import {isDefined,} from 'twenty-shared/utils';import {- BillingPlanKey,+ type BillingPlanKey,SubscriptionInterval,SubscriptionStatus,} from '~/generated-metadata/graphql';@@ -97,23 +98,56 @@ export const useBillingSubscriptionChangeWording = () => {return 'AFTER_TRIAL';}- return isBillingSubscriptionChangeImmediate({ change, subscriptionStatus })+ return isBillingSubscriptionChangeImmediate({+ change,+ currentPlan,+ subscriptionStatus,+ })? 'NOW': 'SCHEDULED';};- const getSwitchPlanLeadSentence = (targetPlanKey: BillingPlanKey) => {+ const getSwitchPlanLeadSentence = (+ change: Extract<BillingSubscriptionChange, { type: 'SWITCH_PLAN' }>,+ ) => {+ const planLabel = getBillingPlanLabel(change.targetPlanKey);+ const isNewVersionOfCurrentPlan =+ planLabel === getBillingPlanLabel(currentPlanKey);+if (isTrialing) {- const planLabel = getBillingPlanLabel(targetPlanKey);+ return isNewVersionOfCurrentPlan+ ? t`Your plan moves to the new ${planLabel} plan immediately and your trial continues.`+ : t`Your plan switches to ${planLabel} immediately and your trial continues.`;+ }- return t`Your plan switches to ${planLabel} immediately and your trial continues.`;+ if (currentPlan.downgradePlanKeys.includes(change.targetPlanKey)) {+ return t`Your plan switches to ${planLabel} on ${getBeautifiedRenewDate()}, at the end of your current billing period.`;}- if (targetPlanKey === BillingPlanKey.ENTERPRISE) {- return t`Your plan switches to Organization immediately, with a prorated charge for the rest of your current billing period.`;+ if (isNewVersionOfCurrentPlan) {+ return t`Your plan moves to the new ${planLabel} plan immediately, with a prorated charge for the rest of your current billing period.`;}- return t`Your plan switches to Pro on ${getBeautifiedRenewDate()}, at the end of your current billing period.`;+ return t`Your plan switches to ${planLabel} immediately, with a prorated charge for the rest of your current billing period.`;+ };++ const getSwitchPlanTitle = (+ change: Extract<BillingSubscriptionChange, { type: 'SWITCH_PLAN' }>,+ ) => {+ const planLabel = getBillingPlanLabel(change.targetPlanKey);++ if (planLabel === getBillingPlanLabel(currentPlanKey)) {+ return t`Move to the new ${planLabel} plan?`;+ }++ const isUpgrade = isBillingSubscriptionChangeUpgrade({+ change,+ currentPlan,+ upcomingInterval,+ upcomingPlanKey,+ });++ return isUpgrade ? t`Upgrade to ${planLabel}?` : t`Switch to ${planLabel}?`;};const getSwitchIntervalLeadSentence = (@@ -146,12 +180,9 @@ export const useBillingSubscriptionChangeWording = () => {change: Extract<BillingSubscriptionChange, { type: 'SWITCH_PLAN' }>;selectedInterval: SettingsBillingPlanInterval | undefined;}): BillingSubscriptionChangeWording => ({- title:- change.targetPlanKey === BillingPlanKey.ENTERPRISE- ? t`Upgrade to Organization?`- : t`Switch to Pro?`,+ title: getSwitchPlanTitle(change),subtitle: [- getSwitchPlanLeadSentence(change.targetPlanKey),+ getSwitchPlanLeadSentence(change),getChargeSentence({interval: upcomingInterval,planKey: change.targetPlanKey,diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingWording.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingWording.tsindex 8292355ff93..f29cb4411cd 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useBillingWording.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useBillingWording.ts@@ -1,6 +1,7 @@+import { BILLING_PLAN_LABELS } from '@/settings/billing/constants/BillingPlanLabels';import { useFormatPrices } from '@/settings/billing/hooks/useFormatPrices';import {- BillingPlanKey,+ type BillingPlanKey,SubscriptionInterval,} from '~/generated-metadata/graphql';import {@@ -52,7 +53,7 @@ export const useBillingWording = () => {};const getBillingPlanLabel = (planKey: BillingPlanKey) =>- planKey === BillingPlanKey.ENTERPRISE ? t`Organization` : t`Pro`;+ t(BILLING_PLAN_LABELS[planKey]);const getIntervalLabelAsAdjectiveCapitalize = (isMonthlyPlan: boolean) => {return capitalize(getIntervalLabel(isMonthlyPlan, true));diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentBillingFlags.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentBillingFlags.tsindex ab0ac85cc8a..b5c351fbc84 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentBillingFlags.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentBillingFlags.ts@@ -1,7 +1,4 @@-import {- SubscriptionInterval,- BillingPlanKey,-} from '~/generated-metadata/graphql';+import { SubscriptionInterval } from '~/generated-metadata/graphql';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import { getSubscriptionPlanKey } from '@/settings/billing/utils/getSubscriptionPlanKey';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';@@ -19,14 +16,10 @@ export const useCurrentBillingFlags = () => {const isMonthlyPlan = interval === SubscriptionInterval.Month;const isYearlyPlan = interval === SubscriptionInterval.Year;- const isProPlan = planKey === BillingPlanKey.PRO;- const isEnterprisePlan = planKey === BillingPlanKey.ENTERPRISE;return {isMonthlyPlan,isYearlyPlan,- isProPlan,- isEnterprisePlan,planKey,interval,};diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentPlan.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentPlan.tsindex 69432962cdd..6658613d420 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentPlan.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useCurrentPlan.ts@@ -1,4 +1,3 @@-import { BillingPlanKey } from '~/generated-metadata/graphql';import { assertIsDefinedOrThrow, findOrThrow } from 'twenty-shared/utils';import { usePlans } from './usePlans';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';@@ -22,10 +21,5 @@ export const useCurrentPlan = () => {new Error('Current plan not found'),);- const oppositPlan =- currentPlanKey === BillingPlanKey.ENTERPRISE- ? BillingPlanKey.PRO- : BillingPlanKey.ENTERPRISE;-- return { currentPlan, oppositPlan };+ return { currentPlan };};diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/useFormatPrices.ts b/packages/twenty-front/src/modules/settings/billing/hooks/useFormatPrices.tsindex f21bd07bbcf..f63ca834c9f 100644--- a/packages/twenty-front/src/modules/settings/billing/hooks/useFormatPrices.ts+++ b/packages/twenty-front/src/modules/settings/billing/hooks/useFormatPrices.ts@@ -29,28 +29,21 @@ export const useFormatPrices = () => {}};- const formatPrices: SettingsBillingPlanPrices = {- [BillingPlanKey.ENTERPRISE]: {- [SubscriptionInterval.Year]: getFormattedPrice(- BillingPlanKey.ENTERPRISE,- SubscriptionInterval.Year,- ),- [SubscriptionInterval.Month]: getFormattedPrice(- BillingPlanKey.ENTERPRISE,- SubscriptionInterval.Month,- ),- },- [BillingPlanKey.PRO]: {- [SubscriptionInterval.Year]: getFormattedPrice(- BillingPlanKey.PRO,- SubscriptionInterval.Year,- ),- [SubscriptionInterval.Month]: getFormattedPrice(- BillingPlanKey.PRO,- SubscriptionInterval.Month,- ),- },- };+ const formatPrices = Object.fromEntries(+ Object.values(BillingPlanKey).map((planKey) => [+ planKey,+ {+ [SubscriptionInterval.Year]: getFormattedPrice(+ planKey,+ SubscriptionInterval.Year,+ ),+ [SubscriptionInterval.Month]: getFormattedPrice(+ planKey,+ SubscriptionInterval.Month,+ ),+ },+ ]),+ ) as SettingsBillingPlanPrices;return {formatPrices,diff --git a/packages/twenty-front/src/modules/settings/billing/types/BillingPlanSwitches.ts b/packages/twenty-front/src/modules/settings/billing/types/BillingPlanSwitches.tsnew file mode 100644index 00000000000..82cd5e5a957--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/types/BillingPlanSwitches.ts@@ -0,0 +1,6 @@+import { type BillingPlan } from '~/generated-metadata/graphql';++export type BillingPlanSwitches = Pick<+ BillingPlan,+ 'downgradePlanKeys' | 'upgradePlanKeys'+>;diff --git a/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.ts b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.tsnew file mode 100644index 00000000000..f9ebb481dc2--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingComparedPlan.ts@@ -0,0 +1,7 @@+import { type SettingsBillingPlanAction } from '@/settings/billing/types/SettingsBillingPlanAction';+import { type BillingPlanKey } from '~/generated-metadata/graphql';++export type SettingsBillingComparedPlan = {+ action: SettingsBillingPlanAction;+ planKey: BillingPlanKey;+};diff --git a/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingPlanComparison.ts b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingPlanComparison.tsindex b81058bfadf..fa2dd455d85 100644--- a/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingPlanComparison.ts+++ b/packages/twenty-front/src/modules/settings/billing/types/SettingsBillingPlanComparison.ts@@ -8,6 +8,8 @@ export type SettingsBillingPlanInterval =| SubscriptionInterval.Month| SubscriptionInterval.Year;+export type SettingsBillingComparedPlanKeys = [BillingPlanKey, BillingPlanKey];+export type SettingsBillingPlanPrices = Record<BillingPlanKey,Record<SettingsBillingPlanInterval, number>diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getBillingPlanCell.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getBillingPlanCell.test.tsindex 8d7934da7a8..e7f2785f658 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getBillingPlanCell.test.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getBillingPlanCell.test.ts@@ -6,7 +6,7 @@ import {SubscriptionInterval,} from '~/generated-metadata/graphql';-const { PRO, ENTERPRISE } = BillingPlanKey;+const { PRO, ENTERPRISE, PRO_V2, ORGANIZATION_V2 } = BillingPlanKey;const { Month, Year } = SubscriptionInterval;const current = { kind: 'current' } as const;@@ -27,7 +27,11 @@ const cancelIntervalSwitch = {change: { type: 'CANCEL_INTERVAL_SWITCH' },} as const;-const getGrid = (subscription: {+const getGrid = ({+ planKeys = [PRO, ENTERPRISE],+ ...subscription+}: {+ planKeys?: BillingPlanKey[];currentPlanKey: BillingPlanKey;currentInterval: SettingsBillingPlanInterval;upcomingPlanKey: BillingPlanKey;@@ -37,7 +41,7 @@ const getGrid = (subscription: {Record<BillingPlanKey, Record<SettingsBillingPlanInterval, unknown>>> = {};- for (const planKey of [PRO, ENTERPRISE]) {+ for (const planKey of planKeys) {grid[planKey] = {[Month]: getBillingPlanCell({...subscription,@@ -86,7 +90,7 @@ describe('getBillingPlanCell', () => {});});- it('cancels a scheduled interval switch from the current interval column', () => {+ it('keeps offering plan switches on other plans while an interval switch is scheduled', () => {expect(getGrid({currentPlanKey: PRO,@@ -98,7 +102,7 @@ describe('getBillingPlanCell', () => {[PRO]: { [Month]: scheduled, [Year]: current },[ENTERPRISE]: {[Month]: switchPlan(ENTERPRISE),- [Year]: cancelIntervalSwitch,+ [Year]: switchPlan(ENTERPRISE),},});});@@ -116,4 +120,22 @@ describe('getBillingPlanCell', () => {[ENTERPRISE]: { [Month]: cancelPlanSwitch, [Year]: current },});});++ it('offers plan switches outside the upcoming plan column when the current plan is not a column', () => {+ expect(+ getGrid({+ planKeys: [PRO_V2, ORGANIZATION_V2],+ currentPlanKey: ENTERPRISE,+ currentInterval: Month,+ upcomingPlanKey: PRO_V2,+ upcomingInterval: Month,+ }),+ ).toEqual({+ [PRO_V2]: { [Month]: scheduled, [Year]: switchInterval(Year) },+ [ORGANIZATION_V2]: {+ [Month]: switchPlan(ORGANIZATION_V2),+ [Year]: switchPlan(ORGANIZATION_V2),+ },+ });+ });});diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getComparedBillingPlanKeysOrThrow.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getComparedBillingPlanKeysOrThrow.test.tsnew file mode 100644index 00000000000..596697d7326--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/getComparedBillingPlanKeysOrThrow.test.ts@@ -0,0 +1,39 @@+import { getComparedBillingPlanKeysOrThrow } from '@/settings/billing/utils/getComparedBillingPlanKeysOrThrow';+import { BillingPlanKey } from '~/generated-metadata/graphql';++const plan = (planKey: BillingPlanKey, isSellable: boolean) => ({+ isSellable,+ planKey,+});++describe('getComparedBillingPlanKeysOrThrow', () => {+ it('returns the two plans on sale in list order', () => {+ expect(+ getComparedBillingPlanKeysOrThrow([+ plan(BillingPlanKey.PRO, false),+ plan(BillingPlanKey.ENTERPRISE, false),+ plan(BillingPlanKey.PRO_V2, true),+ plan(BillingPlanKey.ORGANIZATION_V2, true),+ ]),+ ).toEqual([BillingPlanKey.PRO_V2, BillingPlanKey.ORGANIZATION_V2]);+ });++ it('throws when fewer than two plans are on sale', () => {+ expect(() =>+ getComparedBillingPlanKeysOrThrow([+ plan(BillingPlanKey.PRO, true),+ plan(BillingPlanKey.ENTERPRISE, false),+ ]),+ ).toThrow();+ });++ it('throws when more than two plans are on sale', () => {+ expect(() =>+ getComparedBillingPlanKeysOrThrow([+ plan(BillingPlanKey.PRO, true),+ plan(BillingPlanKey.ENTERPRISE, true),+ plan(BillingPlanKey.PRO_V2, true),+ ]),+ ).toThrow();+ });+});diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeImmediate.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeImmediate.test.tsindex 89c6d70919b..1f1bcdda458 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeImmediate.test.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeImmediate.test.ts@@ -6,6 +6,15 @@ import {} from '~/generated-metadata/graphql';describe('isBillingSubscriptionChangeImmediate', () => {+ const proPlan = {+ upgradePlanKeys: [BillingPlanKey.ENTERPRISE],+ downgradePlanKeys: [],+ };+ const enterprisePlan = {+ upgradePlanKeys: [],+ downgradePlanKeys: [BillingPlanKey.PRO],+ };+it('applies upgrades immediately and downgrades at period end', () => {expect(isBillingSubscriptionChangeImmediate({@@ -13,12 +22,14 @@ describe('isBillingSubscriptionChangeImmediate', () => {type: 'SWITCH_PLAN',targetPlanKey: BillingPlanKey.ENTERPRISE,},+ currentPlan: proPlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(true);expect(isBillingSubscriptionChangeImmediate({change: { type: 'SWITCH_PLAN', targetPlanKey: BillingPlanKey.PRO },+ currentPlan: enterprisePlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(false);@@ -28,6 +39,7 @@ describe('isBillingSubscriptionChangeImmediate', () => {type: 'SWITCH_INTERVAL',targetInterval: SubscriptionInterval.Year,},+ currentPlan: proPlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(true);@@ -37,6 +49,32 @@ describe('isBillingSubscriptionChangeImmediate', () => {type: 'SWITCH_INTERVAL',targetInterval: SubscriptionInterval.Month,},+ currentPlan: proPlan,+ subscriptionStatus: SubscriptionStatus.Active,+ }),+ ).toBe(false);+ });++ it('defers a plan switch only when the target is a downgrade of the current plan', () => {+ const legacyEnterprisePlan = {+ upgradePlanKeys: [BillingPlanKey.ORGANIZATION_V2],+ downgradePlanKeys: [BillingPlanKey.PRO_V2],+ };++ expect(+ isBillingSubscriptionChangeImmediate({+ change: {+ type: 'SWITCH_PLAN',+ targetPlanKey: BillingPlanKey.ORGANIZATION_V2,+ },+ currentPlan: legacyEnterprisePlan,+ subscriptionStatus: SubscriptionStatus.Active,+ }),+ ).toBe(true);+ expect(+ isBillingSubscriptionChangeImmediate({+ change: { type: 'SWITCH_PLAN', targetPlanKey: BillingPlanKey.PRO_V2 },+ currentPlan: legacyEnterprisePlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(false);@@ -46,6 +84,7 @@ describe('isBillingSubscriptionChangeImmediate', () => {expect(isBillingSubscriptionChangeImmediate({change: { type: 'SWITCH_PLAN', targetPlanKey: BillingPlanKey.PRO },+ currentPlan: enterprisePlan,subscriptionStatus: SubscriptionStatus.Trialing,}),).toBe(true);@@ -55,6 +94,7 @@ describe('isBillingSubscriptionChangeImmediate', () => {type: 'SWITCH_INTERVAL',targetInterval: SubscriptionInterval.Month,},+ currentPlan: enterprisePlan,subscriptionStatus: SubscriptionStatus.Trialing,}),).toBe(true);@@ -64,12 +104,14 @@ describe('isBillingSubscriptionChangeImmediate', () => {expect(isBillingSubscriptionChangeImmediate({change: { type: 'CANCEL_PLAN_SWITCH' },+ currentPlan: enterprisePlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(true);expect(isBillingSubscriptionChangeImmediate({change: { type: 'CANCEL_INTERVAL_SWITCH' },+ currentPlan: enterprisePlan,subscriptionStatus: SubscriptionStatus.Active,}),).toBe(true);diff --git a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeUpgrade.test.ts b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeUpgrade.test.tsindex f10e2f4889d..82d0725ec29 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeUpgrade.test.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/__tests__/isBillingSubscriptionChangeUpgrade.test.ts@@ -5,6 +5,14 @@ import {} from '~/generated-metadata/graphql';describe('isBillingSubscriptionChangeUpgrade', () => {+ const proPlan = {+ upgradePlanKeys: [BillingPlanKey.ENTERPRISE],+ downgradePlanKeys: [],+ };+ const enterprisePlan = {+ upgradePlanKeys: [],+ downgradePlanKeys: [BillingPlanKey.PRO],+ };const proMonthlyUpcoming = {upcomingPlanKey: BillingPlanKey.PRO,upcomingInterval: SubscriptionInterval.Month,@@ -14,13 +22,14 @@ describe('isBillingSubscriptionChangeUpgrade', () => {upcomingInterval: SubscriptionInterval.Year,};- it('treats switching to Organization or to annual as upgrades', () => {+ it('treats switching to an upgrade plan or to annual as upgrades', () => {expect(isBillingSubscriptionChangeUpgrade({change: {type: 'SWITCH_PLAN',targetPlanKey: BillingPlanKey.ENTERPRISE,},+ currentPlan: proPlan,...proMonthlyUpcoming,}),).toBe(true);@@ -30,12 +39,14 @@ describe('isBillingSubscriptionChangeUpgrade', () => {type: 'SWITCH_INTERVAL',targetInterval: SubscriptionInterval.Year,},+ currentPlan: proPlan,...proMonthlyUpcoming,}),).toBe(true);expect(isBillingSubscriptionChangeUpgrade({change: { type: 'SWITCH_PLAN', targetPlanKey: BillingPlanKey.PRO },+ currentPlan: enterprisePlan,...enterpriseYearlyUpcoming,}),).toBe(false);@@ -45,33 +56,63 @@ describe('isBillingSubscriptionChangeUpgrade', () => {type: 'SWITCH_INTERVAL',targetInterval: SubscriptionInterval.Month,},+ currentPlan: enterprisePlan,...enterpriseYearlyUpcoming,}),).toBe(false);});+ it('reads plan upgrades from the current plan switches', () => {+ const legacyProPlan = {+ upgradePlanKeys: [BillingPlanKey.PRO_V2, BillingPlanKey.ORGANIZATION_V2],+ downgradePlanKeys: [],+ };++ expect(+ isBillingSubscriptionChangeUpgrade({+ change: { type: 'SWITCH_PLAN', targetPlanKey: BillingPlanKey.PRO_V2 },+ currentPlan: legacyProPlan,+ ...proMonthlyUpcoming,+ }),+ ).toBe(true);+ expect(+ isBillingSubscriptionChangeUpgrade({+ change: {+ type: 'SWITCH_PLAN',+ targetPlanKey: BillingPlanKey.ENTERPRISE,+ },+ currentPlan: legacyProPlan,+ ...proMonthlyUpcoming,+ }),+ ).toBe(false);+ });+it('treats cancelling a scheduled downgrade as an upgrade', () => {expect(isBillingSubscriptionChangeUpgrade({change: { type: 'CANCEL_PLAN_SWITCH' },+ currentPlan: enterprisePlan,...proMonthlyUpcoming,}),).toBe(true);expect(isBillingSubscriptionChangeUpgrade({change: { type: 'CANCEL_INTERVAL_SWITCH' },+ currentPlan: enterprisePlan,...proMonthlyUpcoming,}),).toBe(true);expect(isBillingSubscriptionChangeUpgrade({change: { type: 'CANCEL_PLAN_SWITCH' },+ currentPlan: proPlan,...enterpriseYearlyUpcoming,}),).toBe(false);expect(isBillingSubscriptionChangeUpgrade({change: { type: 'CANCEL_INTERVAL_SWITCH' },+ currentPlan: proPlan,...enterpriseYearlyUpcoming,}),).toBe(false);diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getBillingPlanCell.ts b/packages/twenty-front/src/modules/settings/billing/utils/getBillingPlanCell.tsindex 1760e775bf3..eb8b154e789 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/getBillingPlanCell.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/getBillingPlanCell.ts@@ -27,7 +27,6 @@ export const getBillingPlanCell = ({return { kind: 'scheduled' };}- const isPlanSwitchScheduled = upcomingPlanKey !== currentPlanKey;const isIntervalSwitchScheduled = upcomingInterval !== currentInterval;if (planKey === upcomingPlanKey) {@@ -39,23 +38,10 @@ export const getBillingPlanCell = ({};}- if (interval === upcomingInterval) {- return {- kind: 'change',- change: isPlanSwitchScheduled- ? { type: 'CANCEL_PLAN_SWITCH' }- : { type: 'SWITCH_PLAN', targetPlanKey: planKey },- };- }-- if (isPlanSwitchScheduled) {+ if (planKey === currentPlanKey) {return { kind: 'change', change: { type: 'CANCEL_PLAN_SWITCH' } };}- if (isIntervalSwitchScheduled) {- return { kind: 'change', change: { type: 'CANCEL_INTERVAL_SWITCH' } };- }-return {kind: 'change',change: { type: 'SWITCH_PLAN', targetPlanKey: planKey },diff --git a/packages/twenty-front/src/modules/settings/billing/utils/getComparedBillingPlanKeysOrThrow.ts b/packages/twenty-front/src/modules/settings/billing/utils/getComparedBillingPlanKeysOrThrow.tsnew file mode 100644index 00000000000..23f073c6525--- /dev/null+++ b/packages/twenty-front/src/modules/settings/billing/utils/getComparedBillingPlanKeysOrThrow.ts@@ -0,0 +1,21 @@+import { type SettingsBillingComparedPlanKeys } from '@/settings/billing/types/SettingsBillingPlanComparison';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';+import { type BillingPlan } from '~/generated-metadata/graphql';++export const getComparedBillingPlanKeysOrThrow = (+ plans: Pick<BillingPlan, 'isSellable' | 'planKey'>[],+): SettingsBillingComparedPlanKeys => {+ const [firstPlanKey, secondPlanKey, ...otherPlanKeys] = plans+ .filter((plan) => plan.isSellable)+ .map((plan) => plan.planKey);++ if (+ !isDefined(firstPlanKey) ||+ !isDefined(secondPlanKey) ||+ isNonEmptyArray(otherPlanKeys)+ ) {+ throw new Error('The plan comparison expects exactly two plans on sale');+ }++ return [firstPlanKey, secondPlanKey];+};diff --git a/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeImmediate.ts b/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeImmediate.tsindex 36353c5e099..640ff66394a 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeImmediate.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeImmediate.ts@@ -1,16 +1,18 @@+import { type BillingPlanSwitches } from '@/settings/billing/types/BillingPlanSwitches';import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';import { assertUnreachable } from 'twenty-shared/utils';import {- BillingPlanKey,SubscriptionInterval,SubscriptionStatus,} from '~/generated-metadata/graphql';export const isBillingSubscriptionChangeImmediate = ({change,+ currentPlan,subscriptionStatus,}: {change: BillingSubscriptionChange;+ currentPlan: BillingPlanSwitches;subscriptionStatus: SubscriptionStatus | undefined;}) => {if (subscriptionStatus === SubscriptionStatus.Trialing) {@@ -19,7 +21,7 @@ export const isBillingSubscriptionChangeImmediate = ({switch (change.type) {case 'SWITCH_PLAN':- return change.targetPlanKey === BillingPlanKey.ENTERPRISE;+ return !currentPlan.downgradePlanKeys.includes(change.targetPlanKey);case 'SWITCH_INTERVAL':return change.targetInterval === SubscriptionInterval.Year;case 'CANCEL_PLAN_SWITCH':diff --git a/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeUpgrade.ts b/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeUpgrade.tsindex 4709fe69915..1387456262a 100644--- a/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeUpgrade.ts+++ b/packages/twenty-front/src/modules/settings/billing/utils/isBillingSubscriptionChangeUpgrade.ts@@ -1,27 +1,30 @@+import { type BillingPlanSwitches } from '@/settings/billing/types/BillingPlanSwitches';import { type BillingSubscriptionChange } from '@/settings/billing/types/BillingSubscriptionChange';import { assertUnreachable } from 'twenty-shared/utils';import { type SettingsBillingPlanInterval } from '@/settings/billing/types/SettingsBillingPlanComparison';import {- BillingPlanKey,+ type BillingPlanKey,SubscriptionInterval,} from '~/generated-metadata/graphql';export const isBillingSubscriptionChangeUpgrade = ({change,+ currentPlan,upcomingInterval,upcomingPlanKey,}: {change: BillingSubscriptionChange;+ currentPlan: BillingPlanSwitches;upcomingInterval: SettingsBillingPlanInterval;upcomingPlanKey: BillingPlanKey;}) => {switch (change.type) {case 'SWITCH_PLAN':- return change.targetPlanKey === BillingPlanKey.ENTERPRISE;+ return currentPlan.upgradePlanKeys.includes(change.targetPlanKey);case 'SWITCH_INTERVAL':return change.targetInterval === SubscriptionInterval.Year;case 'CANCEL_PLAN_SWITCH':- return upcomingPlanKey === BillingPlanKey.PRO;+ return currentPlan.downgradePlanKeys.includes(upcomingPlanKey);case 'CANCEL_INTERVAL_SWITCH':return upcomingInterval === SubscriptionInterval.Month;default:diff --git a/packages/twenty-front/src/testing/mock-data/billing-plans.ts b/packages/twenty-front/src/testing/mock-data/billing-plans.tsindex 15a23ad48c6..fa30bfaf8db 100644--- a/packages/twenty-front/src/testing/mock-data/billing-plans.ts+++ b/packages/twenty-front/src/testing/mock-data/billing-plans.ts@@ -5,6 +5,9 @@ export const mockBillingPlans = {{__typename: 'BillingPlan',planKey: 'PRO',+ isSellable: true,+ upgradePlanKeys: ['ENTERPRISE'],+ downgradePlanKeys: [],baseProducts: [{__typename: 'BillingLicensedProduct',@@ -302,6 +305,9 @@ export const mockBillingPlans = {{__typename: 'BillingPlan',planKey: 'ENTERPRISE',+ isSellable: true,+ upgradePlanKeys: [],+ downgradePlanKeys: ['PRO'],baseProducts: [{__typename: 'BillingLicensedProduct',@@ -596,5 +602,25 @@ export const mockBillingPlans = {},],},+ {+ __typename: 'BillingPlan',+ planKey: 'PRO_V2',+ isSellable: false,+ upgradePlanKeys: [],+ downgradePlanKeys: [],+ baseProducts: [],+ resourceCreditProducts: [],+ meteredProducts: [],+ },+ {+ __typename: 'BillingPlan',+ planKey: 'ORGANIZATION_V2',+ isSellable: false,+ upgradePlanKeys: [],+ downgradePlanKeys: [],+ baseProducts: [],+ resourceCreditProducts: [],+ meteredProducts: [],+ },],} as ListPlansQuery;diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.tsindex 246394b9111..1f4abe4aa3a 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts@@ -10,6 +10,7 @@ import { CustomException } from 'src/utils/custom-exception';export enum BillingExceptionCode {BILLING_CUSTOMER_NOT_FOUND = 'BILLING_CUSTOMER_NOT_FOUND',BILLING_PLAN_NOT_FOUND = 'BILLING_PLAN_NOT_FOUND',+ BILLING_PLAN_NOT_ALLOWED = 'BILLING_PLAN_NOT_ALLOWED',BILLING_PRODUCT_NOT_FOUND = 'BILLING_PRODUCT_NOT_FOUND',BILLING_PRICE_NOT_FOUND = 'BILLING_PRICE_NOT_FOUND',BILLING_SUBSCRIPTION_NOT_FOUND = 'BILLING_SUBSCRIPTION_NOT_FOUND',@@ -45,6 +46,8 @@ const getBillingExceptionUserFriendlyMessage = (code: BillingExceptionCode) => {return msg`Billing customer not found.`;case BillingExceptionCode.BILLING_PLAN_NOT_FOUND:return msg`Billing plan not found.`;+ case BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED:+ return msg`This plan is not available.`;case BillingExceptionCode.BILLING_PRODUCT_NOT_FOUND:return msg`Billing product not found.`;case BillingExceptionCode.BILLING_PRICE_NOT_FOUND:diff --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 0270da4eef1..53432780333 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@@ -21,8 +21,8 @@ import { BillingSessionDTO } from 'src/engine/core-modules/billing/dtos/billing-import { BillingUpdateDTO } from 'src/engine/core-modules/billing/dtos/billing-update.dto';import { BillingCheckoutSessionInput } from 'src/engine/core-modules/billing/dtos/inputs/billing-checkout-session.input';import { BillingSessionInput } from 'src/engine/core-modules/billing/dtos/inputs/billing-session.input';+import { BillingSwitchPlanInput } from 'src/engine/core-modules/billing/dtos/inputs/billing-switch-plan.input';import { BillingUpdateSubscriptionItemPriceInput } from 'src/engine/core-modules/billing/dtos/inputs/billing-update-subscription-item-price.input';-import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';import { BillingPlanService } from 'src/engine/core-modules/billing/services/billing-plan.service';import { BillingPortalWorkspaceService } from 'src/engine/core-modules/billing/services/billing-portal.workspace-service';import { BillingSubscriptionUpdateService } from 'src/engine/core-modules/billing/services/billing-subscription-update.service';@@ -30,6 +30,7 @@ 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';@@ -137,7 +138,7 @@ export class BillingResolver {user,workspace,successUrlPath,- plan: plan ?? BillingPlanKey.PRO,+ plan: getCheckoutPlanKeyOrThrow({ planKey: plan }),requirePaymentMethod,};@@ -202,18 +203,18 @@ export class BillingResolver {workspaceActivationStatus: workspace.activationStatus,});- const resolvedPlan = plan ?? BillingPlanKey.PRO;+ const checkoutPlanKey = getCheckoutPlanKeyOrThrow({ planKey: plan });const billingPricesPerPlan =await this.billingPlanService.getPricesPerPlanByInterval({- planKey: resolvedPlan,+ planKey: checkoutPlanKey,interval: recurringInterval,});return this.billingPortalWorkspaceService.createSubscriptionPaymentIntent({user,workspace,- plan: resolvedPlan,+ plan: checkoutPlanKey,billingPricesPerPlan,idempotencyKey,});@@ -289,8 +290,11 @@ export class BillingResolver {}),SettingsPermissionGuard(PermissionFlagType.BILLING),)- async switchBillingPlan(@AuthWorkspace() workspace: WorkspaceEntity) {- await this.billingSubscriptionUpdateService.changePlan(workspace.id);+ async switchBillingPlan(+ @AuthWorkspace() workspace: WorkspaceEntity,+ @Args() { plan }: BillingSwitchPlanInput,+ ) {+ await this.billingSubscriptionUpdateService.changePlan(workspace.id, plan);return {billingSubscriptions: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.tsnew file mode 100644index 00000000000..12de010fe26--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/constants/billing-plan-switches.constant.ts@@ -0,0 +1,23 @@+/* @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.tsnew file mode 100644index 00000000000..3ffa92dd10e--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/constants/billing-sellable-plan-keys.constant.ts@@ -0,0 +1,8 @@+/* @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/dtos/billing-plan.dto.ts b/packages/twenty-server/src/engine/core-modules/billing/dtos/billing-plan.dto.tsindex 9fb4ede0ab7..d9a33f45ee2 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@@ -13,6 +13,15 @@ export class BillingPlanDTO {@Field(() => BillingPlanKey)planKey: BillingPlanKey;+ @Field(() => Boolean)+ isSellable: boolean;++ @Field(() => [BillingPlanKey])+ upgradePlanKeys: BillingPlanKey[];++ @Field(() => [BillingPlanKey])+ downgradePlanKeys: BillingPlanKey[];+@Field(() => [BillingLicensedProduct])baseProducts: BillingLicensedProduct[];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 df05e121fb0..02d3fd78323 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,6 +10,7 @@ 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';@@ -20,7 +21,7 @@ export class BillingCheckoutSessionInput {@IsNotEmpty()recurringInterval: SubscriptionInterval;- @Field(() => BillingPlanKey, { defaultValue: BillingPlanKey.PRO })+ @Field(() => BillingPlanKey, { defaultValue: BILLING_SELLABLE_PLAN_KEYS[0] })@IsEnum(BillingPlanKey)@IsOptional()plan?: BillingPlanKey;diff --git a/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-switch-plan.input.ts b/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-switch-plan.input.tsnew file mode 100644index 00000000000..5e0c1b11ea1--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/dtos/inputs/billing-switch-plan.input.ts@@ -0,0 +1,15 @@+/* @license Enterprise */++import { ArgsType, Field } from '@nestjs/graphql';++import { IsEnum, IsOptional } from 'class-validator';++import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';++@ArgsType()+export class BillingSwitchPlanInput {+ @Field(() => BillingPlanKey, { nullable: true })+ @IsEnum(BillingPlanKey)+ @IsOptional()+ plan?: BillingPlanKey;+}diff --git a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-plan-key.enum.ts b/packages/twenty-server/src/engine/core-modules/billing/enums/billing-plan-key.enum.tsindex bfcaf02c84b..5a9a5d90550 100644--- a/packages/twenty-server/src/engine/core-modules/billing/enums/billing-plan-key.enum.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/enums/billing-plan-key.enum.ts@@ -5,6 +5,8 @@ import { registerEnumType } from '@nestjs/graphql';export enum BillingPlanKey {PRO = 'PRO',ENTERPRISE = 'ENTERPRISE',+ PRO_V2 = 'PRO_V2',+ ORGANIZATION_V2 = 'ORGANIZATION_V2',}registerEnumType(BillingPlanKey, {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 14f0a15ef94..19f5035864a 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,6 +9,8 @@ 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';@@ -58,6 +60,9 @@ export class BillingPlanService {return {planKey,+ isSellable: BILLING_SELLABLE_PLAN_KEYS.includes(planKey),+ upgradePlanKeys: BILLING_PLAN_SWITCHES[planKey].upgradePlanKeys,+ downgradePlanKeys: BILLING_PLAN_SWITCHES[planKey].downgradePlanKeys,meteredProducts,baseProducts,resourceCreditProducts,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 cc6b8a0a6a1..47ed556fa3a 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,6 +18,7 @@ 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';@@ -42,6 +43,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 { 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';import { buildSchedulePhasesUpdate } from 'src/engine/core-modules/billing/utils/build-schedule-phases-update.util';@@ -193,22 +195,23 @@ export class BillingSubscriptionUpdateService {});}- async changePlan(workspaceId: string) {+ async changePlan(workspaceId: string, targetPlanKey?: BillingPlanKey) {const billingSubscription =await this.billingSubscriptionService.getCurrentBillingSubscriptionOrThrow({ workspaceId },);- const currentPlan =+ const currentPlanKey =getBaseProductSubscriptionItemOrThrow(billingSubscription).billingProduct?.metadata.planKey;+ assertIsDefinedOrThrow(currentPlanKey);++ const planSwitch = getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey });+await this.updateSubscription(workspaceId, billingSubscription.id, {type: SubscriptionUpdateType.PLAN,- newPlan:- currentPlan === BillingPlanKey.ENTERPRISE- ? BillingPlanKey.PRO- : BillingPlanKey.ENTERPRISE,+ newPlan: planSwitch.targetPlanKey,});}@@ -609,8 +612,10 @@ export class BillingSubscriptionUpdateService {?.metadata.planKey;const isDowngrade =- currentPlan !== update.newPlan &&- update.newPlan === BillingPlanKey.PRO;+ isDefined(currentPlan) &&+ BILLING_PLAN_SWITCHES[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 20cf2acf94c..322b725782e 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,8 @@ import { isDefined } from 'twenty-shared/utils';import type Stripe from 'stripe';-import { BillingPlanKey } from 'src/engine/core-modules/billing/enums/billing-plan-key.enum';+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';import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';@@ -38,7 +39,7 @@ export class StripeCheckoutService {successUrl,cancelUrl,stripeCustomerId,- plan = BillingPlanKey.PRO,+ plan = BILLING_SELLABLE_PLAN_KEYS[0],requirePaymentMethod = true,withTrialPeriod,}: {@@ -88,7 +89,7 @@ export class StripeCheckoutService {workspace,stripeSubscriptionLineItems,stripeCustomerId,- plan = BillingPlanKey.PRO,+ plan = BILLING_SELLABLE_PLAN_KEYS[0],requirePaymentMethod = false,withTrialPeriod,idempotencyKey,@@ -138,7 +139,7 @@ export class StripeCheckoutService {workspace,stripeSubscriptionLineItems,stripeCustomerId,- plan = BillingPlanKey.PRO,+ plan = BILLING_SELLABLE_PLAN_KEYS[0],withTrialPeriod,idempotencyKey,}: {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 ea47440ede1..7838635a8f6 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@@ -5,6 +5,9 @@ import { type BillingPlanKey } from 'src/engine/core-modules/billing/enums/billiexport type BillingGetPlanResult = {planKey: BillingPlanKey;+ isSellable: boolean;+ upgradePlanKeys: BillingPlanKey[];+ downgradePlanKeys: BillingPlanKey[];meteredProducts: BillingProductEntity[];baseProducts: BillingProductEntity[];resourceCreditProducts: 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.tsnew file mode 100644index 00000000000..17b1a330e40--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/types/billing-plan-switches.type.ts@@ -0,0 +1,8 @@+/* @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/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.tsnew file mode 100644index 00000000000..2f1798c5ea3--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-checkout-plan-key-or-throw.util.spec.ts@@ -0,0 +1,17 @@+/* @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.tsnew file mode 100644index 00000000000..33e18b16136--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/get-plan-switch-or-throw.util.spec.ts@@ -0,0 +1,29 @@+/* @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 { getPlanSwitchOrThrow } from 'src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util';++describe('getPlanSwitchOrThrow', () => {+ it.each([+ [BillingPlanKey.PRO, BillingPlanKey.ENTERPRISE],+ [BillingPlanKey.ENTERPRISE, BillingPlanKey.PRO],+ ])('allows %s to %s', (currentPlanKey, targetPlanKey) => {+ expect(getPlanSwitchOrThrow({ currentPlanKey, targetPlanKey })).toEqual({+ targetPlanKey,+ });+ });++ it('refuses a plan outside the current plan switches', () => {+ expect(() =>+ getPlanSwitchOrThrow({+ currentPlanKey: BillingPlanKey.PRO,+ targetPlanKey: BillingPlanKey.PRO_V2,+ }),+ ).toThrow(+ expect.objectContaining({+ code: BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ }),+ );+ });+});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 d083aeef5c1..109877ab404 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@@ -17,6 +17,9 @@ export const formatBillingDatabaseProductToGraphqlDTO = (): BillingPlanDTO => {return {planKey: plan.planKey,+ isSellable: plan.isSellable,+ upgradePlanKeys: plan.upgradePlanKeys,+ downgradePlanKeys: plan.downgradePlanKeys,baseProducts: plan.baseProducts.map((product) => {return {...product,diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.tsindex fef0781cf19..c2f8d3cf30a 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts@@ -24,6 +24,7 @@ export const getBillingExceptionStatusCode = (case BillingExceptionCode.BILLING_CREDIT_GRANT_VALIDITY_INVALID:case BillingExceptionCode.BILLING_CREDIT_GRANT_TYPE_NOT_GRANTABLE:case BillingExceptionCode.BILLING_SUBSCRIPTION_ALREADY_EXISTS:+ case BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED:return 400;case BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE:case BillingExceptionCode.BILLING_UPGRADE_INVOICE_PAYMENT_FAILED: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.tsnew file mode 100644index 00000000000..8c0d4e9d171--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-checkout-plan-key-or-throw.util.ts@@ -0,0 +1,25 @@+/* @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.tsnew file mode 100644index 00000000000..4fb6c830da5--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-switch-or-throw.util.ts@@ -0,0 +1,40 @@+/* @license Enterprise */++import { isDefined } from 'twenty-shared/utils';++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';++export const getPlanSwitchOrThrow = ({+ currentPlanKey,+ targetPlanKey,+}: {+ currentPlanKey: BillingPlanKey;+ targetPlanKey?: BillingPlanKey;+}): { targetPlanKey: BillingPlanKey } => {+ const { upgradePlanKeys, downgradePlanKeys } =+ BILLING_PLAN_SWITCHES[currentPlanKey];+ const allowedTargetPlanKeys = [...upgradePlanKeys, ...downgradePlanKeys];++ if (!isDefined(targetPlanKey) && allowedTargetPlanKeys.length !== 1) {+ throw new BillingException(+ `A target plan is required to switch from plan ${currentPlanKey}, which allows ${allowedTargetPlanKeys.length} plan switches`,+ BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ );+ }++ const switchTargetPlanKey = targetPlanKey ?? allowedTargetPlanKeys[0];++ if (!allowedTargetPlanKeys.includes(switchTargetPlanKey)) {+ throw new BillingException(+ `Switching from plan ${currentPlanKey} to plan ${switchTargetPlanKey} is not allowed`,+ BillingExceptionCode.BILLING_PLAN_NOT_ALLOWED,+ );+ }++ return { targetPlanKey: switchTargetPlanKey };+};