Fetch virtual payment address of users in my react native app

309 views Asked by At

I have integrated react-native-upi-payment in my app. The RNUpiPayment Component calls initializePayment method here which gives only vpa for a default user. How can I give vpa address for many users in my database by fecth api or any other methods? Any methods or suggestions please.

My code is here

<TouchableOpacity
        style={styles.payBtn}
        activeOpacity={0.5}
        onPress={() => {
          RNUpiPayment.initializePayment(
            {
              vpa: '8856452125@ybl', // or can be john@ybl or mobileNo@upi
              payeeName: 'Stanlee',
              amount: '20',
              transactionRef: 'aasf-332-aoei-fn',
            },
            () => {
              console.log('Success');
            },
            () => {
              console.log('Failed');
            },
          );
        }}>
        <Text style={styles.payBtnTxt}>PAY</Text>
      </TouchableOpacity>
1

There are 1 answers

0
Safaf Mohammed On
Finally got it!

    DriverPaymentFunction = () => {
    const {DriverUPI} = this.state;
    const {DriverName} = this.state;

    fetch('http://ip/appname/payment.php', {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        upi_id: DriverUPI,
        driver: DriverName,
      }),
    })
      .then((response) => response.json())
      .then((responseJson) => {
        // If server response message same as Data Matched
        if (responseJson === 'Data Matched') {
          RNUpiPayment.initializePayment( //Payment API
                  {
                    vpa: DriverUPI, // or can be john@ybl or mobileNo@upi
                    payeeName: DriverName,
                    amount: '0',
                    transactionRef: 'AppName Ride Transaction',
                  },
                  () => {
                    console.log('Success');
                  },
                  () => {
                    console.log('Failed');
                  },
                );
        } else {
          Alert.alert(responseJson);
        }
      })
      .catch((error) => {
        console.error(error);
      });
  };