Skip to content

Commit 1c01d58

Browse files
svenefftingeroboquat
authored andcommitted
[server] don't rely on stripe for billingmode
1 parent 1797a0c commit 1c01d58

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

components/server/ee/src/billing/billing-mode.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import { ConfigCatClientFactory } from "@gitpod/gitpod-protocol/lib/experiments/
1111
import { SubscriptionService } from "@gitpod/gitpod-payment-endpoint/lib/accounting";
1212
import { Subscription } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
1313
import { Config } from "../../../src/config";
14-
import { StripeService } from "../user/stripe-service";
1514
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
1615
import { TeamDB, TeamSubscription2DB, TeamSubscriptionDB, UserDB } from "@gitpod/gitpod-db/lib";
1716
import { Plans } from "@gitpod/gitpod-protocol/lib/plans";
1817
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
1918
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";
2024

2125
export const BillingModes = Symbol("BillingModes");
2226
export interface BillingModes {
@@ -41,7 +45,7 @@ export class BillingModesImpl implements BillingModes {
4145
@inject(Config) protected readonly config: Config;
4246
@inject(ConfigCatClientFactory) protected readonly configCatClientFactory: ConfigCatClientFactory;
4347
@inject(SubscriptionService) protected readonly subscriptionSvc: SubscriptionService;
44-
@inject(StripeService) protected readonly stripeService: StripeService;
48+
@inject(UsageServiceDefinition.name) protected readonly usageService: UsageServiceClient;
4549
@inject(TeamSubscriptionDB) protected readonly teamSubscriptionDb: TeamSubscriptionDB;
4650
@inject(TeamSubscription2DB) protected readonly teamSubscription2Db: TeamSubscription2DB;
4751
@inject(TeamDB) protected readonly teamDB: TeamDB;
@@ -116,10 +120,10 @@ export class BillingModesImpl implements BillingModes {
116120

117121
// Stripe: Active personal subsciption?
118122
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) {
123127
hasUbbPersonal = true;
124128
}
125129

@@ -191,10 +195,10 @@ export class BillingModesImpl implements BillingModes {
191195

192196
// 3. Now we're usage-based. We only have to figure out whether we have a plan yet or not.
193197
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) {
198202
result.paid = true;
199203
}
200204
return result;

0 commit comments

Comments
 (0)