#jarek-checkout-lineitems

1 messages · Page 1 of 1 (latest)

dim oceanBOT
burnt fjord
#

What's the problem/what's not working exactly @twilit flicker ?

#

jarek-checkout-lineitems

twilit flicker
#

I'm just trying to pass metadata to each lineItem. From what I gather, I need to expadn the product data in order to get this metadata. I think I'm just going to create a new object with [{ productId: lineItemId, ...lineItem }] and pass the data that way. Not sure if it will work, but if I can't simply do lineItem.metadata = ... then that's what I'll do

#

in a stripe checkout session

burnt fjord
#

sorry this is still a bit confusing. Like for example why do you put the metadata on the Product instead of on the Price in that case?
And yes you can expand the Checkout Session's LineItem's Price

twilit flicker
#

Basically, how do I pass a productId to a lineItem in a checkout session?

#

This productId is our own data

burnt fjord
#

LineItems do not have any metadata so you can't. What you can do is create a custom Price object (which you do via price_data) and set metadata on it.

twilit flicker
#

I'm trying to do that here

price_data: {
currency: 'usd',
product_data: {
name: name,
},
unit_amount: priceInCents,
metadata: {
productId: item.id
}
},

quantity: item.quantity,
}

#

But its saying 500 Received unknown parameter: line_items[0][price_data][metadata]

burnt fjord
#

ah you're right, so strange. Then yeah put it on the Product, that's the only way

twilit flicker
#

Right, I've tried that, but it comes back as product
:
"prod_PAaIb7zOqIUg2Q", does that mean I need to expand the product?

#

Heres my function

const stripeResponse = await StripeClient.checkout.sessions.retrieve(
event.data.object.id,
{ expand: ['line_items'] },
{ stripeAccount: event.account }
);

#

Does it need to be

const stripeResponse = await StripeClient.checkout.sessions.retrieve(
event.data.object.id,
{ expand: ['line_items.product'] },
{ stripeAccount: event.account }
);

theres not much documentation on expanding

burnt fjord
#

does that mean I need to expand the product?
yes

#

you need to do expand: ['line_items.data.price.product']

twilit flicker
#

Ok, I can work with this, thank you!