@@ -16,7 +16,7 @@ import { AuthProviderService } from "../auth/auth-provider-service";
16
16
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics" ;
17
17
import { Config } from "../config" ;
18
18
import { StripeService } from "../../ee/src/user/stripe-service" ;
19
- import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution " ;
19
+ import { BillingModes } from "../../ee/src/billing/billing-mode " ;
20
20
21
21
@injectable ( )
22
22
export class UserDeletionService {
@@ -33,6 +33,7 @@ export class UserDeletionService {
33
33
@inject ( AuthProviderService ) protected readonly authProviderService : AuthProviderService ;
34
34
@inject ( IAnalyticsWriter ) protected readonly analytics : IAnalyticsWriter ;
35
35
@inject ( StripeService ) protected readonly stripeService : StripeService ;
36
+ @inject ( BillingModes ) protected readonly billingMode : BillingModes ;
36
37
37
38
/**
38
39
* This method deletes a User logically. The contract here is that after running this method without receiving an
@@ -50,20 +51,10 @@ export class UserDeletionService {
50
51
log . debug ( { userId : id } , "Is deleted but markDeleted already set. Continuing." ) ;
51
52
}
52
53
53
- if ( this . config . enablePayment ) {
54
- let subscriptionId ;
55
- try {
56
- // Also cancel any usage-based (Stripe) subscription
57
- subscriptionId = await this . stripeService . findUncancelledSubscriptionByAttributionId (
58
- AttributionId . render ( { kind : "user" , userId : user . id } ) ,
59
- ) ;
60
- if ( subscriptionId ) {
61
- await this . stripeService . cancelSubscription ( subscriptionId ) ;
62
- }
63
- } catch ( error ) {
64
- log . error ( "Error cancelling Stripe user subscription" , error , { subscriptionId } ) ;
65
- throw new Error ( `Failed to cancel stripe subscription. ${ error } ` ) ;
66
- }
54
+ const billingMode = await this . billingMode . getBillingModeForUser ( user , new Date ( ) ) ;
55
+ if ( billingMode . mode === "usage-based" ) {
56
+ // Also cancel any usage-based (Stripe) subscription
57
+ await this . stripeService . cancelSubscriptionForUser ( user . id ) ;
67
58
}
68
59
69
60
// Stop all workspaces
0 commit comments