@@ -110,13 +110,16 @@ export class BillingModesImpl implements BillingModes {
110110
111111 // 2. Any personal subscriptions?
112112 // Chargebee takes precedence
113- function isTeamSubscription ( s : Subscription ) : boolean {
114- return ! ! Plans . getById ( s . planId ) ?. team ;
113+ function isPersonalSubscription ( s : Subscription ) : boolean {
114+ return ! Plans . getById ( s . planId ) ?. team ;
115+ }
116+ function isOldTeamSubscription ( s : Subscription ) : boolean {
117+ return ! ! Plans . getById ( s . planId ) ?. team && ! s . teamMembershipId ;
115118 }
116119 const cbSubscriptions = await this . subscriptionSvc . getActivePaidSubscription ( user . id , now ) ;
117- const cbTeamSubscriptions = cbSubscriptions . filter ( ( s ) => isTeamSubscription ( s ) ) ;
120+ const cbTeamSubscriptions = cbSubscriptions . filter ( ( s ) => isOldTeamSubscription ( s ) ) ;
118121 const cbPersonalSubscriptions = cbSubscriptions . filter (
119- ( s ) => ! isTeamSubscription ( s ) && s . planId !== Plans . FREE_OPEN_SOURCE . chargebeeId ,
122+ ( s ) => isPersonalSubscription ( s ) && s . planId !== Plans . FREE_OPEN_SOURCE . chargebeeId ,
120123 ) ;
121124 const cbOwnedTeamSubscriptions = (
122125 await this . teamSubscriptionDb . findTeamSubscriptions ( { userId : user . id } )
@@ -166,15 +169,50 @@ export class BillingModesImpl implements BillingModes {
166169 return usageBased ( ) ;
167170 }
168171 if ( hasCbPaidTeamMembership || hasCbPaidTeamSeat || canUpgradeToUBB ) {
169- // TODO(gpl): Q: How to test the free-tier, then? A: Make sure you have no CB paid seats anymore
170- // For that we could add a new field here, which lists all seats that are "blocking" you, and display them in the UI somewhere.
171- return { mode : "chargebee" , canUpgradeToUBB : true } ; // UBB is enabled, but no seat nor subscription yet.
172+ // Q: How to test the free-tier, then? A: Make sure you have no CB paid seats anymore
173+ // For that we lists all Team Subscriptions/Team Memberships that are "blocking" you, and display them in the UI somewhere.
174+ const result : BillingMode = { mode : "chargebee" , canUpgradeToUBB } ; // UBB is enabled, but no seat nor subscription yet.
175+
176+ const teamNames = [ ] ;
177+ for ( const tm of teamsModes ) {
178+ if ( tm . mode === "chargebee" && tm . teamNames ) {
179+ teamNames . push ( `Team Membership: ${ tm . teamNames } ` ) ;
180+ }
181+ }
182+ const tsOwners = await Promise . all ( cbTeamSubscriptions . map ( ( s ) => this . mapTeamSubscriptionToOwnerName ( s ) ) ) ;
183+ for ( const owner of tsOwners ) {
184+ if ( ! owner ) {
185+ continue ;
186+ }
187+ const [ ts , ownerName ] = owner ;
188+ teamNames . push ( `Team Subscription '${ Plans . getById ( ts . planId ) ?. name } ' (owner: ${ ownerName } )` ) ;
189+ }
190+ if ( teamNames . length > 0 ) {
191+ result . teamNames = teamNames ;
192+ }
193+
194+ return result ;
172195 }
173196
174197 // UBB free tier
175198 return usageBased ( ) ;
176199 }
177200
201+ protected async mapTeamSubscriptionToOwnerName ( s : Subscription ) : Promise < [ TeamSubscription , string ] | undefined > {
202+ if ( ! s || ! s . teamSubscriptionSlotId ) {
203+ return undefined ;
204+ }
205+ const ts = await this . teamSubscriptionDb . findTeamSubscriptionBySlotId ( s . teamSubscriptionSlotId ! ) ;
206+ if ( ! ts ) {
207+ return undefined ;
208+ }
209+ const user = await this . userDB . findUserById ( ts . userId ) ;
210+ if ( ! user ) {
211+ return undefined ;
212+ }
213+ return [ ts , user . name || user . fullName || "---" ] ;
214+ }
215+
178216 async getBillingModeForTeam ( team : Team , _now : Date ) : Promise < BillingMode > {
179217 if ( ! this . config . enablePayment ) {
180218 // Payment is not enabled. E.g. Self-Hosted.
@@ -200,7 +238,7 @@ export class BillingModesImpl implements BillingModes {
200238 return { mode : "chargebee" , canUpgradeToUBB : isUsageBasedBillingEnabled } ;
201239 }
202240
203- return { mode : "chargebee" , paid : true } ;
241+ return { mode : "chargebee" , teamNames : [ team . name ] , paid : true } ;
204242 }
205243
206244 // 2. UBB enabled at all?
0 commit comments