#BRData
1 messages · Page 1 of 1 (latest)
Hello
Hi Bismarck
What do you mean by "went through successfully"?
So I have this code that comes in the quick setup with Stripe inside the handleSubmit function
const { error } = await stripe.confirmPayment({
elements,
redirect: "if_required",
confirmParams: {
// Make sure to change this to your payment completion page
return_url: windowLocation,
receipt_email: emailAddress,
},
});
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
And I noticed that its checking the error.type and the if else statement only contains an error check - what is a way for me to check if the payment went through succesfully so I can include a javascript snippet of code inside that success statement to do things that need to be done on my end of things
It shouldn't have else { showMessage("An unexpected error occurred."); }
What docs do you see that in?
If it reaches your else block then the promise successfully resolved without an error and you would show a success
If you want to really make sure, then you can retrieve the PaymentIntent in that else block using: https://stripe.com/docs/js/payment_intents/retrieve_payment_intent
Then you can see the status of the PaymentIntent to ensure it is succeeded
Line 58-62 on the checkout.js file
Oh yikes
Well, to be fair, this assumes you don't use redirect: if_required
So that would be accurate in that case since you would only reach that code if there was an unexpected error.
So actually that is technically correct
But confusing
But yeah, since you aren't redirecting by defeault, you should just retrieve the PaymentIntent in that block like I mentioned above
Hmm... still a little confused to be honest
elements,
redirect: "if_required",
confirmParams: {
return_url: windowLocation,
receipt_email: emailAddress,
},
});
if (error) {
// There was an error during payment confirmation
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
} else if (paymentIntent && paymentIntent.status === "succeeded") {
// Payment was successful
showMessage("Payment succeeded!");
} else {
// Handle other cases if needed
showMessage("An unexpected result occurred.");
}```
Does that look right?
Ah right I forgot we do supply the paymentIntent if the promise resolves successfully
So you don't even need to retrieve it
Yep that looks good to me
I'd test it out!
But wait - quick question
since I am using payment holds
it will not be succeeded unless its captured correct?
Ah yes, so you want status === 'requires_capture'
Ahh okay thank you.