naoufal / react-native-payments

Accept Payments with Apple Pay and Android Pay using the Payment Request API.
https://www.npmjs.com/package/react-native-payments
1.59k stars 413 forks source link

Error: AbortError on paymentRequest.show() #383

Open dentep opened 1 year ago

dentep commented 1 year ago

Hello everyone. I am trying to follow a demo and setup Apple Pay on ios. I have configured merchantID and the library works well with a simulator. Unfortunately when I launch the app on a real device I get following error:

[Error: AbortError]

Code for running the function:

  const PaymentRequest = require('react-native-payments').PaymentRequest;

  const payApple = async () => {
    console.log('payApple')
    const METHOD_DATA = [{
      supportedMethods: ['apple-pay'],
      data: {
        merchantIdentifier: '****',
        supportedNetworks: ['visa'],
        countryCode: 'US',
        currencyCode: 'USD'
      }
    }];

    const OPTIONS = {
      requestPayerName: false,
      requestPayerPhone: false,
      requestPayerEmail: false,
      requestShipping: false
    };

    const DETAILS = {
      id: 'example',
      displayItems: [
        {
          label: 'Movie Ticket',
          amount: { currency: 'USD', value: '15.00' }
        }
      ],
      total: {
        label: 'Merchant Name',
        amount: { currency: 'USD', value: '15.00' }
      }
    };

    const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS, OPTIONS);
    paymentRequest.canMakePayments().
      then((canMakePayment) => {
        if (canMakePayment) {
          console.log('Can Make Payment');
          paymentRequest.show()
            .then(paymentResponse => {
              console.log('payments response')
              // Your payment processing code goes here
              paymentResponse.complete('success');
            })
            .catch((error) => {
              //error here
              console.log(error)
              console.log("Show Error", JSON.stringify(error, null, 2));
            })
        } else {
          console.log('Cant Make Payment');
        }
      })
      .catch((error) => {
        console.log("Can Make Payments Error", error);
      })
  }
"react-native": "0.67.4",
"react-native-payments": "^0.8.4",
hivie7510 commented 1 year ago

I wish I could get this far. Even using your code I am stuck at null is not an object (evaluating 'ReactNativePayments.createPaymentRequest'). I know this is a week later, but if you see this do you have anything that you remember that would have caused this issue.

sagarjeu commented 1 year ago

[Error: AbortError] on simulator iphone 14 for merchantIdentifier: 'merchant.apple.test',

ApplepayAPi() { const METHOD_DATA = [ { supportedMethods: ['apple-pay'], data: { merchantIdentifier: 'merchant.apple.test', supportedNetworks: ['visa'], countryCode: 'US', currencyCode: 'USD', }, }, ]; const DETAILS = { id: 'example', displayItems: [ { label: 'Movie Ticket', amount: {currency: 'USD', value: '15.00'}, }, ], total: { label: 'Merchant Name', amount: {currency: 'USD', value: '15.00'}, }, }; const OPTIONS = { requestPayerName: false, requestPayerPhone: false, requestPayerEmail: false, requestShipping: false, }; let paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS, OPTIONS);

paymentRequest.addEventListener('shippingaddresschange', e => {
  const updatedDetails = getUpdatedDetailsForShippingAddress(
    paymentRequest.shippingAddress,
  );

  e.updateWith(updatedDetails);
});

paymentRequest.addEventListener('shippingoptionchange', e => {
  const updatedDetails = getUpdatedDetailsForShippingOption(
    paymentRequest.shippingOption,
  );

  e.updateWith(updatedDetails);
});

paymentRequest
  .canMakePayments()
  .then(canMakePayment => {
    if (canMakePayment) {
      console.log('Can Make Payment');
      paymentRequest
        .show()
        .then(paymentResponse => {
          // Your payment processing code goes here
          paymentResponse.complete('success');
          Alert.alert('Payment Complete');
        })
        .catch(error => {
          console.log('Show Error', error);
        });
    } else {
      console.log('Cant Make Payment');
    }
  })
  .catch(error => {
    console.log('Can Make Payments Error', error);
  });

}

Nouman-Javaid commented 1 year ago

I am facing the same error i- e [Error: AbortError]

Did anyone find any solution?

dfragosodiaz commented 1 year ago

Hi! Our team is also getting a similar issue where the app crashes when using apple pay. Does anyone have any idea of why this might be happening? Did something change lately with this package that might be causing problems interacting with ApplePay?