#.abishek
1 messages · Page 1 of 1 (latest)
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.
Hello
Hi
You can set metadata on a Price and then use that Price in a line_item if that is what you are asking
You may just need to tell me what you are actually trying to do though to find the best solution
so, we have a cart functionality on our app and we wanted to associate our cart item id with the line item id on the checkout session, so when we process the webhook checkout.session.completed we can get additional cart item information for the line item we are trying to process
does it make sense?
Sure
So you either attach the metadata directly to the Price as I noted above
Or you could add metadata directly to the Checkout Session, or even the PaymentIntent (via payment_intent_data.metadata: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i am already storing the cart id on the session's metadata property, just trying to figure out a way to associate each item on the cart to each line item on the session
btw, I am using the price_data for each line_item
Yeah you can't set metadata on the line item if you are using price_data
So you would have to create the Price ahead of the Checkout Session if you want this
ya, I cannot use the price because our cart functionality uses a coupon functionality, so the price per item is different based on the coupon applied, which is why we use the price_data. With price, we cannot customize the amount
since we support mulitple payment providers, we have the coupon functionality on our cart
You can still do this -- you would just create the necessary Price and then create the Checkout Session
The only difference is two API requests instead of one
so that would basically create unnecessary data in the Stripe Product Catalog if we do that
every checkout, if there are like 5 items added and in a day there are 100 orders, that would create 500 items in the Stripe Product Catalog
but even if I use the price how would I set the metadata?
You have lots of Prices in your catalogue anyway if you are using price_data, they are just archived immediately.
Regardless, I'd recommend just setting this metadata on the PaymentIntent instead
Don't use the line_items here at all
ok, may need more info. We were planning to use the Stripe Checkout, so how would that work with PaymentIntent?
Checkout Sessions create PaymentIntents
So you can have the metadata carried down to the PaymentIntent itself by setting payment_intent_data.metadata when you create the Checkout Session.
but payment_intent on the session would be null if the mode is SUBSCRIPTION right?
so, the cart items can be a mix of both subscription and one-off items
if there is atleast one subscription item on the cart, then the mode of the checkout is set to SUBSCRIPTION else PAYMENT
Okay then you would use subscription_data.metadata (https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata) in that case -- same idea.
lol, but that still doesn't solve my problem. Not sure I am explaining it correctly.
our app's cart_id is mapped to checkout_session.metadata['id]
each item on the cart has a id, and each item can either be a one-off item or a recurring.
as mentioned above, if atleast one item is a recurring item, the session.mode is set to SUBSCRIPTION.
based on what you are saying, I can use the subscription_data, how do I associate each line item on the cart with each lineitem on the checkout session using the subscription_data.metadata or payment_intent_data.metadata ? I feel like I am missing something? because when I am processing these line_items on the checkout.session.completed I would like to know the associated cart_item_id. It would have been great if there was a metadata on the line item
You would need to set this metadata yourself -- you would currate it based on whatever you are inputting in line_items.
because when I am processing these line_items on the checkout.session.completed I would like to know the associated cart_item_id.
In this case you would need to look at more than just theline_itemsif you want to view that metadata
You would look at the actual metadata you set on the PaymentIntent or Subscription
Or, you can just add more key/value pairs to the actual Checkout Session metadata
It is completely up to you
But what you can't do right now is set metadata when using price_data when creating line_items
ok
The API simply doesn't support that (I can put in a feature request for that)
ya, that would be great though
I understand, happy to submit a feature request and hopefully it is built in the future.
But simply not possible right now
ok, do the line_items atleast maintain index as they are when they are created?
Yes they will be in the same order every time you retrieve the Session