-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[server][dashboard] Allow new Stripe customers to select their billing currency #12376
Changes from all commits
e2381bb
fded9fc
428226d
82362cc
491c9fc
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 |
---|---|---|
|
@@ -80,7 +80,7 @@ import { | |
TeamSubscriptionSlot, | ||
TeamSubscriptionSlotResolved, | ||
} from "@gitpod/gitpod-protocol/lib/team-subscription-protocol"; | ||
import { Currency, Plans } from "@gitpod/gitpod-protocol/lib/plans"; | ||
import { Plans } from "@gitpod/gitpod-protocol/lib/plans"; | ||
import * as pThrottle from "p-throttle"; | ||
import { formatDate } from "@gitpod/gitpod-protocol/lib/util/date-time"; | ||
import { FindUserByIdentityStrResult, UserService } from "../../../src/user/user-service"; | ||
|
@@ -2054,22 +2054,37 @@ export class GitpodServerEEImpl extends GitpodServerImpl { | |
} | ||
} | ||
|
||
async createOrUpdateStripeCustomerForTeam(ctx: TraceContext, teamId: string, currency: string): Promise<void> { | ||
const user = this.checkAndBlockUser("createOrUpdateStripeCustomerForTeam"); | ||
const team = await this.guardTeamOperation(teamId, "update"); | ||
await this.ensureStripeApiIsAllowed({ team }); | ||
try { | ||
let customer = await this.stripeService.findCustomerByTeamId(team!.id); | ||
if (!customer) { | ||
customer = await this.stripeService.createCustomerForTeam(user, team!); | ||
} | ||
await this.stripeService.setPreferredCurrencyForCustomer(customer, currency); | ||
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. Would this allow me to change my currency after I've got a subscription in one currency? And if so, is that a problem? 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.
Yes -- you can always cancel your Subscription, then buy a new Subscription in any available currency.
No -- this is a feature. If you're paying in USD, but want to change to EUR, you can. |
||
} catch (error) { | ||
log.error(`Failed to update Stripe customer profile for team '${teamId}'`, error); | ||
throw new ResponseError( | ||
ErrorCodes.INTERNAL_SERVER_ERROR, | ||
`Failed to update Stripe customer profile for team '${teamId}'`, | ||
); | ||
} | ||
} | ||
|
||
protected defaultSpendingLimit = 100; | ||
async subscribeTeamToStripe( | ||
ctx: TraceContext, | ||
teamId: string, | ||
setupIntentId: string, | ||
currency: Currency, | ||
): Promise<void> { | ||
const user = this.checkAndBlockUser("subscribeUserToStripe"); | ||
async subscribeTeamToStripe(ctx: TraceContext, teamId: string, setupIntentId: string): Promise<void> { | ||
this.checkAndBlockUser("subscribeUserToStripe"); | ||
const team = await this.guardTeamOperation(teamId, "update"); | ||
await this.ensureStripeApiIsAllowed({ team }); | ||
try { | ||
let customer = await this.stripeService.findCustomerByTeamId(team!.id); | ||
if (!customer) { | ||
customer = await this.stripeService.createCustomerForTeam(user, team!, setupIntentId); | ||
throw new Error(`No Stripe customer profile for team '${team.id}'`); | ||
} | ||
await this.stripeService.createSubscriptionForCustomer(customer.id, currency); | ||
await this.stripeService.setDefaultPaymentMethodForCustomer(customer, setupIntentId); | ||
await this.stripeService.createSubscriptionForCustomer(customer); | ||
|
||
const attributionId = AttributionId.render({ kind: "team", teamId }); | ||
|
||
|
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.
How do we ensure that
currency
is a valid value? Does Stripe reject an invalid type of currency?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.
currency
can be any string. Then, when we choose a Gitpod Product Price in Stripe, we see if one is available in our configuration for that specific string. If there is, great. If not, we pick theUSD
Price.