#jdesignv2_checkout-product-metadata

1 messages ยท Page 1 of 1 (latest)

rocky etherBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1230928604116811840

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

noble pawnBOT
peak dagger
#

Also for context this is how I currently 'append' my line_items in the code:

for (let a = 0; a < Object.keys(productInformation.allOptions).length; a++) {
  const key = Object.keys(productInformation.allOptions)[a];
  const option = productInformation.allOptions[key];
  products.push({
    "price_data": {
      "currency": "EUR",
      "product_data": {
        "name": option.label,
        "metadata": {
          "id": key,
          "index": productInformation.selectedOptions[key]
        }
      },
      "unit_amount": option.price
    },
    "quantity": 1
  })
}

And I don't really want to append the checkout_session's metadata as this is going to be complicated as it allows only strin : string values

rocky etherBOT
strange badge
#

Hi ๐Ÿ‘‹

Are you just receiving the Checkout Session object in the checkout.session.completed event?

peak dagger
#

in this case yeah - I also receive other events like application_fee.created for other 'tasks' but only checkout.session.completed for fullfilling the order

strange badge
#

Right because only yhe checkout session will have that info

peak dagger
#

ok good

strange badge
#

However, line_items are not returned expanded by default

peak dagger
#

I am already expanding line_items already. This is the code:

case 'checkout.session.completed':
  checkout = event.data.object;
  status = checkout.status;
  // console.log(checkout);
  console.log(`Checkout SESSION succeeded status is ${status}.`);
  let checkoutSession = await stripe.checkout.sessions.retrieve(
    checkout.id,
    {
      expand: ["customer",
        "payment_intent",
        "line_items",
        "line_items.data.price.product",
        "invoice"
      ],
    }
  );

  if (checkout.mode != "subscription") {
    fullfillOrder(checkoutSession);
  }
  break;
strange badge
#

Okay so you are retrieving them too?

peak dagger
#

yup

#

But there are no metadata keys anywhere

#

at least not filled

#

one sec

#
[
  ...
  {
    id: 'li_1P7KgwKBPpELGMIUOxGSjp0A',
    object: 'item',
    amount_discount: 0,
    amount_subtotal: 2000,
    amount_tax: 0,
    amount_total: 2000,
    currency: 'eur',
    description: '7colorPrint | alu_dibond',
    price: {
      id: 'price_1P7KgwKBPpELGMIUWgy6JCDm',
      object: 'price',
      active: false,
      billing_scheme: 'per_unit',
      created: 1713545617,
      currency: 'eur',
      custom_unit_amount: null,
      livemode: false,
      lookup_key: null,
      metadata: {},
      nickname: null,
      product: [Object],
      recurring: null,
      tax_behavior: 'unspecified',
      tiers_mode: null,
      transform_quantity: null,
      type: 'one_time',
      unit_amount: 2000,
      unit_amount_decimal: '2000'
    },
    quantity: 1
  }
]
strange badge
peak dagger
#

exactly

peak dagger
#

The metadata object is just empty

strange badge
#

And it looks like the metadata is set on the product_data

peak dagger
#

yup

#

I also just checked - It seems you cannot set the metadata at a higher location f.ex. in the line_item itself. It is first allowed in the product_data...

strange badge
#

Sorry I'm not sure what you mean by that. Are you saying that, even though we allow passing metadata on price_data and product_data, it is only returned when set on line_item?

peak dagger
#

No I meant that the stripe api only allows the metadata to be specified in the product_data.

#

I just double-checked that again - not that I have defined the metadata at the wrong place

strange badge
#

Ack

peak dagger
#

sry for the confusion ^^

strange badge
#

That's okay

#

I have reached out to my colleagues to further investigate this

peak dagger
#

ok

#

Do I just wait here?

strange badge
#

Yeah, I should have some idea of what is going on in a few minutes

peak dagger
#

๐Ÿ‘

strange badge
#

Okay I am seeing metadata on two of the three products in this checkout session

peak dagger
#

Yeah that is correct

strange badge
#

For pr_1P7KkKKBPpELGMIUIDog5hEx and pr_1P7Kd5KBPpELGMIUxOLyrudp

#

And when you attempt to retrieve them you do not see this?

peak dagger
#

exactly

strange badge
#

Do you get the full Product object returned or just an ID?

peak dagger
#

At least they are not in the line_items array of the expanded checkout session object

#

the full object

strange badge
#

Can you expand the product property there?

peak dagger
#

I have this for retrieving the session:

expand: ["customer",
  "payment_intent",
  "line_items",
  "line_items.data.price.product",
  "invoice"
],
#

Do I need to add smth?

strange badge
#

No I meant in what you are sharing here

#

In the output it shows
product: [Object]

peak dagger
#

Ah yeah I tried at it was undefined...

#

But maybe I did smth wrong

#

I will do another test buy and print out the 3rd line_item

#

one sec

strange badge
#

Thanks!

peak dagger
#

๐Ÿคฆโ€โ™‚๏ธ

#

yup

#

it is all there

#

wow how did I oversee that... god damn

#
{
  id: 'prod_PxFBeduVsnxkyX',
  object: 'product',
  active: false,
  attributes: [],
  created: 1713545617,
  default_price: null,
  description: null,
  features: [],
  images: [],
  livemode: false,
  marketing_features: [],
  metadata: { id: 'option_materials', index: '1' }, // It is all here ^^
  name: '7colorPrint | alu_dibond',
  package_dimensions: null,
  shippable: null,
  statement_descriptor: null,
  tax_code: null,
  type: 'service',
  unit_label: null,
  updated: 1713545618,
  url: null
}
strange badge
#

There's a lot of nested stuff in those requests!

peak dagger
#

Yeah that is true

strange badge
#

Unless you write very specific logging to traverse all those layers, it could be easy to miss.

peak dagger
#

Do you know if there is a way to show more nested items in the VSCode console?

peak dagger
#

ok but thanks for your time ๐Ÿ™‚

#

And the help pointing me in the right direction

strange badge
#

Sure thing! Sometimes you just need to bounce ideas off someone to find what you missed.