@@ -102,9 +102,17 @@ export class BillingModesImpl implements BillingModes {
102
102
) ;
103
103
}
104
104
105
+ // Stripe: Active personal subsciption?
106
+ let hasUbbPersonal = false ;
107
+ const billingStrategy = await this . usageService . getCurrentBillingStategy ( { kind : "user" , userId : user . id } ) ;
108
+ if ( billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
109
+ hasUbbPersonal = true ;
110
+ }
111
+
105
112
// 1. UBB enabled?
106
- if ( ! isUsageBasedBillingEnabled ) {
113
+ if ( ! isUsageBasedBillingEnabled && ! hasUbbPersonal ) {
107
114
// UBB is not enabled: definitely chargebee
115
+ // EXCEPT we're doing a rollback
108
116
return { mode : "chargebee" } ;
109
117
}
110
118
@@ -138,13 +146,6 @@ export class BillingModesImpl implements BillingModes {
138
146
}
139
147
}
140
148
141
- // Stripe: Active personal subsciption?
142
- let hasUbbPersonal = false ;
143
- const billingStrategy = await this . usageService . getCurrentBillingStategy ( { kind : "user" , userId : user . id } ) ;
144
- if ( billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
145
- hasUbbPersonal = true ;
146
- }
147
-
148
149
// 3. Check team memberships/plans
149
150
// UBB overrides wins if there is _any_. But if there is none, use the existing Chargebee subscription.
150
151
const teamsModes = await Promise . all ( teams . map ( ( t ) => this . getBillingModeForTeam ( t , now ) ) ) ;
@@ -241,17 +242,18 @@ export class BillingModesImpl implements BillingModes {
241
242
return { mode : "chargebee" , teamNames : [ team . name ] , paid : true } ;
242
243
}
243
244
244
- // 2. UBB enabled at all?
245
- if ( ! isUsageBasedBillingEnabled ) {
246
- return { mode : "chargebee" } ;
247
- }
248
-
249
- // 3. Now we're usage-based. We only have to figure out whether we have a plan yet or not.
250
- const result : BillingMode = { mode : "usage-based" } ;
245
+ // 2. UBP enabled OR respective BillingStrategy?
251
246
const billingStrategy = await this . usageService . getCurrentBillingStategy ( AttributionId . create ( team ) ) ;
252
- if ( billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
253
- result . paid = true ;
247
+ if ( billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE || isUsageBasedBillingEnabled ) {
248
+ // Now we're usage-based. We only have to figure out whether we have a paid plan yet or not.
249
+ const result : BillingMode = { mode : "usage-based" } ;
250
+ if ( billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
251
+ result . paid = true ;
252
+ }
253
+ return result ;
254
254
}
255
- return result ;
255
+
256
+ // 3. Default case if none is enabled: fall back to Chargebee
257
+ return { mode : "chargebee" } ;
256
258
}
257
259
}
0 commit comments