我尝试在用户确认付款后将客户订单存储在 MongoDB 中。那么确认付款后如何停止stripe中的重定向呢?
if_required
标志不会触发自动重定向到return_url
。因此,您可以通过适当调用 handleSuccess
或 handleError
方法来处理重定向逻辑,如下所示:
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);
}
您可以使用文档中的默认参数https://stripe.com/docs/js/ payment_intents/confirm_ payment#confirm_ payment_intent-options-redirect
confirmParams: {
return_url: "https://example.com",
},
redirect: 'if_required'
});