With the the below code implemented in ReactNative, I can complete the Stripe payment successfully.
const openPaymentSheet = async (paymentIntentClientSecret: string, ephemeralKey: string, stripeId: string) => {
try {
const { error } = await initPaymentSheet({
customerId: stripeId,
customerEphemeralKeySecret: ephemeralKey,
paymentIntentClientSecret: paymentIntentClientSecret,
merchantDisplayName: 'Workout Wallet'
});
if (error) {
captureLog('Error in init payment sheet: ', error)
Alert.alert('Error', error.message);
return;
}
const { error: paymentError } = await presentPaymentSheet();
if (paymentError) {
captureLog('Error in payment: ', paymentError)
Alert.alert('Error', paymentError.message);
} else {
Alert.alert('Success', 'Your payment was confirmed successfully!');
}
} catch (err) {
console.log("Failed to open payment sheet: ", err);
Alert.alert('Error', 'Failed to open payment sheet');
}
};
On the server, I’m able to capture the success and failure events from Stripe.
On the client side, after successful payment, I’ve to save the invoice details, order summary, discount details, etc in the database against that transaction. But the client app doesn’t get the details of the transaction ID or anything else. How can I capture the transaction id to save the custom details in my DB?
Business logic like saving invoice details, order summary, discount details, etc. should always take place in the webhook handler. You should never do it via client, since the customer can close the browser window before the data is saved and it will be lost. You can listen to payment_intent.succeeded
webhook event on your server, and use the PaymentIntent ID to fetch any relevant objects/information via Stripe API to save it to your database.
4