#drprofsgtmrj
1 messages · Page 1 of 1 (latest)
Hello! You can listen for checkout.session.completed Events and update the items with the metadata you want at that point.
True. But one issue is that we no longer know which items are which to set
How do you tell them apart when you create the Checkout Session?
Also, they are just line items when returned. How do you even update these ?
I think I might be misunderstanding your quesiton. Can you give me a request ID showing the creation of one of these Checkout Sessions? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_WNDi1HC26U0WoD
This is just me playing around with creating one
Ideally I could just pass along the metadata with the unique identifier
Okay, so you've got three line items there. If you could specify metadata for those, what would it be?
Is there a mapping between the Product IDs you're using there and the IDs you want to specify?
No because you could have two of the same product ids
For instance, we could have two wizehire screening products with different price data.
The only way to distinguish between the two would be some unique identifier. And if we want to avoid storing stripe data in our db.. well
Why do you want to avoid storing Stripe data in your DB?
Anyway, what I would recommend is to set metadata on the Checkout Session itself, using the Product ID and the amount combined as the key and the value can be your UUID.
For example, you can set a key called prod_123-5000 which would be for the prod_123 line item that's $50, then set the value to your UUID.
It's not directly on the line items, but it's on the Checkout Session.
Because our db is the source of truth.
My question still is the same though. When you get the line items from the checkout session, how do you actually update them?
You don't. You would update the resulting line items on the resulting Subscription and/or Invoice.
I see . Ok so you get the subscription items, etc
The Checkout Session will generate a Subscription with the line items you specify. That will, in turn, generate an Invoice with line items. You can update all or some of those.
Yep.
But that subscription isn't stored within the checkout session upon completion
So you can listen to a checkout session completion but have no knowledge of the subscription it generated
Subscriptions and Invoices are separate objects, they aren't nested or contained within other objects, like Checkout Sessions. The Checkout Session does have a reference to the Subscription it creates though: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-subscription
So you can listen for checkout.session.completed Events and get the Subscription ID from them.
Oh. I might have missed that. OK
Yeah makes sense
Yeah rather than the Metadata being a uuid. Prob better to have it be generated
Like the product I'd plus price
Wait last question. Can you just create a subscription and pass it to the checkout session?
No.
Checkout Sessions create Subscriptions, they can't be used with existing Subscriptions.
👍