#teevee_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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.
Are you listening for checkout.session.completed in your Webhook handler here?
Or a different Event type?
payment_intent.processing, payment_intent.succeeded payment_intent.failed
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
The payload is coming from payment_intent.succeeded without the metadata userID
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok I am looking at the doc. Can you give an example block of code? im sorry i dont see it in the doc
It would just be:
payment_intent_data: {
metadata: {
userId: userId,
},
}```
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,
},
}
});
Yep, feel free to test it out