File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,10 @@ export class StripeService {
125
125
return result . data [ 0 ] ;
126
126
}
127
127
128
+ async cancelSubscription ( subscriptionId : string ) : Promise < void > {
129
+ await this . getStripe ( ) . subscriptions . del ( subscriptionId ) ;
130
+ }
131
+
128
132
async createSubscriptionForCustomer ( customerId : string , currency : Currency ) : Promise < void > {
129
133
const priceId = this . config ?. stripeConfig ?. usageProductPriceIds [ currency ] ;
130
134
if ( ! priceId ) {
Original file line number Diff line number Diff line change @@ -1455,17 +1455,22 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
1455
1455
1456
1456
protected async onTeamDeleted ( teamId : string ) : Promise < void > {
1457
1457
const now = new Date ( ) ;
1458
- const teamSubscription = await this . teamSubscription2DB . findForTeam ( teamId , now . toISOString ( ) ) ;
1459
- if ( ! teamSubscription ) {
1460
- // No team subscription, nothing to do 🌴
1461
- return ;
1458
+ const ts2 = await this . teamSubscription2DB . findForTeam ( teamId , now . toISOString ( ) ) ;
1459
+ if ( ts2 ) {
1460
+ const chargebeeSubscriptionId = ts2 . paymentReference ;
1461
+ await this . chargebeeService . cancelSubscription (
1462
+ chargebeeSubscriptionId ,
1463
+ { } ,
1464
+ { teamId, chargebeeSubscriptionId } ,
1465
+ ) ;
1466
+ }
1467
+ const teamCustomer = await this . stripeService . findCustomerByTeamId ( teamId ) ;
1468
+ if ( teamCustomer ) {
1469
+ const subsciption = await this . stripeService . findUncancelledSubscriptionByCustomer ( teamCustomer . id ) ;
1470
+ if ( subsciption ) {
1471
+ await this . stripeService . cancelSubscription ( subsciption . id ) ;
1472
+ }
1462
1473
}
1463
- const chargebeeSubscriptionId = teamSubscription . paymentReference ;
1464
- await this . chargebeeService . cancelSubscription (
1465
- chargebeeSubscriptionId ,
1466
- { } ,
1467
- { teamId, chargebeeSubscriptionId } ,
1468
- ) ;
1469
1474
}
1470
1475
1471
1476
protected async updateTeamSubscriptionQuantity ( teamSubscription : TeamSubscription2 ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments