#mulo_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.
โฑ๏ธ 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/1295332020268044331
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! well yes if you're using Checkout to start the subscription there's an event for that CheckoutSession completing.
how can I differenciate the two?
I'd like only to get when a subscirption is paid, and only when a one-off is paid
makes sense but that's not really how it works. You'd just write some code that inspects the actual details of the CheckoutSession while handling checkout.session.completed, determines if it's telling you a Subscription has just been created or if it's a one-time payment, and take whatever appropriate action on your server
so both one-off and subs fall under checkout.session.completed ?
if you're using Checkout to start the subscription (mode:"subscription")there's an event for that CheckoutSession completing. if you use Checkout for a one-time payment, there's an event for that CheckoutSession completing
something like:
if (event.type === "checkout.session.completed") {
if (event.type === 'invoice.paid') {
//this is monthly sub?
} else {
// one off?
}
}
oh ye right, meant logic-wise
https://docs.stripe.com/checkout/fulfillment
that shows how you can get the checkoutSession object
and then as I mentioned earlier, you can check fields of that object (like mode or the details of what's in the line_items) to see what has been bought and react accordingly
so i can remove invoice.paid, and just use checkout.session.completed
which both one-off and monthly sub fall under?
well it depends. You should still listen to invoice.paid so you can handle the recurring payments.
but how's that those get also logged in checkout.session.completed
I just move the checkout.session.completed below invoice.paid?
no the order is not important at all. Sorry I don't think you're getting this
you create a CheckoutSession, in mode:subscription. The events you get are like :
- checkout.session.completed โ when the customer fills in Checkout and starts their subscription
- invoice.paid โ at the same time; it's the event for the first invoice of this subscription
- invoice.paid โ a month later; it's the event for a recurring payment on the created subscription
- invoice.paid โ a month later; it's the event for a recurring payment on the created subscription
- ...
each of those is a distinct event that hits your endpoint and triggers your code separately
checkout.session.completed โ when the customer fills in Checkout and starts their subscription
This triggers for both one-off payments and recurring payments?
if you're using Checkout to start the subscription (mode:"subscription")there's an event for that CheckoutSession completing. if you use Checkout for a one-time payment, there's an event for that CheckoutSession completing
this is to create one-off payments
const session = await stripe.checkout.sessions.create({
success_url: url,
cancel_url: url,
payment_method_types: ['card'],
line_items: [{ price: selectedItem, quantity: 1 }],
mode: 'payment',
metadata: { custom_id:`${discordUserId}@${guildId}@${amount}`,},
});
return session.url
this for monthly sub
const session = await stripe.checkout.sessions.create({
success_url: url,
cancel_url: url,
payment_method_types: ['card'],
line_items: [{ price: officialSubId, quantity: 1, },],
mode: 'subscription',
subscription_data: { metadata: { custom: `${discordUserId}@${guildId}` } }
});
yes so they both use Checkout, they both generate a checkout.session.completed event. Your code needs to inspect the CheckoutSession when handling that event, determine if it's telling you a Subscription has just been created or if it's a one-time payment, and take whatever appropriate action on your server
Ok, so i see the mode I can directly check in the event. Tho in my case for subs:
- when a sub is first created I do get both
checkout.session.completedandinvoice.paid? - then onward I just get
invoice.paid
for one-off payments I just get checkout.session.completed?
yes
If so, is there another endpoint i can listen to for when one-off payements are are finalized instead of listening to checkout.session.completed?
the recommended event is checkout.session.completed and the recommended integration is to check the details in your code when handling it, as described above
ye but as you said if I just listen to checkout.session.completed then I wouldnt get the recurring payments of monthly subs? or am I mistaken
Hey! Taking over for my colleague.
Yes you need to fetch the correspnding details from that event using your code and Stripe APIs.
ok so would this be a workaround:
if (event.type === "checkout.session.completed") {
if (event.data.object.mode === 'subscription') {
// skips event for subs, will get handled by 'invoice.paid' instead
response.status(200).end();
return
}
// processing one-off payments instead here
return
}
if (event.type === 'invoice.paid') {
//processing monthly subs
// this is never triggered by on one-off payments, it's the first cycle of monthly sub and all subsequent ones
}
Yes that should work I think...
can you just confirm
if (event.type === 'invoice.paid') {
// this is never triggered by on one-off payments, it's the first cycle of monthly sub and all subsequent ones
}
Yes, if you don't use Invoice for one-time payments
thanks folks!