Skip to content

[UBP] Add server method to create a stripe customers for an individual user #12753

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 2 commits into from
Sep 8, 2022

Conversation

andrew-farries
Copy link
Contributor

@andrew-farries andrew-farries commented Sep 8, 2022

Description

Add a createOrUpdateStripeCustomerForUser method to server to allow the creation of Stripe customers for individual users. Previously we had only the createOrUpdateStripeCustomerForTeam method which would create a Stripe customer for a Gitpod team.

The only difference between the createOrUpdateStripeCustomerForUser and createOrUpdateStripeCustomerForTeam methods is the metadata in the resulting Stripe customer object. For teams we store [teamId]: foo and for users we store [userId]: bar.

Related Issue(s)

Part of #12685

How to test

  • Set the billing mode to UBP for your user in the preview environment by creating a team with Gitpod in the name.
  • In the developer console run:
await window._gp.gitpodService.server.createOrUpdateStripeCustomerForUser("EUR")
  • Visit the Stripe dashboard and see the new customer (without payment method or subscription) with the userId in the metadata.

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview
  • /werft with-payment

Andrew Farries added 2 commits September 8, 2022 07:14
Implement `findCustomerByTeamId` and `findCustomerByUserId` in terms of
this more general method.
Directly analogous to createOrUpdateStripeCustomerForTeam, the only
difference is the metadata on the resulting Stripe customer.
@andrew-farries andrew-farries requested a review from a team September 8, 2022 07:18
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Sep 8, 2022
@roboquat roboquat added the size/M label Sep 8, 2022
@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-af-server-create-stripe-customer-for-user.6 because the annotations in the pull request description changed
(with .werft/ from main)

@@ -2086,6 +2086,24 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
}
}

async createOrUpdateStripeCustomerForUser(ctx: TraceContext, currency: string): Promise<void> {
const user = this.checkAndBlockUser("createOrUpdateStripeCustomerForUser");
await this.ensureStripeApiIsAllowed({ user });
Copy link
Member

Choose a reason for hiding this comment

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

💯

@@ -2086,6 +2086,24 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
}
}

async createOrUpdateStripeCustomerForUser(ctx: TraceContext, currency: string): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

☁️ Originally I thought about merging these two methods on attributionId. But I think it makes sense to have them separate as they have different semantics around access rights etc.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tested and works. ✔️

@roboquat roboquat merged commit 7df06a8 into main Sep 8, 2022
@roboquat roboquat deleted the af/server-create-stripe-customer-for-user branch September 8, 2022 07:59
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/M team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants