#JCrags-GO-metadata
1 messages ยท Page 1 of 1 (latest)
Sure thing ๐
Out of curiosity have you tested setting metadata on a Checkout Session using our GO library?
I'm not super familiar with our GO library but I do think we expect metadata here for the Session object: https://github.com/stripe/stripe-go/blob/master/checkout_session.go#L1049
@fiery onyx let's chat here
No, the function session.New() requires parameter with type *stripe.CheckoutSessionParams not *stripe.CheckoutSession so it's missing the metadata option I believe
/checkout/session/client.go line 25
Give me a moment to catch up
@fiery onyx metadata is included automatically from the Params struct, it's in all the resources as expected
See https://github.com/stripe/stripe-go/pull/1468 where one of the maintainers explained the misunderstanding
That's what I needed, thanks!
One other question I have though, which relates to metadata on lineitems when creating a checkout session. When the checkout.session.completed is fired, and I retrieve the session object, I can loop over the line items by calling this: https://stripe.com/docs/api/checkout/sessions/line_items but when I do this, the metadata is empty, even though the product really has metadata configured, I can see it in the dashboard under "Metadata" section just fine. Do I really have to retrieve the product via another API call, and then retrieve the metadata? Here is the output when looping over the line items as an example, you can see the metadata is empty, even though there is actually metadata for that product ID:
(*stripe.LineItem)(0xc000761400)({
AmountSubtotal: (int64) 10081,
AmountTotal: (int64) 12198,
Currency: (stripe.Currency) (len=3) "eur",
ID: (string) (len=27) "li_1L5bsIFKn7uROhgCrsyN4cdH",
Object: (string) (len=4) "item",
Price: (*stripe.Price)(0xc0002ea900)({
Active: (bool) false,
BillingScheme: (stripe.PriceBillingScheme) (len=8) "per_unit",
Created: (int64) 1654029670,
Currency: (stripe.Currency) (len=3) "eur",
ID: (string) (len=30) "price_1L5bsIFKn7uROhgCttJqv68M",
Metadata: (map[string]string) {
},
Product: (*stripe.Product)(0xc00074a780)({
ID: (string) (len=19) "prod_LnCGlxJHX7viJi",
Metadata: (map[string]string) <nil>,
}),
UnitAmount: (int64) 10081,
UnitAmountDecimal: (float64) 10081
}),
Quantity: (int64) 1,
Taxes: ([]*stripe.LineItemTax) <nil>
})
From the dasbhoard
If the metadata is on the Product then it appears only on the Product not the LineItem
Are you properly expanding the Product when you look at the line items?
Because my guess right now is that you are just getting product: 'prod_123'
No I am not expanding, but I can do that if that's what it requires to read that metadata. The only thing I am doing is looping over the lineitems of the session via Next()
Every object has their own metadata
so there's no reason for the Product metadata to appear on the LineItem or the Price metadata
and objects are "linked" together in the API
A Checkout Sessions has N LineItems in line_items. Each LineItem points to a Price, each Price points to a Product
what you want is to carefully read through https://stripe.com/docs/expand
You can call https://stripe.com/docs/api/checkout/sessions/retrieve and expand the line items and the underlying Price's Product via AddExpand("line_items.data.price.product")
That's even better yes, that's exactly what I need ๐ I was just a bit confused because I could see the "Metadata" object in the response but that's just because it's mapped to that struct and that's why it's empty. I got it now thank you so much for your help. Have a great day/evening ๐
yeah it's a quirk of stripe-go that always uses the whole resource but sometimes just has ID set