#erztemplerobba_webhooks
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. Thank you for your patience!
โฑ๏ธ We automatically close idle threads, which makes them read-only. Make sure you stick around to chat in realtime! If this thread is closed and you have another question you'll need to start a new thread.
๐ 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/1213008818431197194
๐ Have more to share? You can add more detail below, including code, screenshots, videos, etc.
hello! i'm sorry but i don't understand the question, maybe can you share more on what you're trying to achieve or the problem you're encountering in more detail?
Hi. Maybe it's a weird question, sorry for that.
I have one server endpoint `stripe-payment' that take care of normal, single payments:
router.post('/create-checkout-session', express.json(), async (req, res) => {
[...]
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
mode: 'payment',
metadata: orderInformation,
line_items: formattedCart.map(item => {
return {
price_data: {
currency: 'KRW',
product_data: {
name: item.name
},
unit_amount: item.price
},
quantity: item.quantity
}
}),
success_url: `${clientUrl}/success`
cancel_url: `${clientUrl}/error`
})
res.json({ url: session.url })
} catch (error) {
console.log(error.message)
res.status(500).json({ error: error.message })
return
Payments that hit this endpoint are caught by my stripe webhook /stripe-webhook
router.post('/', express.raw({ type: 'application/json' }), async (request, response) => {
const sig = request.headers['stripe-signature']
let event = null;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
} catch (err) {
console.log(err.message)
response.status(400).end()
return
}
console.log(event)
return
if (event.type === 'checkout.session.completed') {
[...]
This works just fine. Now I also want to add another subscription based payment flow:
router.post('/create-subscription-session', express.json(), async (req, res) => {
[...]
try {
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
line_items: [
{
price: priceId,
quantity: 1,
},
],
[...]
I want tthis to be handled by a different webhook because it requires different server logic.
So my question is how can I make this const session = await stripe.checkout.sessions.create({ mode: 'subscription',
session only trigger my subscription webhook and not the normal one?
aaaah, okay i think i get what you're trying to do now
Kinda new with this, sorry if this a weird question/way to do it ๐
what webhook event types are you processing or listening for specifically?
only checkout.session.completed?
For my normal payments only checkout.session.completed, yes.
For subscription based payment there seems to be a overlap of event types so my thought was that both webhooks are triggered.
When I stage a subscription payment, checkout.session.completed' is also triggered
so there's no way to separate the checkout.session.completed for subscriptions and payments, they will both be sent to a single webhook endpoint url. Your webhook endpoint will have to process them differently based off the mode
Ah, I see. So it's not normal to have several webhooks but instead one webhook that goes something like this:
router.post('/', express.raw({ type: 'application/json' }), async (request, response) => {
if (mode === 'subscription') {
subscription logic
}
if (mode === 'payment') {
payment logic
}
?
yep, that's correct