Questions & Answers

Stripe: Callback when payment is done

I use this to accept stipe payments:

this.stripe = await loadStripe(test_key);
const originWebsite = document.location.origin;
const {error} = await this.stripe!.redirectToCheckout({
  lineItems: [{
    price: priceid_test,
    quantity: 1,
  mode: 'payment',
  successUrl: originWebsite+'/settings/premium_success',
  cancelUrl: originWebsite+'/settings/premium'

This work fine. But: I do not want to use webhooks or any other server side / back end code. What I need is a simple callback method that tells me if the purchase was successful or not. Something like:

paymentDone: myFunction(paymentInfo)

And in myFunction I will handle the payment if successful. I know that webhooks are the strongly recommended way and this client side approach has security issues.

Still, this is the way I want to go for now. I have been searching the web for hours but I cannot find how to do it. How can I do this?

2023-01-20 13:42:03
As far as I know this is not possible using their checkout portal. Users are redirected to your successUrl after they complete the payment, but this is not at all telling the a payment has been done, as it's a simple redirect to a page meant to show a confirmation message to the user. You should really use webhooks (or write your own checkout page which I highly discourage).
Answers(0) :