From 93c0263aeb2e29102faf885965c38fc54ce602ed Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Tue, 7 Feb 2023 14:10:32 +0000 Subject: [PATCH] [server] Ignore old FREE/FREE_50 when evaluating BillingMode --- .../server/ee/src/billing/billing-mode.spec.db.ts | 12 ++++++++++++ components/server/ee/src/billing/billing-mode.ts | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/components/server/ee/src/billing/billing-mode.spec.db.ts b/components/server/ee/src/billing/billing-mode.spec.db.ts index e770620a09d3dc..be9252029afb90 100644 --- a/components/server/ee/src/billing/billing-mode.spec.db.ts +++ b/components/server/ee/src/billing/billing-mode.spec.db.ts @@ -281,6 +281,18 @@ class BillingModeSpec { }, }, // user: usage-based + { + name: "user: stripe free, chargebee FREE (old)", + subject: user(), + config: { + enablePayment: true, + usageBasedPricingEnabled: true, + subscriptions: [subscription(Plans.FREE)], + }, + expectation: { + mode: "usage-based", + }, + }, { name: "user: stripe free, chargebee paid personal (inactive) + team seat (inactive)", subject: user(), diff --git a/components/server/ee/src/billing/billing-mode.ts b/components/server/ee/src/billing/billing-mode.ts index 459c3135119e17..f92c0e510fa098 100644 --- a/components/server/ee/src/billing/billing-mode.ts +++ b/components/server/ee/src/billing/billing-mode.ts @@ -127,7 +127,11 @@ export class BillingModesImpl implements BillingModes { const cbSubscriptions = await this.subscriptionSvc.getActivePaidSubscription(user.id, now); const cbTeamSubscriptions = cbSubscriptions.filter((s) => isOldTeamSubscription(s)); const cbPersonalSubscriptions = cbSubscriptions.filter( - (s) => isPersonalSubscription(s) && s.planId !== Plans.FREE_OPEN_SOURCE.chargebeeId, + (s) => + isPersonalSubscription(s) && + ![Plans.FREE_OPEN_SOURCE.chargebeeId, Plans.FREE.chargebeeId, Plans.FREE_50.chargebeeId].includes( + s.planId!, + ), ); const cbOwnedTeamSubscriptions = ( await this.teamSubscriptionDb.findTeamSubscriptions({ userId: user.id })