Skip to content

Commit 00246c6

Browse files
svenefftingeroboquat
authored andcommitted
[ubp] ensure right billingStrategy
1 parent 124a2e6 commit 00246c6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

components/server/ee/src/workspace/gitpod-server-impl.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -2020,13 +2020,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20202020
});
20212021
}
20222022

2023-
protected async ensureIsUsageBasedFeatureFlagEnabled(user: User): Promise<void> {
2024-
const isUsageBasedBillingEnabled = await this.isUsageBasedFeatureFlagEnabled(user);
2025-
if (!isUsageBasedBillingEnabled) {
2026-
throw new ResponseError(ErrorCodes.PERMISSION_DENIED, "not allowed");
2027-
}
2028-
}
2029-
20302023
protected async ensureChargebeeApiIsAllowed(sub: { user?: User; team?: Team }): Promise<void> {
20312024
await this.ensureBillingMode(sub, (m) => m.mode === "chargebee");
20322025
}
@@ -2281,7 +2274,16 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
22812274
await this.guardCostCenterAccess(ctx, user.id, attrId, "update");
22822275

22832276
const response = await this.usageService.getCostCenter({ attributionId });
2284-
if (response?.costCenter?.billingStrategy !== CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE) {
2277+
2278+
// backward compatibility for cost centers that were created before introduction of BillingStrategy
2279+
if (response.costCenter) {
2280+
const stripeSubscriptionId = await this.findStripeSubscriptionId(ctx, attributionId);
2281+
if (stripeSubscriptionId != undefined) {
2282+
response.costCenter.billingStrategy = CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE;
2283+
}
2284+
}
2285+
2286+
if (response.costCenter?.billingStrategy !== CostCenter_BillingStrategy.BILLING_STRATEGY_STRIPE) {
22852287
throw new ResponseError(
22862288
ErrorCodes.BAD_REQUEST,
22872289
`Setting a usage limit is not valid for non-Stripe billing strategies`,
@@ -2291,8 +2293,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
22912293
costCenter: {
22922294
attributionId,
22932295
spendingLimit: usageLimit,
2294-
billingStrategy:
2295-
response?.costCenter?.billingStrategy || CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER,
2296+
billingStrategy: CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER,
22962297
},
22972298
});
22982299

0 commit comments

Comments
 (0)