-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 }); | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should supply the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.