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

Possible Unhandled Promise Rejection (id: 0): 10 #28

Closed whysetiawan closed 6 years ago

whysetiawan commented 7 years ago

Hello guys, i am newbie in react native. Then i'm learning about this library. I just try to show react-native-android payments. But when i click the button i got an error .

Possible Unhandled Promise Rejection (id: 0): 10

    androidPay(){
        const DETAILS = {
              id: 'basic-example',
              displayItems: [
                {
                  label: 'Movie Ticket',
                  amount: { currency: 'USD', value: '15.00' }
                }
              ],
              total: {
                label: 'Merchant Name',
                amount: { currency: 'USD', value: '15.00' }
              }
            };
        const METHOD_DATA = [{
              supportedMethods: ['android-pay'],
              data: {
                supportedNetworks: ['visa', 'mastercard', 'amex'],
                currencyCode: 'USD',
                environment: 'TEST', // defaults to production
                paymentMethodTokenizationParameters: {
                  tokenizationType: 'NETWORK_TOKEN',
                  parameters: {
                    publicKey: 'pk_test_jTdyDhKRi0XUBF12a3mALc4n'
                  }
                }
              }
            }];
            const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS)
            paymentRequest.show().then((response) => {
            console.log(response)
        })

    }
Andreyco commented 6 years ago

What iOS version are you running? It's possibly related to #31

whysetiawan commented 6 years ago

i'm using android, i tried to show the android pay but i got that error

EpicNem commented 6 years ago

Hi, have the same error

tsubery commented 6 years ago

Hi, I encountered the same error. Fixed the unhandled rejection here. I'd open a pull request but don't want to create diff conflicts with other pull requests. This fix didn't help me find out the cause of the "10" error code. I used logcat and saw a detailed error message from the package WalletMerchantError. In my case it was complaying about the invalid publicKey. Hope this information helps :)

jthink0228 commented 6 years ago

excuse me, where to find the publicKey? i have no idea...

many thanks

Amnesthesia commented 6 years ago

I'm getting this too, using the publicKey provided by Braintree — perhaps that's not the one I'm supposed to be using?

Amnesthesia commented 6 years ago

Okay, it works if you set your gateway parameter correctly, and set the publicKey to your public key from e.g braintree, and also set GATEWAY_TOKEN (instead of NETWORK_TOKEN as the documentation shows). Now i get another unhandled promise rejection, but it's some progress at least

Documentation shows:

{
      supportedMethods: ['android-pay'],
      data: {
        supportedNetworks: ['visa', 'mastercard', 'amex'],
        currencyCode: 'USD',
        environment: 'TEST', // defaults to production
        paymentMethodTokenizationParameters: {
          tokenizationType: 'NETWORK_TOKEN',
          parameters: {
            publicKey: 'YOUR KEY HERE',
          },
        },
      },
    }
}

What got me a bit further:

{
      supportedMethods: ['android-pay'],
      data: {
        supportedNetworks: ['visa', 'mastercard', 'amex'],
        currencyCode: 'USD',
        environment: 'TEST', // defaults to production
        paymentMethodTokenizationParameters: {
          tokenizationType: 'GATEWAY_TOKEN',
          parameters: {
            gateway: 'braintree',
            publicKey: 'PUBLIC KEY FROM BRAINTREE',
          },
        },
      },
    }
}
Andreyco commented 6 years ago

Could you post more info on rejection?

Amnesthesia commented 6 years ago

I think I solved it by finding the correct public key somewhere in the Play Console (if I remember correctly), but ended up having to scrap it all anyway because Google Play isn't available in my country :(

Andreyco commented 6 years ago

What a pity :-/

WilliamAnputra commented 5 years ago

Anyone figured out what the solution is ?

Hemanth1985 commented 5 years ago

Where should we find the public key?

miticous commented 5 years ago

Same problem here, I give up.... by the way, you can get publicKey from here https://payments.developers.google.com/paymentmethodtoken/test/keys.json

b3hz4d commented 5 years ago

I had this issue too. It's because your linking with react native having problem, check your MainApplication.java and be sure that react native payments included

tomaszNowakKivy commented 5 years ago

For me, it works only with "GATEWAY_TOKEN" type and "braintree" or "stripe" gateway. Is it really necessary to use one of them?

Wilson-Lim commented 5 years ago

I am still getting the same issue, any fix ?

esinanturan commented 4 years ago

I have tried the one given here worked for me https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#using-openssl BOdoXP+9Aq473SnGwg3JU1aiNpsd9vH2ognq4PtDtlLGa3Kj8TPf+jaQNPyDSkh3JUhiS0KyrrlWhAgNZKHYF2Y=

TonchoLozev commented 2 years ago

Follow the steps at secant: Use OpenSSL to generate a public key(https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#using-openssl) And then use the public key.