Skip to content

[stripe] Attach billing creator user id to Stripe customer #16996

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 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ components/**/*_pb.js linguist-generated=true
components/**/*_pb.ts linguist-generated=true
components/**/*_pb.d.ts linguist-generated=true
components/**/*_connectweb.ts linguist-generated=true
components/**/*.pb.ts linguist-generated=true

**/go.sum linguist-generated=true
1 change: 1 addition & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
currency,
email: billingEmail,
name: billingName,
billingCreatorUserId: user.id,
});
return;
} catch (error) {
Expand Down
179 changes: 96 additions & 83 deletions components/usage-api/go/v1/billing.pb.go

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion components/usage-api/typescript/src/usage/v1/billing.pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/usage-api/usage/v1/billing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ message CreateStripeCustomerRequest {
string name = 2;
string email = 3;
string currency = 4;
// Gitpod User ID for the user setting up billing.
string billing_creator_user_id = 5;
}

message CreateStripeCustomerResponse {
Expand Down
9 changes: 5 additions & 4 deletions components/usage/pkg/apiv1/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ func (s *BillingService) CreateStripeCustomer(ctx context.Context, req *v1.Creat
}

customer, err := s.stripeClient.CreateCustomer(ctx, stripe.CreateCustomerParams{
AttributuonID: string(attributionID),
Currency: req.GetCurrency(),
Email: req.GetEmail(),
Name: req.GetName(),
AttributuonID: string(attributionID),
Currency: req.GetCurrency(),
Email: req.GetEmail(),
Name: req.GetName(),
BillingCreatorUserID: req.GetBillingCreatorUserId(),
})
if err != nil {
log.WithError(err).Errorf("Failed to create stripe customer.")
Expand Down
20 changes: 12 additions & 8 deletions components/usage/pkg/stripe/stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
)

const (
AttributionIDMetadataKey = "attributionId"
PreferredCurrencyMetadataKey = "preferredCurrency"
// Metadata keys are used for storing additional context in Stripe
AttributionIDMetadataKey = "attributionId"
PreferredCurrencyMetadataKey = "preferredCurrency"
BillingCreaterUserIDMetadataKey = "billingCreatorUserId"
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to have a comment here what we use these for ☁️

Copy link
Member Author

Choose a reason for hiding this comment

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

There are comments in the respective usages. I'll add something..

Copy link
Member Author

Choose a reason for hiding this comment

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

added comment

)

type Client struct {
Expand Down Expand Up @@ -278,10 +280,11 @@ func (c *Client) GetPriceInformation(ctx context.Context, priceID string) (price
}

type CreateCustomerParams struct {
AttributuonID string
Currency string
Email string
Name string
AttributuonID string
Currency string
Email string
Name string
BillingCreatorUserID string
}

func (c *Client) CreateCustomer(ctx context.Context, params CreateCustomerParams) (customer *stripe.Customer, err error) {
Expand All @@ -298,8 +301,9 @@ func (c *Client) CreateCustomer(ctx context.Context, params CreateCustomerParams
// We set the preferred currency on the metadata such that we can later retreive it when we're creating a Subscription
// This is also done to propagate the preference into the Customer such that we can inform them when their
// new subscription would use a different currency to the previous one
PreferredCurrencyMetadataKey: params.Currency,
AttributionIDMetadataKey: params.AttributuonID,
PreferredCurrencyMetadataKey: params.Currency,
AttributionIDMetadataKey: params.AttributuonID,
BillingCreaterUserIDMetadataKey: params.BillingCreatorUserID,
},
},
Email: stripe.String(params.Email),
Expand Down