Md Jana Alam
Md Jana Alam

Reputation: 129

How to stop the redirecting after payment confirm on stripe?

I am trying to store the customer order at MongoDB once the user confirms payment. So how can i stop the redirecting in stripe after confirm payment?

Upvotes: 12

Views: 10060

Answers (2)

Awshaf Ishtiaque
Awshaf Ishtiaque

Reputation: 971

The if_required flag does not trigger automatic redirect to the return_url. Therefore you can handle your redirect logic by invoking the handleSuccess or handleError methods appropriately, as shown below:

try {
  const { error, paymentIntent } = await stripe.confirmPayment({
    elements,
    confirmParams: {
      return_url: "https://google.com",
    },
    redirect: "if_required",
  });
  
  if (error) {
    console.error(error);
    // handleError();
  } else if (paymentIntent && paymentIntent.status === "succeeded") {
    console.log("Payment succeeded");
    // handleSuccess();
  } else {
    console.log("Payment failed");
    // handleOther();
  }
  } catch (error) {
  console.error(error);
}

Upvotes: 23

Alex Scherbyna
Alex Scherbyna

Reputation: 143

You can use default param from documentation https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-redirect

confirmParams: {
    return_url: "https://example.com",
},
    redirect: 'if_required' 
});

Upvotes: 10

Related Questions