#worth12_api
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1357588035931209949
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello! I’m not entirely clear on the issue you’re experiencing. Could you please clarify what you mean by, 'I tried passing it as metadata in the checkout session, but I can’t find a way to use that on my server side with the customer object'?
Absolutely, I am trying to pass the userId (id of a user in my database) to the checkout, and have it accessable within the Customer object. This is so I can have that userId when handling the customer.create webhook.
okay, firstly, how did you try to pass the userId to the Checkout session?
Here is my api:
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: PRICE_ID,
quantity: 1,
},
],
mode: "subscription",
return_url: ${YOUR_DOMAIN}/return?session_id={CHECKOUT_SESSION_ID},
ui_mode: "custom",
metadata: {
"userId": userId,
},
client_reference_id: userId,
});
Based on the code snippet you shared, it looks like Stripe is automatically creating a Customer for you. You'd like this automatically created Customer to include the metadata you've passed in, correct?
yes, exactly!
sorry for the kind of poor problem explanation
What you'll need to do is make a subsequent request to update the automatically created Customer with the metadata. Unfortunately, there’s no way for the automatically created Customer to include the metadata you provided via the Checkout Session by default.
On a side note, I'll suggest also passing the metadata into subscription_data.metadata (for mode="subscription"). This way, the Subscription will contain that metadata, and so will the Invoice Line Items. https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_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.
Okay, sounds good. Thank you!