PayHereLK / payhere-mobilesdk-reactnative

PayHere Mobile SDK for React Native
8 stars 6 forks source link

TypeError: null is not an object (evaluating '_reactNative.NativeModules.PayhereOfficial.startPayment') #4

Closed RavinduJayasekara closed 3 years ago

RavinduJayasekara commented 3 years ago

TypeError: null is not an object (evaluating '_reactNative.NativeModules.PayhereOfficial.startPayment')

import { StatusBar } from "expo-status-bar"; import React from "react"; import { StyleSheet, Text, View, Button } from "react-native"; import PayHere from "@payhere/payhere-mobilesdk-reactnative";

export default function App() {

const fetchUrl = async () => {

const paymentObject = {
  sandbox: true, // true if using Sandbox Merchant ID
  merchant_id: "", // Replace your Merchant ID
  merchant_secret: "", // See step 4e
  notify_url: "https://sandbox.payhere.lk/pay/checkout",
  order_id: "ItemNo12345",
  items: "Hello from React Native!",
  amount: "50.00",
  currency: "LKR",
  first_name: "Saman",
  last_name: "Perera",
  email: "samanp@gmail.com",
  phone: "0771234567",
  address: "No.1, Galle Road",
  city: "Colombo",
  country: "Sri Lanka",
  delivery_address: "No. 46, Galle road, Kalutara South",
  delivery_city: "Kalutara",
  delivery_country: "Sri Lanka",
  custom_1: "",
  custom_2: "",
};

try {
  PayHere.startPayment(
    paymentObject,
    (paymentId) => {
      console.log("Payment Completed", paymentId);
    },
    (errorData) => {
      Alert.alert("PayHere Error", errorData);
    },
    () => {
      console.log("Payment Dismissed");
    }
  );
} catch (e) {
  console.log(e);
}

};

return (

Open up App.js to start working on your app!
PayHereDevs commented 3 years ago

Hi Ravinud!

Apologies for the delayed response. _reactNative.NativeModules.PayhereOfficial evalutes to null when you have missed the step to perform the react-native link step.

Please try perform the command on your React Native project root and try rebuilding again. We will be glad to be of further support.

 react-native link @payhere/payhere-mobilesdk-reactnative