I’m using @stripe/stripe-react-native
in my React Native project. Notice below that there is an error but it isn’t descriptive or helpful. I want to know what I am missing or doing wrong so that I can finish the transaction.
Here is the only call to initPaymentSheet
:
initPaymentSheet({
merchantDisplayName: "Acme, Inc.", // Actual name changed for privacy
intentConfiguration: {
mode: { amount: transaction.amountOwed * 100, currencyCode: 'USD', },
confirmHandler: (paymentMethod, shouldSavePaymentMethod, intentCreationCallback) => {
console.log('confirmHandler > paymentMethod:', JSON.stringify(paymentMethod, null, 2))
console.log('confirmHandler > shouldSavePaymentMethod: ', JSON.stringify(shouldSavePaymentMethod, null, 2))
console.log('confirmHandler > clientSecret: ', transaction.piPaymentIntent.clientSecret)
intentCreationCallback({ clientSecret: transaction.piPaymentIntent.clientSecret, });
},
}
})
Every test card number that I use give me the same error: “Something went wrong”.
This is the snippet of component code that is loaded before calls to presentPaymentSheet
:
return (<StripeProvider publishableKey={publishableKey}>
<View style={styles.container}></View>
</StripeProvider >);
The publishable key that I use works for making website purchases.
The problem is that presentPaymentSheet()
cannot finish in the then
method or throw an error to the catch
method of the promise returned by presentPaymentSheet()
.
The only way I can finish the transaction is by tapping the ‘X’ in the Stripe payment sheet. What I am missing or doing wrong that prevents me from finishing the transaction?
Here is the code:
presentPaymentSheet().then((paymentSheetResult) => {
console.log('This is never reached!')
const { error } = paymentSheetResult;
if (error) {
myConfirmHandler({ sResultCode: 'C' }, paymentSheetResult);
} else {
myConfirmHandler({ sResultCode: 'F' });
}
}).catch((error) => {
console.log('This, TOO, is never reached!');
setExplanation(
'There was an error initializing the payment sheet. Please try again later.nn' +
error?.message);
myConfirmHandler({ sResultCode: 'C' }, { error });
}).finally(() => {
console.log('This is only reached on a user canceled transaction!')
console.log('finally of presentPaymentSheet')
});
I thought that calling presentPaymentSheet
after calling initPaymentSheet
while consuming the StripeProvider
component with the correct publishable key would be enough to let a user finish the transaction.
The client secret was not given due to a typo. This is the sort of behavior that results when intentCreationCallback
is called without a proper client-secret key.