#CameronBryce
1 messages ยท Page 1 of 1 (latest)
Hello ๐
When you say " the metadata doesn't upload" what do you mean? Do you have the code you're using to set metadata?
async execute(interaction) {
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
line_items: [{ price: '...', quantity: 1 }],
metadata: { userIdentification: interaction.member.id },
mode: 'subscription',
});
console.log(interaction.member.id, interaction.guild.id);
console.log(session);
},
So, this is a Discord bot, written with Node.js. I'm unsure what I might be doing wrong. I'm trying to upload the userIdentification and set it in the metadata. Where I can access it later with this code below. Though, the code works and the payment is successful, when searching through the stripe.subscriptions.list() - The metadata shows as empty.
async execute(interaction) {
const subscriptions = await stripe.subscriptions.list();
console.log(subscriptions.data);
},
That's because you're setting the metadata on the Checkout Session object. If you want to set it on the Subscription object, then you'll want to use the Checkout Sessions subscriptions_data.metadata attributel 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.
I figured it might be easier if I showed both my files, the top codeblock works and in the console.log(session) there's a unique link, where a user can pay from. Though, it doesn't seem to post the metadata unless I'm doing it wrong
Ohh okay, let me look at that!
async execute(interaction) {
const session = await stripe.checkout.sessions.create({
success_url: 'https://example.com/success',
line_items: [{ price: '...', quantity: 1 }],
subscription_data: {
'metadata': { userIdentification: interaction.member.id },
},
mode: 'subscription',
});
console.log(interaction.member.id, interaction.guild.id);
console.log(session);
},
So, I did as you said (believe, anyway) - I checked and the metadata uploaded correctly. Would there be a better way to do this or is this just fine? And thank you so much!
yup! That looks like it worked. This is the best way to set metadata when you create the Checkout Session, but you can add it directly to the Subscription via a Subscription Update call at any point:https://stripe.com/docs/api/subscriptions/update#update_subscription-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.