#teevee_code

1 messages ยท Page 1 of 1 (latest)

vale groveBOT
#

๐Ÿ‘‹ 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/1268299053691834450

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

solar wedge
#

Hello

#

Where are you setting metadata exactly?

tepid lodge
#

router.post('/create-checkout-session', async (req, res) => {
try {
// Simplified userId retrieval
const userId = req.session.user._id;
console.log('User ID from session:', userId);

// Simplified Stripe customer ID retrieval
const stripeCustomerId = req.session.user.stripeCustomerId;
console.log('Stripe Customer ID from session:', stripeCustomerId);

// Create Stripe checkout session
const session = await stripe.checkout.sessions.create({
  payment_method_types: ['card'],
  customer: stripeCustomerId,
  mode: 'payment',
  line_items: [
    {
      price: 'price_1P63ydKqO403i8Jlzq7Z7rYa',
      quantity: 1,
    },
  ],
  success_url: `${process.env.SUCCESS_DOMAIN}?session_id={CHECKOUT_SESSION_ID}`,
  metadata: {
    userId: userId,
  },
});

res.json({ id: session.id });

} catch (error) {
console.error('Error creating Stripe Checkout session:', error);
res.status(500).json({ error: 'Failed to create Stripe Checkout session' });
}
});

#

Sorry not sure why it didnt post the whole endpoint the first time.

solar wedge
#

Are you listening for checkout.session.completed in your Webhook handler here?

#

Or a different Event type?

tepid lodge
#

payment_intent.processing, payment_intent.succeeded payment_intent.failed

solar wedge
#

Gotcha, in that case you want to set the metadata via the payment_intent_data.metadata param instead of top-level here

#

That will carry it down to the PaymentIntent object

tepid lodge
#

The payload is coming from payment_intent.succeeded without the metadata userID

solar wedge
tepid lodge
#

Ok I am looking at the doc. Can you give an example block of code? im sorry i dont see it in the doc

solar wedge
#

It would just be:

payment_intent_data: {
  metadata: {
          userId: userId,
        },
}```
tepid lodge
#

Like this?

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
customer: stripeCustomerId,
mode: 'payment',
line_items: [
{
price: 'price_1P63ydKqO403i8Jlzq7Z7rYa',
quantity: 1,
},
],
success_url: ${process.env.SUCCESS_DOMAIN}?session_id={CHECKOUT_SESSION_ID},
payment_intent_data: {
metadata: {
userId: userId,
},
}

});
solar wedge
#

Yep, feel free to test it out

tepid lodge
#

Thank you so much.

#

It works, you guys are the best. Thanks again. This was huge huge help. Had me stumped for hours. ๐Ÿ˜ฉ