react-native-payments icon indicating copy to clipboard operation
react-native-payments copied to clipboard

Possible Unhandled Promise Rejection (id: 1) 10 (on Android)

Open MohammedAliBinTaleb opened this issue 3 years ago • 5 comments

Thank you for Great Payment package mr @naoufal

I have issues with react-native-payment when I try to press button to show Android Pay it give me this Errror Possible Unhandled Promise Rejection (id: 1) 10

Even when I try to catch Error in console.log(Error) it show me this ===> "10" !

this is my code 👇

import { StatusBar } from "expo-status-bar";
import React from "react";
import { Button, StyleSheet, Text, View } from "react-native";
let ReactNativePayment = require("react-native-payments");
import { NativeModules } from "react-native";
const { ReactNativePayments } = NativeModules;
// let {ReactNativePayments } = require("react-native-payments");
global.PaymentRequest = ReactNativePayment.PaymentRequest;
export default function App() {
  const METHOD_DATA = [
    {
      supportedMethods: ["android-pay"],
      data: {
        supportedNetworks: ["visa", "mastercard", "amex"],
        currencyCode: "SAR",
        environment: "TEST", // defaults to production
        paymentMethodTokenizationParameters: {
          tokenizationType: "PAYMENT_GATEWAY",
          parameters: {
            publicKey: "???-???-???",
          },
        },
      },
    },
  ];
  const DETAILS = {
    // id: "1",
    displayItems: [
      {
        label: "Movie Ticket",
        amount: { currency: "SAR", value: "15.00" },
      },
    ],
    total: {
      label: "Merchant Name",
      amount: { currency: "SAR", value: "15.00" },
    },
  };
  const onPay = async () => {
    const paymentRequest = new global.PaymentRequest(METHOD_DATA, DETAILS);
    let respons = await paymentRequest.show();
  };
  return (
    <View style={styles.container}>
      <Text>Good</Text>
      <Button title="Pay open" onPress={onPay} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

note : I have no idea how to generate publish key is this could be a problem ?

I hope you can help me as soon as possible 😅

MohammedAliBinTaleb avatar Dec 08 '20 07:12 MohammedAliBinTaleb

publish key ====> public key

MohammedAliBinTaleb avatar Dec 08 '20 07:12 MohammedAliBinTaleb

Hi Mohammed, yes it is a problem - you need to sign up for a merchant account with either Stripe or Braintree to use the tokenization options. They will give you an API key.

If you exclude those you should have an Apple/Google cryptogram returned but you will need to decrypt it server side which is pretty complex, so I'd recommend going with one of the above. The signup process for Stripe is much easier than Braintree.

nabilfreeman avatar Jan 06 '21 10:01 nabilfreeman

mohamed did it work with you ?

ahmed3ly avatar Aug 26 '21 17:08 ahmed3ly

Please try with try...catch block

const onPay = async () => {
   try {
    const paymentRequest = new global.PaymentRequest(METHOD_DATA, DETAILS);
    let respons = await paymentRequest.show();
    } catch (e){
    // handle error
  }
  };

govarthananve avatar Oct 11 '22 13:10 govarthananve

Hi Mohammed, yes it is a problem - you need to sign up for a merchant account with either Stripe or Braintree to use the tokenization options. They will give you an API key.

If you exclude those you should have an Apple/Google cryptogram returned but you will need to decrypt it server side which is pretty complex, so I'd recommend going with one of the above. The signup process for Stripe is much easier than Braintree.

I don't use Stripe and Braintree. How can I get publicKey? @govarthananve @nabilfreeman

showtan001 avatar Oct 25 '22 02:10 showtan001