Skip to content

[usage] Use createStripeSubscription behind feature flag #14332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb"
import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb";
import { IncrementalPrebuildsService } from "../prebuilds/incremental-prebuilds-service";
import { ConfigProvider } from "../../../src/workspace/config-provider";
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";

@injectable()
export class GitpodServerEEImpl extends GitpodServerImpl {
Expand Down Expand Up @@ -2177,9 +2178,10 @@ export class GitpodServerEEImpl extends GitpodServerImpl {

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

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

await this.stripeService.setDefaultPaymentMethodForCustomer(customerId, setupIntentId);
await this.stripeService.createSubscriptionForCustomer(customerId, attributionId);
const createStripeSubscriptionOnUsage = await getExperimentsClientForBackend().getValueAsync(
"createStripeSubscriptionOnUsage",
false,
{
user: user,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: which user/team should we be feature flagging for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you run through the subscription workflow in staging for both a user and a team, and it works through the usage component, then I'd largely go and enable it for all in prod, but monitor.

Adding specific target rules here is mostly for completeness, and for if it does go wrong that we can disable for all but reproduce for our team or something like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should supply the team_id as well for the case when it's enabled by a team

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely - will add it.

teamId: team ? team.id : undefined,
},
);

if (createStripeSubscriptionOnUsage) {
await this.billingService.createStripeSubscription({ attributionId, setupIntentId, usageLimit });
} else {
await this.stripeService.setDefaultPaymentMethodForCustomer(customerId, setupIntentId);
await this.stripeService.createSubscriptionForCustomer(customerId, attributionId);
}

// Creating a cost center for this customer
const { costCenter } = await this.usageService.setCostCenter({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-up, we should then move the cost-center setting into the CreateStripeSubscription call

Expand Down