Search code examples
javascriptangularjsionic-frameworkstripe-paymentspayment-processing

stripe checkout form and server validation


I´m a Stripe beginner and I integrated the (really nice) Stripe checkout form into my Ionic App. Everything is working, the fields get validated and the I get the token and data in the callback.

I have more of an general question:

When everything is validated and the credit card token is generated, the button changes to green and the form closes. But that does not mean that the payment was successful.

Depending on a one-time or recurring payment, I need to send the data to my server, create a customer/charge/plan/subscription and there something can go wrong.

But in the end the user thinks everything is fine. I saw that other people are sending mails if something goes wrong.

What`s the best way to handle such an error?


Solution

  • I got this answer from the Stripe support:

    tl;dr

    We have to add our own server validation or send an email to the user. I will implement a spinner after the checkout and if the server says OK then redirect the user. Also sending a mail is an option.

    Hey there,

    Thanks for reaching out to us, I'm happy to help you with this!

    When you create a one-time charge or a subscription with Stripe in your backend, the payment is attempted synchronously, so you could simply create code to handle exceptions in your backend and inform the user that their charge failed. You could use this code to send an email or simply display an error message on the resulting page.

    There's an outline of this in our API docs here. https://stripe.com/docs/api#errors

    You can also use webhooks to inform your application of certain events (such as failed or successful payments) and trigger actions such as sending emails. More on this here:

    https://stripe.com/docs/webhooks https://stripe.com/docs/api#event_types https://github.com/boucher/stripe-webhook-mailer

    Stripe does not receive any information from you if the token is created but not processed on your backend, so in this case I'd offer a customer support email and if a customer writes in, ask them to enter their card details again through your app and make any adjustments to your integration to ensure you are charging the token after creation.

    I hope this helps and please let me know if you have any other questions!

    All the best