Issue
I have a backend service that handles the Stripe webhooks post-payment but I want my service to do some background api calls before returning, Stripe returns a success too quickly, so that subsequent client requests are running too soon.
And what's the difference between confirmPaymentSheetPayment and presentPaymentSheet methods, they both appear to fire at the same time? My hope was the confirmPaymentSheetPayment fired after a response from my backend to Stripe but that doesn't appear to be the case.
A simplifed version:
const {presentPaymentSheet, confirmPaymentSheetPayment} = useStripe();
const openPaymentSheet = async () => {
await initializePaymentSheet(option);
const {error} = await presentPaymentSheet();
if (error) {
console.log(`Error code: ${error.code}`, error.message);
} else {
console.log('Success', 'Presented');
}
// not sure of the difference between presentPaymentSheet success and confirmPaymentSheetPayment?
const {error2} = await confirmPaymentSheetPayment();
if (error2) {
console.log(`Error code: ${error.code}`, error.message);
} else {
console.log('Success', 'Confirmed');
// now refresh the client
}
setModalVisible(false);
};
Or there another way to do this, other than just waiting x seconds before refreshing the client?
Solution
The presentPaymentSheet
method is used to present the Payment Sheet to the Customer. At that point they control when the confirmation will happen based on when they submit their payment method info.
That being said, there is another documented flow for handling the confirmation yourself. Here are the docs for that flow. Using that approach you use the payment sheet only to collect the payment method information and you later confirm the payment yourself (after your background api calls).
The major difference here is that you initialize the payment sheet with customFlow: true,
and then call the confirmPaymentSheet
method once the rest of the actions you want to perform and completed.
Answered By - RyanM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.