Skip to content
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

Add support for Metadata for PaymentIntentData and SubscriptionData on Checkout Session #1093

Merged
merged 1 commit into from
May 7, 2020
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
8 changes: 8 additions & 0 deletions checkout/session/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func TestCheckoutSessionNew(t *testing.T) {
},
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{
Description: stripe.String("description"),
Metadata: map[string]string{
"attr1": "val1",
"attr2": "val2",
},
Shipping: &stripe.ShippingDetailsParams{
Address: &stripe.AddressParams{
Line1: stripe.String("line1"),
Expand All @@ -51,6 +55,10 @@ func TestCheckoutSessionNew(t *testing.T) {
Quantity: stripe.Int64(2),
},
},
Metadata: map[string]string{
"attr1": "val1",
"attr2": "val2",
},
},
SuccessURL: stripe.String("https://stripe.com/success"),
})
Expand Down
2 changes: 2 additions & 0 deletions checkout_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type CheckoutSessionPaymentIntentDataParams struct {
ApplicationFeeAmount *int64 `form:"application_fee_amount"`
CaptureMethod *string `form:"capture_method"`
Description *string `form:"description"`
Metadata map[string]string `form:"metadata"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted for map[string]string for consistency with plan and price. In theory it should be a pointer I think but in this case it's not updatable so it shouldn't matter right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maps are kind of a special type in that they're always reference types, and so you shouldn't use a pointer with them. See this blog post on them:

var m map[string]int

Map types are reference types, like pointers or slices, and so the value of m above is nil; it doesn't point to an initialized map. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don't do that. To initialize a map, use the built in make function:

m = make(map[string]int)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice, so we didn't overlook this originally when we used map. Thanks for clarifying @brandur-stripe !

OnBehalfOf *string `form:"on_behalf_of"`
ReceiptEmail *string `form:"receipt_email"`
SetupFutureUsage *string `form:"setup_future_usage"`
Expand Down Expand Up @@ -101,6 +102,7 @@ type CheckoutSessionSubscriptionDataParams struct {
Coupon *string `form:"coupon"`
DefaultTaxRates []*string `form:"default_tax_rates"`
Items []*CheckoutSessionSubscriptionDataItemsParams `form:"items"`
Metadata map[string]string `form:"metadata"`
TrialEnd *int64 `form:"trial_end"`
TrialFromPlan *bool `form:"trial_from_plan"`
TrialPeriodDays *int64 `form:"trial_period_days"`
Expand Down