问题描述
我已在我的应用程序中集成了本机支付。 RNUpiPayment组件在此处调用initializePayment方法,该方法仅为默认用户提供vpa。如何通过fecth api或任何其他方法为数据库中的许多用户提供vpa地址?请提供任何方法或建议。
<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>
解决方法
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);
});
};