#jdesignv2_checkout-product-metadata
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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
Hi ๐
Are you just receiving the Checkout Session object in the checkout.session.completed event?
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
Right because only yhe checkout session will have that info
ok good
However, line_items are not returned expanded by default
You can tell this because our API reference doc has the word Expandable next to the property: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-line_items
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;
Okay so you are retrieving them too?
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
}
]
Okay I can see the metadata you are sending in this request: https://dashboard.stripe.com/test/logs/req_N758UUDEOrx9Wh
exactly
This is from the request before that but shows the same issue
The metadata object is just empty
And it looks like the metadata is set on the product_data
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...
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?
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
Ack
sry for the confusion ^^
Yeah, I should have some idea of what is going on in a few minutes
๐
Okay I am seeing metadata on two of the three products in this checkout session
Yeah that is correct
For pr_1P7KkKKBPpELGMIUIDog5hEx and pr_1P7Kd5KBPpELGMIUxOLyrudp
And when you attempt to retrieve them you do not see this?
exactly
Do you get the full Product object returned or just an ID?
At least they are not in the line_items array of the expanded checkout session object
the full object
this f.ex.
Can you expand the product property there?
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?
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
Thanks!
๐คฆโโ๏ธ
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
}
There's a lot of nested stuff in those requests!
Yeah that is true
Unless you write very specific logging to traverse all those layers, it could be easy to miss.
Do you know if there is a way to show more nested items in the VSCode console?
Ok so there seems to be no easier way hahaha
ok but thanks for your time ๐
And the help pointing me in the right direction
Sure thing! Sometimes you just need to bounce ideas off someone to find what you missed.