razorpay / react-native-razorpay

React Native wrapper for Razorpay's mobile SDKs
https://www.npmjs.com/package/react-native-razorpay
MIT License
121 stars 107 forks source link

[TypeError: Cannot read property 'open' of null] #451

Open Akulvarshney opened 1 year ago

Akulvarshney commented 1 year ago

I had installed the react-native-razorpay package using

$ npm i react-native-razorpay --save

I have imported the RazorpayCheckout on the top:

import RazorpayCheckout from "react-native-razorpay";

then I have created a function named paymentRazor, which has been called to an onPress functionality of a button.

` const paymentRazor = () => {

var options = {
  key: "rzp_test_Rh5hj15XBv8XmI",
  currency: "INR",
  amount: "5000",
  order_id: "order_DslnoIgkIDL8Zt",
  name: "Akul varshney",
  description: "Payment for purchase order",
  image: "http://103.107.67.49/static/media/Orane-Consulting-logo.c3a9713e.jpg",
  prefill: {
    email: "akul.varshney@orane.in",
    contact: "8800252885",
    name: "Akul Varshney",
  },
  theme: { color: "#53a20e" },
};

console.log(options);

RazorpayCheckout(options)
  .then((data) => {

    let bodyData = {
      razorpay_payment_id: data.razorpay_payment_id,
      razorpay_order_id: "order_DslnoIgkIDL8Zt",
      razorpay_signature: data.razorpay_signature,
    };
    dispatch(razorPayment(bodyData));
    alert(`Success: ${data.razorpay_payment_id}`);
  })

  .catch((error) => {
    // handle failure
    alert(`Error: ${error.code} | ${error.description}`);
    console.log(error);
  });

};`

Once I click on that button, the following error occurs:

LOG [TypeError: Cannot read property 'open' of null]

Jojit-Thomas commented 1 year ago

Hey, I encountered the same error. Have you discovered any solutions for it?

skbhati199 commented 1 year ago

I was facing this issue after I have fixed

Follow these step :

yarn add react-native-razorpay
npx expo prebuild
npx expo run:[ios|android] --device <-- mandatory
pranav750 commented 6 months ago

@skbhati199 Ran the command -

npx expo prebuild
npx expo run:android --device

Build is successful but it is throwing this error

CommandError: Couldn't open Android app with activity "com.anonymous.cc_ui_expo://expo-development-client/?url=http%3A%2F%2F192.168.1.3%3A8081" on device "Resizable_Experimental_API_34".
The app might not be installed, try installing it with: npx expo run:android -d Resizable_Experimental_API_34
Activity class {com.anonymous.cc_ui_expo://expo-development-client/?url=http%3A%2F%2F192.168.1.3%3A8081} does not exist.

Tried starting the app again using

npx expo start

The app is opening but it is again throwing the same error.

[TypeError: Cannot read property 'open' of null]
vivekshindhe commented 6 months ago

@pranav750 The issue is because after running npx expo run:android --device command, when the build failed and you ran the metro server it was in Expo Go mode.

Try running the following commands in order

  1. npx expo start
  2. Press s to switch to development build
  3. Press a to run on android.
sudhakara11 commented 2 months ago

Dear All,

Could anyone able to figure out the issue?

Kindly do the needful

Regards