#Logan-subs-metadata
1 messages · Page 1 of 1 (latest)
Hi there!
How are you setting metadata?
Are you setting it here: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata?
At the top level metadata parameter when you create your Checkout Sessions?
const session = await stripe.checkout.sessions.create({
mode: "subscription",
line_items: [
{
price: data.priceId,
// For metered billing, do not pass quantity
quantity: 1,
},
],
success_url: "http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "http://localhost:3000/canceled",
metadata: {
twid: data.userId,
},
});
Gotcha. So yeah. You want to instead set it here: https://stripe.com/docs/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.
That will carry the metadata down to the Subscription object
And it will then be in your customer.subscription.updated webhook
So I put it in line_items?
I am unsure how to place it into subscription_data.metadata
subscription_data: {
metadata: {
twid: data.userId,
},
},
?
Outside of line items. It would be its own hash.
if (data.userId) {
const session = await stripe.checkout.sessions.create({
mode: "subscription",
line_items: [
{
price: data.priceId,
// For metered billing, do not pass quantity
quantity: 1,
},
],
success_url: "http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "http://localhost:3000/canceled",
subscription_data: {
metadata: {
twid: data.userId,
},
},
});
res.send(session);
}
mode: "subscription",
line_items: [
{
price: data.priceId,
// For metered billing, do not pass quantity
quantity: 1,
},
],
success_url: "http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}",
cancel_url: "http://localhost:3000/canceled",
subscription_data: {
metadata: {
twid: data.userId,
},
},
});```