#JCrags-GO-metadata

1 messages ยท Page 1 of 1 (latest)

granite cargo
#

Hi! Let me take a look.

fiery onyx
#

Sure thing ๐Ÿ™‚

granite cargo
#

Out of curiosity have you tested setting metadata on a Checkout Session using our GO library?

lament temple
#

@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

faint karma
#

@fiery onyx metadata is included automatically from the Params struct, it's in all the resources as expected

fiery onyx
#

That's what I needed, thanks!

faint karma
#

Sure thing!

#

Going to archive the thread! Have a grand day!

#

hello back

fiery onyx
#

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

faint karma
#

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'

fiery onyx
#

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()

faint karma
#

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

fiery onyx
#

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 ๐Ÿ™‚

faint karma
#

yeah it's a quirk of stripe-go that always uses the whole resource but sometimes just has ID set