#CameronBryce

1 messages ยท Page 1 of 1 (latest)

tepid scrollBOT
dapper herald
#

Hello ๐Ÿ˜„

stray seal
#

When you say " the metadata doesn't upload" what do you mean? Do you have the code you're using to set metadata?

dapper herald
#
  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);
  },
stray seal
#

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

dapper herald
#

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!

stray seal