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

Could Not invoke ReactNativePayments.show Null #327

Open Tanzeel-ur-rehman-git opened 3 years ago

Tanzeel-ur-rehman-git commented 3 years ago
Screenshot 2021-09-01 at 6 41 49 PM Screenshot 2021-09-01 at 6 42 19 PM

in Ios payment console is working fine but in android i get error this is my code

`import React, {Component} from 'react'; import {Platform, View, Text, TouchableOpacity} from 'react-native'; import {PaymentRequest} from 'react-native-payments';

class App extends Component { constructor(props) { super(props); this.state = { }; }

showPaymentSheet = (succeed = true) => { const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS); paymentRequest .show() .then(paymentResponse => { const card_token = paymentResponse.details.paymentToken; // const paymentdetail = paymentResponse.details; // const paymentresponce = paymentResponse;

    if (succeed) {
      paymentResponse.complete('success');
      console.log('Payment request completed with card token', card_token);
      // console.log('Payment detail', paymentdetail);
      // console.log('Payment request ', paymentresponce);
    } else {
      paymentResponse.complete('failure');
      console.log('Payment request failed');
    }
  })
  .catch(error => {
    if (error.message === 'AbortError') {
      console.log('Payment request was dismissed');
    }
  });

};

render() { return ( <View style={{margin: 50}}> <View style={{height: 44}}>

Pay Now
      {/* <ApplePayButton
        type="plain"
        style="black"
        onPress={this.showPaymentSheet}
      /> */}
    </View>
  </View>
);

} }

const APPLE_METHOD_DATA = [ { supportedMethods: ['apple-pay'], data: { merchantIdentifier: 'merchant.com.your-app.namespace', supportedNetworks: ['visa', 'mastercard', 'amex'], countryCode: 'US', currencyCode: 'USD', paymentMethodTokenizationParameters: { parameters: { gateway: 'stripe', 'stripe:publishableKey': 'your key etc', }, }, }, }, ];

const ANDROID_METHOD_DATA = [ { supportedMethods: ['android-pay'], data: { supportedNetworks: ['visa', 'mastercard', 'amex'], currencyCode: 'USD', environment: 'TEST', // defaults to production paymentMethodTokenizationParameters: { tokenizationType: 'NETWORK_TOKEN', parameters: { publicKey: 'you key etc, }, }, }, }, ];

const METHOD_DATA = Platform.OS == 'ios' ? APPLE_METHOD_DATA : ANDROID_METHOD_DATA;

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'}, }, };

export default App;`

i install android dependencies like give in document all good but when i click on pay now button it gives error

Screenshot 2021-09-01 at 6 39 16 PM
dyrkow commented 3 years ago

Same issue on android, IOS work correctly.

dyrkow commented 3 years ago

@Tanzeel-ur-rehman-git I find solution in this issue Just downgrade to implementation com.google.android.gms:play-services-wallet:17.0.0