Open Tanzeel-ur-rehman-git opened 3 years ago
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;`
`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}}>
{/* <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
Same issue on android, IOS work correctly.
@Tanzeel-ur-rehman-git I find solution in this issue Just downgrade to implementation com.google.android.gms:play-services-wallet:17.0.0
com.google.android.gms:play-services-wallet:17.0.0
in Ios payment console is working fine but in android i get error this is my code
i install android dependencies like give in document all good but when i click on pay now button it gives error