javascript - How to access items metadata in Stripe checkout session - Stack Overflow

When I create a Checkout session, I am creating prices on the fly with price_data and product_data prop

When I create a Checkout session, I am creating prices on the fly with price_data and product_data properties. For each item, I am putting metadata in the product_data.metadata property.

After payment is successfully finished, I fetch the session data in order to display Payment Successful page to the customer. But for some reason, metadata of the items are empty. Metadata of the items are present when I check it in the Dashboard, but they are empty when I fetch it with API.

I tried to fetch whole session data with expanded line_items property:

const session = await stripe.checkout.sessions.retrieve(session_id, { expand: ['line_items'] });

And I also tried to fetch the items directly:

const line_items = await stripe.checkout.sessions.listLineItems(session_id);

In both scenarios, metadata of each item is empty.

When I create a Checkout session, I am creating prices on the fly with price_data and product_data properties. For each item, I am putting metadata in the product_data.metadata property.

After payment is successfully finished, I fetch the session data in order to display Payment Successful page to the customer. But for some reason, metadata of the items are empty. Metadata of the items are present when I check it in the Dashboard, but they are empty when I fetch it with API.

I tried to fetch whole session data with expanded line_items property:

const session = await stripe.checkout.sessions.retrieve(session_id, { expand: ['line_items'] });

And I also tried to fetch the items directly:

const line_items = await stripe.checkout.sessions.listLineItems(session_id);

In both scenarios, metadata of each item is empty.

Share Improve this question asked Mar 4, 2022 at 13:29 NeNaDNeNaD 20.5k11 gold badges61 silver badges112 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

When creating the items on the fly, metadata ends up in the product property, and not in the price property.

So I solved the issue with expanding the items with product data:

const line_items = await stripe.checkout.sessions.listLineItems(session_id, {
  expand: ['data.price.product'],
});

The response have the metadata inside product property.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743706238a4493414.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信