react-native-payments icon indicating copy to clipboard operation
react-native-payments copied to clipboard

AbortError on clicking cancel button

Open vysakhcs1 opened this issue 5 years ago • 8 comments

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 avatar May 20 '19 15:05 vysakhcs1

@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.

wkoutre avatar May 21 '19 20:05 wkoutre

@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.

Ok done. But I have another problem here. PassbookUIService quit unexpectedly. I'm attaching screenshot here. Screenshot 2019-05-20 at 3 17 42 PM

Please help me out.

vysakhcs1 avatar May 22 '19 09:05 vysakhcs1

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.

wkoutre avatar May 22 '19 17:05 wkoutre

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 .

vysakhcs1 avatar May 23 '19 14:05 vysakhcs1

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 avatar Mar 09 '20 07:03 Zilleabbas10

@Zilleabbas10 have you got solution this error?

sushilkmishra avatar May 13 '20 13:05 sushilkmishra

Having this issue too. Has anybody found a fix? @sushilmishraios @Zilleabbas10

indigomelody avatar Sep 08 '20 16:09 indigomelody

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

ocean-beach avatar Oct 07 '20 10:10 ocean-beach