Skip to content

Commit bd15072

Browse files
author
Laurie T. Malau
committed
[usage] Use createStripeSubscription behind feature flag
1 parent 5e09a4d commit bd15072

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb"
119119
import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb";
120120
import { IncrementalPrebuildsService } from "../prebuilds/incremental-prebuilds-service";
121121
import { ConfigProvider } from "../../../src/workspace/config-provider";
122+
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
122123

123124
@injectable()
124125
export class GitpodServerEEImpl extends GitpodServerImpl {
@@ -2177,9 +2178,10 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21772178

21782179
const user = this.checkAndBlockUser("subscribeToStripe");
21792180

2181+
let team: Team | undefined;
21802182
try {
21812183
if (attrId.kind === "team") {
2182-
const team = await this.guardTeamOperation(attrId.teamId, "update");
2184+
team = await this.guardTeamOperation(attrId.teamId, "update");
21832185
await this.ensureStripeApiIsAllowed({ team });
21842186
} else {
21852187
await this.ensureStripeApiIsAllowed({ user });
@@ -2189,8 +2191,21 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21892191
throw new Error(`No Stripe customer profile for '${attributionId}'`);
21902192
}
21912193

2192-
await this.stripeService.setDefaultPaymentMethodForCustomer(customerId, setupIntentId);
2193-
await this.stripeService.createSubscriptionForCustomer(customerId, attributionId);
2194+
const createStripeSubscriptionOnUsage = await getExperimentsClientForBackend().getValueAsync(
2195+
"createStripeSubscriptionOnUsage",
2196+
false,
2197+
{
2198+
user: user,
2199+
teamId: team ? team.id : undefined,
2200+
},
2201+
);
2202+
2203+
if (createStripeSubscriptionOnUsage) {
2204+
await this.billingService.createStripeSubscription({ attributionId, setupIntentId, usageLimit });
2205+
} else {
2206+
await this.stripeService.setDefaultPaymentMethodForCustomer(customerId, setupIntentId);
2207+
await this.stripeService.createSubscriptionForCustomer(customerId, attributionId);
2208+
}
21942209

21952210
// Creating a cost center for this customer
21962211
const { costCenter } = await this.usageService.setCostCenter({

0 commit comments

Comments
 (0)