Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

packy's avatar
Level 7

Stripe - Confirm card payment

How do most people proceed with creating an order, or user after Stripe has confirmed a payment?? I have used Webhooks and just code like below:

 stripe.confirmCardPayment(clientSecret, {
                payment_method: {
                    card: card,
                    billing_details: {
                        email: "{{$email}}",
                        name: "{{$name}}"
                    },
                }
            })
            .then(function (result) {
                if (result.error) {
                    @this.card_error = result.error.message;
                } else {
                    Livewire.emit('paymentSucceeded', result.paymentIntent.id);
                }
            });

Where if there is no error I will call a livewire event to create an order/user through PHP right then and there. My only issue is what happens if after Stripe processes the payment for some reason (internet or just something) we never hit the stripe.confirmCardPayment function. Does this happen? I honestly trust webhooks a little more but also hate using them since they seem harder to test and are less versatile on what I can pass Stripe through meta data.

What are your thoughts? Over thinking this???

0 likes
3 replies
martinbean's avatar

@packy confirmCardPayment is what will make the actual charge. You should then be only creating an order and fulfilling any items after the PaymentIntent is completed. Stripe’s documentation does go over this:

Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.

1 like
packy's avatar
Level 7

Thanks for the info, I have used that webhook before. I guess my question is why cant I use the JS to just fulfill the order? In their docs it makes it seem that this a valid way to do it, and which I have done it this way, I am just curious if there is more odds something can break in the flow by not using a webhook

from Stripe on using custom payment flow

stripe
    .confirmCardPayment(clientSecret, {
      payment_method: {
        card: card
      }
    })
    .then(function(result) {
      if (result.error) {
        // Show error to your customer
        showError(result.error.message);
      } else {
        // The payment succeeded!
        orderComplete(result.paymentIntent.id);
      }
    });
martinbean's avatar

@packy Because of the reasons Stripe will list in the documentation.

Whilst on your page, a user could potentially close the browser in between the payment being completed and your orderComplete function firing and completing. In which case you will have charged someone’s card but not created the corresponding order.

1 like

Please or to participate in this conversation.