admin管理员组文章数量:1122832
I am using Stripe Elements for payment processing and React and have a specific workflow where I first create a pending order in the database before triggering stripe.confirmPayment
. Here's a simplified version of my code:
// --> Validate first Stripe embedded form
const order = await createOrder(values);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: `URL`,
},
});
if (error) {
// Show error
setIsLoading(false);
return;
}
The issue I want to address is validating the card details in the Stripe Elements form before calling stripe.confirmPayment
. This is important to avoid creating unnecessary pending orders in the database when the card validation fails.
Solution:
// Trigger form validation and wallet collection
const {error: submitError} = await elements.submit();
if (submitError) {
toast({
title: "Payment failed",
description: submitError?.message,
variant: "destructive",
});
setIsLoading(false);
return;
}
I am using Stripe Elements for payment processing and React and have a specific workflow where I first create a pending order in the database before triggering stripe.confirmPayment
. Here's a simplified version of my code:
// --> Validate first Stripe embedded form
const order = await createOrder(values);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: `URL`,
},
});
if (error) {
// Show error
setIsLoading(false);
return;
}
The issue I want to address is validating the card details in the Stripe Elements form before calling stripe.confirmPayment
. This is important to avoid creating unnecessary pending orders in the database when the card validation fails.
Solution:
// Trigger form validation and wallet collection
const {error: submitError} = await elements.submit();
if (submitError) {
toast({
title: "Payment failed",
description: submitError?.message,
variant: "destructive",
});
setIsLoading(false);
return;
}
Share
Improve this question
edited Nov 22, 2024 at 16:16
hantoren
asked Nov 22, 2024 at 13:29
hantorenhantoren
1,1854 gold badges24 silver badges45 bronze badges
1 Answer
Reset to default 1You can actually leverage https://docs.stripe.com/payments/accept-a-payment-deferred to start by collecting/validating the PaymentMethod (using elements.submit
) and then create the order and the PaymentIntent at the same time and finally confirming the PI on the client side
本文标签: reactjsHow to validate Stripe Elements form before calling stripeconfirmPaymentStack Overflow
版权声明:本文标题:reactjs - How to validate Stripe Elements form before calling stripe.confirmPayment - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303543a1931923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论