I'm trying to associate name in metadata with payment session and then access in webhook handler. How would I do that?
My code:
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: <priceid>,
quantity: 1,
},
],
metadata: {
nick: `${req.params.nick}`,
},
mode: "payment",
success_url: `${process.env.DOMAIN}/success`,
cancel_url: `${process.env.DOMAIN}/bany`,
})
Webhook handler:
router.post(
"/webhook",
express.json({ type: "application/json" }),
(request, response) => {
const event = request.body
// Handle the event
switch (event.type) {
case "checkout.session.completed":
const data = <metadata from checkout session>
console.log(data)
break
default:
console.log(`Unhandled event type ${event.type}`)
}
response.json({ received: true })
}
)