@@ -11,12 +11,16 @@ import { ConfigCatClientFactory } from "@gitpod/gitpod-protocol/lib/experiments/
11
11
import { SubscriptionService } from "@gitpod/gitpod-payment-endpoint/lib/accounting" ;
12
12
import { Subscription } from "@gitpod/gitpod-protocol/lib/accounting-protocol" ;
13
13
import { Config } from "../../../src/config" ;
14
- import { StripeService } from "../user/stripe-service" ;
15
14
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode" ;
16
15
import { TeamDB , TeamSubscription2DB , TeamSubscriptionDB , UserDB } from "@gitpod/gitpod-db/lib" ;
17
16
import { Plans } from "@gitpod/gitpod-protocol/lib/plans" ;
18
17
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution" ;
19
18
import { TeamSubscription , TeamSubscription2 } from "@gitpod/gitpod-protocol/lib/team-subscription-protocol" ;
19
+ import {
20
+ CostCenter_BillingStrategy ,
21
+ UsageServiceClient ,
22
+ UsageServiceDefinition ,
23
+ } from "@gitpod/usage-api/lib/usage/v1/usage.pb" ;
20
24
21
25
export const BillingModes = Symbol ( "BillingModes" ) ;
22
26
export interface BillingModes {
@@ -41,7 +45,7 @@ export class BillingModesImpl implements BillingModes {
41
45
@inject ( Config ) protected readonly config : Config ;
42
46
@inject ( ConfigCatClientFactory ) protected readonly configCatClientFactory : ConfigCatClientFactory ;
43
47
@inject ( SubscriptionService ) protected readonly subscriptionSvc : SubscriptionService ;
44
- @inject ( StripeService ) protected readonly stripeService : StripeService ;
48
+ @inject ( UsageServiceDefinition . name ) protected readonly usageService : UsageServiceClient ;
45
49
@inject ( TeamSubscriptionDB ) protected readonly teamSubscriptionDb : TeamSubscriptionDB ;
46
50
@inject ( TeamSubscription2DB ) protected readonly teamSubscription2Db : TeamSubscription2DB ;
47
51
@inject ( TeamDB ) protected readonly teamDB : TeamDB ;
@@ -116,10 +120,10 @@ export class BillingModesImpl implements BillingModes {
116
120
117
121
// Stripe: Active personal subsciption?
118
122
let hasUbbPersonal = false ;
119
- const subscriptionId = await this . stripeService . findUncancelledSubscriptionByAttributionId (
120
- AttributionId . render ( { kind : "user" , userId : user . id } ) ,
121
- ) ;
122
- if ( subscriptionId ) {
123
+ const constCenterResponse = await this . usageService . getCostCenter ( {
124
+ attributionId : AttributionId . render ( { kind : "user" , userId : user . id } ) ,
125
+ } ) ;
126
+ if ( constCenterResponse . costCenter ?. billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
123
127
hasUbbPersonal = true ;
124
128
}
125
129
@@ -191,10 +195,10 @@ export class BillingModesImpl implements BillingModes {
191
195
192
196
// 3. Now we're usage-based. We only have to figure out whether we have a plan yet or not.
193
197
const result : BillingMode = { mode : "usage-based" } ;
194
- const subscriptionId = await this . stripeService . findUncancelledSubscriptionByAttributionId (
195
- AttributionId . render ( { kind : "team" , teamId : team . id } ) ,
196
- ) ;
197
- if ( subscriptionId ) {
198
+ const costCenter = await this . usageService . getCostCenter ( {
199
+ attributionId : AttributionId . render ( AttributionId . create ( team ) ) ,
200
+ } ) ;
201
+ if ( costCenter . costCenter ?. billingStrategy === CostCenter_BillingStrategy . BILLING_STRATEGY_STRIPE ) {
198
202
result . paid = true ;
199
203
}
200
204
return result ;
0 commit comments