#yony
1 messages ยท Page 1 of 1 (latest)
Does the user ID here refer to Stripe customer ID or your own defined user ID?
Our own defined user id
Am I right to understand that you would like to store your own defined user ID in the Checkout Session that you will be able to retrieve it when receiving checkout.session.completed event?
Yes, correct.
when receiving checkout.session.completed event, we want to store the subscription id for our own define user ID in the database.
In this case, you can set the user ID in metadata when creating a Checkout Session and the information will be present under metadata field in checkout.session.completed event: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-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.
Ok, so i can add a custom field in the metadata like the following?
const session = await stripe.checkout.sessions.create({ success_url: 'https://example.com/success', line_items: [ {price: 'price_H5ggYwtDq4fbrJ', quantity: 2}, ], mode: 'payment', user_id: '126373889494' });
Nope. You should set your user_id kay-value pair in metadata field. For example,
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
line_items: [
{price: 'price_xxx', quantity: 2},
],
mode: 'payment',
metadata: {
user_id: 'user_123',
},
});
Ok checking
Ok great, I was able to get the user_id in the checkout session. Thanks very much @swift drum for your help.
No problem! Happy to help ๐
Just one last question, how to get the custom user_id metadata from the checkout.session.completed webhoook event?
is this going to be something like
event.data.object.metadata.user_id?
It looks right to me
Ok great, thanks @swift drum