#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/1349057695868780676
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Im bit confused as I have reoccurring subscriptions and one time payments
for either of those do I first recieve the event "checkout.session.completed"?
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
}
// this handles one time purchases
...
if (event.type === 'invoice.paid') {
// this handles subscriptions
....
Hi! How are you doing your one time payents?
u mean how do i create the sessions?
Oh duh
Ideally you want to listen to `invoice.*' events for Subscriptions so you can enable/disable things; If you use https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-invoice_creation you would also get an invoice created for a one-off Checkout session, which would mean you could use the same events.
In terms of event order, there's no guarantee, but actually what you've got there should work fine for what you're describing.
so you are saying that for both
- subscriptions (whether it's first payment and subsequent ones)
- one-time payments
they'd fall both intoinvoice.paidevent.type?
meaning i can just return 200 on anything that is not invoice.paid
meaning also. "checkout.session.completed" is not final proof that payment has been processed, while invoice.paid actually is?
One time payments ONLY if you enable Invoice creation as part of the Checkout creation.
When someone pays you, it creates a checkout.session.completed event. Set up an endpoint on your server to accept, process, and confirm receipt of these events.
https://docs.stripe.com/checkout/fulfillment?payment-ui=stripe-hosted#create-payment-event-handler
So both work.
Your original approach is totally reasonable.
for subs I use
const session = await stripe.checkout.sessions.create({
success_url: `https:...`,
cancel_url: `https:...`,
payment_method_types: ['card'],
line_items: [ { price: officialSubId, quantity: 1, },],
mode: 'subscription',
subscription_data: {
metadata: {
custom: `${discordUserId}@${guildId}` //${guildId}
}
}
});
and for one-off payments
const session = await stripe.checkout.sessions.create({
success_url: `https://...s`,
cancel_url: `https://...`,
payment_method_types: ['card', 'paypal'],
line_items: [{ price: selectedItem, quantity: 1 }],
mode: 'payment', // Change to 'payment' for one-time purchases
metadata: {
custom_id: `${discordUserId}@${guildId}@${amount}`, // Add your custom identifier here
},
});
so you mean on the latter I just add
invoice_creation: {
enabled: true
}
const session = await stripe.checkout.sessions.create({
success_url: `https://...s`,
cancel_url: `https://...`,
payment_method_types: ['card', 'paypal'],
line_items: [{ price: selectedItem, quantity: 1 }],
mode: 'payment', // Change to 'payment' for one-time purchases
metadata: {
custom_id: `${discordUserId}@${guildId}@${amount}`, // Add your custom identifier here
},
invoice_creation: {
enabled: true
}
});
and then both subs and one off payments will fall under invoice.paid?
I believe so, yes - but worth testing. ๐
so basically on subscriptions the invoice.paid event is automatic by default,
but for one-off payments it has to be enabled in the session create object?
One-off payments only use Invoices if you tell them to, ya.
but so as i had it previously, w/o the invoice for one-off payments, the "checkout.session.completed" is not proof of purhcase being actually made?
fyi i'm taking over for timebox, caching up now. the discord is a little busy so it might take me a bit to respond.
checkout.session.completed IS proof of purchase being made:
When someone pays you, it creates a checkout.session.completed event. Set up an endpoint on your server to accept, process, and confirm receipt of these events.
https://docs.stripe.com/checkout/fulfillment?payment-ui=stripe-hosted#create-payment-event-handler