javascriptreact-nativegoogle-paypayment-request-api

Google Pay - ERROR: Request Failed - Unexpected developer error, please try again later


When I try to pay(on TEST environment) with Google Pay on a real device I get a the error in the title.

I have tried changing 'gateway' into a string like the google docs show it but so far nothing.

const DETAILS = {
id: 'COMPANY',
displayItems: [
  {
    label: 'Phone Bill',
    amount: { currency: 'USD', value: compTotal }
  }
],
total: {
  label: 'COMPANY',
  amount: { currency: 'USD', value: compTotal }
}
};

// GOOGLE PAY
const METHOD_DATA = [{
  supportedMethods: ['android-pay'],
  data: {
    supportedNetworks: ['visa', 'mastercard', 'amex'],
    currencyCode: 'USD',
    environment: 'TEST', // defaults to production
    paymentMethodTokenizationParameters: {
      tokenizationType: 'GATEWAY_TOKEN',
      parameters: {
        gateway: 'braintree',
        'braintree:tokenizationKey': 'sandbox_XXXXXXXXXXX'
      }
    }
  }
}];

const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS);

paymentRequest.show()
.then(paymentResponse => {
  const { getPaymentToken } = paymentResponse.details;

  return getPaymentToken()
    .then(paymentToken => {
      const { ephemeralPublicKey, encryptedMessage, tag } = paymentToken.details;

      return fetch('...', {
        method: 'POST',
        body: {
          ephemeralPublicKey,
          encryptedMessage,
          tag
        }
      })
      .then(res => res.json())
      .then(paymentResponse.complete('success'), handleConfirm())
      .catch(paymentResponse.complete('fail'), alert(1));
    });
});
};

Expected result would be the payment going through.


Solution

  • Turns out I was not able to do this with React-Native because 'React Native Payments' did not fully support Google Pay which in turn did not fully support Braintree & didn't support Payeezy at all.

    I had to resort to native code(Java) and then link React-Native to that native module. It was pretty simple.

    I used this demo on Github to guide me through it. I was using Braintree as the payment processor but looks like I will be switching to Payeezy.

    I was getting the error in the title because like I said Google Pay wasn't supported fully by 'React-Native-Payments' which in turn didn't support Braintree and when the error was accuring because I was only giving this info -

    parameters: {
      gateway: 'braintree',
      'braintree:tokenizationKey': 'sandbox_TOKEN-HERE'
    }

    But looks like I needed to use this(In the Java Module) -

    .put("gateway", "braintree")
    .put("braintree:apiVersion", "v1")
    .put("braintree:sdkVersion", "BETA")
    .put("braintree:clientKey", "sandbox_TOKEN-HERE")
    .put("braintree:merchantId", "TOKEN-HERE"));