#Logan-subs-metadata

1 messages · Page 1 of 1 (latest)

reef cliff
#

Hi there!

#

How are you setting metadata?

#

At the top level metadata parameter when you create your Checkout Sessions?

slender sky
#
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,
      },
    });
reef cliff
#

That will carry the metadata down to the Subscription object

#

And it will then be in your customer.subscription.updated webhook

slender sky
#

So I put it in line_items?

#

I am unsure how to place it into subscription_data.metadata

#
      subscription_data: {
        metadata: {
          twid: data.userId,
        },
      },
#

?

reef cliff
#

Outside of line items. It would be its own hash.

slender sky
#
  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);
  }
reef cliff
#
      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,
        },
      },
    });```
slender sky
#

Yay

#

Thank you much, you're a coding god

#

Solved