Next.js Discord

Discord Forum

Stripe CLI webhook can't update db inside case 'payment_intent.succeeded'

Unanswered
English Angora posted this in #help-forum
Open in Discord
English AngoraOP
Hello everyone,

A question regarding the implementation of Stripe. A trigger will be made to 'payment_intent.succeeded' but in this switch, I can't update the DB, while outside of this switch, I can.

Somebody else came up with this problem? Please let me know if you need any further information.

Thank you in advance.

Best regards.

Paddy

12 Replies

Red-crowned Parrot
Might need more info


I was thinking of having all Stripe events (that come from your account)
- get published to Kafka in upstash
- have lambda to update your db
- and any other businesses workflow
English AngoraOP
Hey @Red-crowned Parrot,

Thank you for your fast reply. I appreciate you.

I currently already have something, and it works outside the switch, case 'payment_intent.succeeded':. When I place the db create in the case it's not posting to the db anymore, outside of it, it does work.

Under here a code snippet so you understand what I mean and what is going on.
switch (body.type) {
      case 'payment_intent.succeeded':
        const paymentIntent = body.data.object;
        console.log(
          `PaymentIntent for ${paymentIntent.amount} was successful!`
        );
        // Then define and call a method to handle the successful payment intent.
        // handlePaymentIntentSucceeded(paymentIntent);

        break;
      case 'payment_method.attached':
        const paymentMethod = body.data.object;
        // Then define and call a method to handle the successful attachment of a PaymentMethod.
        // handlePaymentMethodAttached(paymentMethod);

        // Now this does NOT seem to work when its inside this case!
        await db.job.create({
          data: {
            title,
            category,
          },
        });

        break;
      default:
        // Unexpected event type
        console.log(`Unhandled event type ${body.type}.`);
    }

    // Now this does work!
    await db.job.create({
      data: {
        title,
        category,
      },
    });


I hope you understand what I mean, thank you so much.

Best regards.

Paddy
Polar bear
I'm sorry if I am misunderstanding your issue, but you want to call db.job.create() in the payment_intent.succeeded case?
It looks like you're currently calling it in the payment_method.attached case.
It also looks like the payment_intent.succeeded case only performs a console.log() before breaking out of the switch? Again, sorry if I'm reading this wrong.
English AngoraOP
Hi @Polar bear Thank you for your reply, sorry I have been flying for the past 24 hours, just checking this on the airport.
The example isn't very accurate it is actually in the payment_intent.succeeded, sorry for that, probably the lack of sleep that did this..😅
And before the break. It's just not working, but outside this 'switch' it is working.. Is it a correct way of using db.create() inside of the switch or is there a different way of doing this?
Thank you Steve, really appreciate your answer man.
I have been stuck on this for a while now.
I also made a checkout.session.completed as I hoped this would be the fix, but it isn't doing anything as well.
Would love to hear from you, @Polar bear !