react-native-payments
react-native-payments copied to clipboard
AbortError on clicking cancel button
Hi there, I'm having issue when I click on cancel button of payment pop up. It is giving me error as AbortError and one warning as Possible Unhandled Promise Rejection (id: 1): Error: InvalidStateError
React Versions "react": "16.6.3", "react-native": "0.57.8",
Following is the code fragment
const supportedMethods = [{ supportedMethods: ['apple-pay'], data: { merchantIdentifier: 'merchant.com.your-app.namespace', supportedNetworks: ['visa', 'mastercard', 'amex'], environment: 'TEST', countryCode: 'US', currencyCode: 'USD' } }];
const details = { id: 'test-payment', displayItems: [ { label: 'Payment', amount: { currency: 'USD', value: 10.00 } } ], total: { label: 'Test', amount: { currency: 'USD', value: 10.00 } } };
const paymentRequest = new PaymentRequest(supportedMethods,details);
`paymentRequest.canMakePayments()
.then(canMakePayments => {
if (canMakePayments) {
return paymentRequest
.show()
.then(paymentResponse => {
paymentResponse.complete('success');
alert(paymentResponse.details.paymentToken);
})
.catch(e => {
alert(e.message);
paymentRequest.abort();
});
}
});`
I got stuck here. Please help me out as soon as possible.
@vysakhcs1 You'll want to change your code so you don't necessarily call paymentRequest.abort()
in the catch
block.
if (e.toString().includes("AbortError")) {
return new Error("Aborted");
}
paymentRequest.abort();
// ...do other error handling things
error.toString()
will log as "AbortError"
, indicating the User has tapped Cancel
.
@vysakhcs1 You'll want to change your code so you don't necessarily call
paymentRequest.abort()
in thecatch
block.if (e.toString().includes("AbortError")) { return new Error("Aborted"); } paymentRequest.abort(); // ...do other error handling things
error.toString()
will log as"AbortError"
, indicating the User has tappedCancel
.
Ok done. But I have another problem here.
PassbookUIService quit unexpectedly.
I'm attaching screenshot here.
Please help me out.
Not sure about this one, my friend. Seems like you should check that all things XCode are up to date, do a quick restart, and go from there.
Some logs would also be helpful.
Not sure about this one, my friend. Seems like you should check that all things XCode are up to date, do a quick restart, and go from there.
Some logs would also be helpful.
Ok I tried all ways. But no escape. Anyway I appreciate your reply .
Hey, i am facing same error. First time when i ask for making payment it work fine. Dialog appears with cancel and add a card button. When i click cancel, it shows Abort errro. But when i again try to click button for making payment, this time nothing happen and no dialog appears. It throw error Invalid State Error. I want to open dialog again once i cancel it. Please help, thanks in advance.
@Zilleabbas10 have you got solution this error?
Having this issue too. Has anybody found a fix? @sushilmishraios @Zilleabbas10
I've fixed it. Just call initialization of const paymentRequest = new PaymentRequest(Platform.OS === 'ios' ? IOS_METHOD_DATA : ANDROID_METHOD_DATA, DETAILS, OPTIONS); inside your pay() function. So each time you click on payment btn it will reinitialize your payment request
Having this issue too. Has anybody found a fix? @sushilmishraios @Zilleabbas10