nitish24p / react-native-upi

A tiny module for Adding payments via UPI in your react native apps ❤️
MIT License
77 stars 30 forks source link

Issue while making payment to upi id in react native #63

Open saurabhc-ecsion opened 7 months ago

saurabhc-ecsion commented 7 months ago

please correct me if I am wrong,

I am trying to integrate this library to make payment using upi in react native app, after integration it giving error Error initiating payment: [TypeError: Cannot read property 'intializePayment' of null]

And also I am getting confused, is this also work from iOS device when user try to make payment from iOS devices.

please let me know, what to do next for payment integration

sharing you sample code (if you can fix):

import React from 'react';
import { View, Button, Alert } from 'react-native';
import UpiPayment from 'react-native-upi-payment';

const App = () => {
  const initiatePayment = async () => {
    try {
      if (UpiPayment) {
        const response = await UpiPayment.initializePayment(
          {
            vpa: 'saurabh.iosdevlpr@okhdfcbank',
            payeeName: 'Saurabh Chaudhari',
            amount: '1',
            transactionRef: 'Testing Transaction',
            transactionNote: 'Test payment',
          },
          (data) => {
            if (data && data.Status === 'SUCCESS') {
              Alert.alert('Payment Successful', 'Payment was successful.');
            } else {
              Alert.alert('Payment Failed', 'Payment was not successful.');
            }
          },
          (error) => {
            console.error('Error initiating payment:', error);
            Alert.alert('Payment Error', 'An error occurred while processing payment.');
          }
        );
      } else {
        Alert.alert('Payment Error', 'UPI Payment module is not available.');
      }
    } catch (error) {
      console.error('Error initiating payment:', error);
      Alert.alert('Payment Error', 'An error occurred while processing payment.');
    }
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button title="Initiate Payment" onPress={initiatePayment} />
    </View>
  );
};

export default App;