#mulo_webhooks

1 messages ยท Page 1 of 1 (latest)

velvet rockBOT
#

๐Ÿ‘‹ 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.

crimson glade
#

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
....
turbid patrol
#

Hi! How are you doing your one time payents?

crimson glade
#

u mean how do i create the sessions?

turbid patrol
#

Oh duh

#

In terms of event order, there's no guarantee, but actually what you've got there should work fine for what you're describing.

crimson glade
#

so you are saying that for both

  • subscriptions (whether it's first payment and subsequent ones)
  • one-time payments
    they'd fall both into invoice.paid event.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?

turbid patrol
crimson glade
#

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?

turbid patrol
#

I believe so, yes - but worth testing. ๐Ÿ™‚

velvet rockBOT
crimson glade
#

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?

turbid patrol
#

One-off payments only use Invoices if you tell them to, ya.

crimson glade
#

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?

high sierra
#

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.

turbid patrol