Skip to content

Commit c0a5b9a

Browse files
authored
[stripe] Attach billing creator user id to Stripe customer (#16996)
* [stripe] Attach billing creator user id to Stripe customer * fix * fix
1 parent 6fcfe25 commit c0a5b9a

File tree

7 files changed

+129
-96
lines changed

7 files changed

+129
-96
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ components/**/*_pb.js linguist-generated=true
88
components/**/*_pb.ts linguist-generated=true
99
components/**/*_pb.d.ts linguist-generated=true
1010
components/**/*_connectweb.ts linguist-generated=true
11+
components/**/*.pb.ts linguist-generated=true
1112

1213
**/go.sum linguist-generated=true

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21982198
currency,
21992199
email: billingEmail,
22002200
name: billingName,
2201+
billingCreatorUserId: user.id,
22012202
});
22022203
return;
22032204
} catch (error) {

components/usage-api/go/v1/billing.pb.go

Lines changed: 96 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/usage-api/typescript/src/usage/v1/billing.pb.ts

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/usage-api/usage/v1/billing.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ message CreateStripeCustomerRequest {
7070
string name = 2;
7171
string email = 3;
7272
string currency = 4;
73+
// Gitpod User ID for the user setting up billing.
74+
string billing_creator_user_id = 5;
7375
}
7476

7577
message CreateStripeCustomerResponse {

components/usage/pkg/apiv1/billing.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ func (s *BillingService) CreateStripeCustomer(ctx context.Context, req *v1.Creat
143143
}
144144

145145
customer, err := s.stripeClient.CreateCustomer(ctx, stripe.CreateCustomerParams{
146-
AttributuonID: string(attributionID),
147-
Currency: req.GetCurrency(),
148-
Email: req.GetEmail(),
149-
Name: req.GetName(),
146+
AttributuonID: string(attributionID),
147+
Currency: req.GetCurrency(),
148+
Email: req.GetEmail(),
149+
Name: req.GetName(),
150+
BillingCreatorUserID: req.GetBillingCreatorUserId(),
150151
})
151152
if err != nil {
152153
log.WithError(err).Errorf("Failed to create stripe customer.")

components/usage/pkg/stripe/stripe.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
)
2424

2525
const (
26-
AttributionIDMetadataKey = "attributionId"
27-
PreferredCurrencyMetadataKey = "preferredCurrency"
26+
// Metadata keys are used for storing additional context in Stripe
27+
AttributionIDMetadataKey = "attributionId"
28+
PreferredCurrencyMetadataKey = "preferredCurrency"
29+
BillingCreaterUserIDMetadataKey = "billingCreatorUserId"
2830
)
2931

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

280282
type CreateCustomerParams struct {
281-
AttributuonID string
282-
Currency string
283-
Email string
284-
Name string
283+
AttributuonID string
284+
Currency string
285+
Email string
286+
Name string
287+
BillingCreatorUserID string
285288
}
286289

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

0 commit comments

Comments
 (0)