#sz

1 messages · Page 1 of 1 (latest)

unkempt adderBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

  • sz, 18 hours ago, 76 messages
lament pendant
#

Hi there, did you set the metadata on the checkout session or on the product object?

limber cobalt
#

On the product object

lament pendant
#

And did you expand product in your webhook handling?

limber cobalt
#

I don't think I did that. What I did instead was fetch the line items associated to the checkout.session.complete

This is the code associated

    const lineItems = await stripe.checkout.sessions.listLineItems(
      event.data.object.id, 
      { stripeAccount: event.account }
    )
#

console logging the lineItems would return the following

{
  "object": "list",
  "data": [
    {
      "id": "li_1ObcqPJVArmNjTxQFlFxHMNY",
      "object": "item",
      "amount_discount": 0,
      "amount_subtotal": 3000,
      "amount_tax": 0,
      "amount_total": 3000,
      "currency": "usd",
      "description": "50 Credits",
      "price": {
        "id": "price_1ObbysJVArmNjTxQg3DcXQhG",
        "object": "price",
        "active": true,
        "billing_scheme": "per_unit",
        "created": 1705985582,
        "currency": "usd",
        "custom_unit_amount": null,
        "livemode": false,
        "lookup_key": null,
        "metadata": {},
        "nickname": null,
        "product": "prod_PQSuNBqNZhnc0s",
        "recurring": null,
        "tax_behavior": "unspecified",
        "tiers_mode": null,
        "transform_quantity": null,
        "type": "one_time",
        "unit_amount": 1500,
        "unit_amount_decimal": "1500"
      },
      "quantity": 2
    }
  ],
  "has_more": false,
  "url": "/v1/checkout/sessions/cs_test_a1rqSqoNxlUik6YjcAgAkfULQpFgYK43vrm9bJ7R3jWGBL6hSVKwDsJiVr/line_items"
}
lament pendant
#

You need to expand product if you want to get its metadata

limber cobalt
#

I see. I have another question then. When a product is created via the API, will a new price also be created as well?

#

And will it always have a 1 to 1 mapping from the newly created product to the price?

lament pendant
#

No, you need to create a price seperately

limber cobalt
#

Just to make sure I'm understanding this correctly.

If a product is created through the stripe.products.create method

Then a subsequent call to stripe.price.create would need to be made with the previous product id in order to link it?

#

For more context, I'm building out a stripe app that allows for merchants to implement credit based usage for their platform (ie: user spends 5 credits in order to generate AI icon and would need to top up on credits to generate more icons)

#

I'm planning on using the metadata to determine how many credits will be awarded to the user based on the product they purchase.

#

Right now, I'm debating whether it would be more appropriate to store the metadata of the credits in the product or in the price

lament pendant
#

That's entirely up to you

limber cobalt
#

hmmm Let me reframe this.

Is the only way to fetch the product metadata from a checkout.session.complete event is through the following steps:

  1. call stripe.checkout.session.listLineItems
  2. map over lineItems and call stripe.products.retrieve
  3. extract product metadata from products
lament pendant
#

There's a quicker way, you can just call checkout session retrieval API and expand line_items.data.price.product

limber cobalt
#

I'll give that a try

#

that was perfect