Я пытаюсь интегрировать платежный шлюз payumoney в реагирующий на родную систему, но когда я нажал кнопку «Оплатить», я получил ошибку «java.lang.double» не может быть приведен к java.lang.string »на экране мобильного телефона.
Я искал код в Google, но я попал в узел js как бэкэнд.
Мой JS-файл выглядит так: -
import * as React from 'react';
import { Image, ImageBackground, ScrollView, Animated, Text, StyleSheet, View, ListView, TextInput, ActivityIndicator, Alert, TouchableOpacity } from 'react-native';
import PayuMoney from 'react-native-payumoney';
export default class Consult_dr extends React.Component {
constructor(props) {
super(props);
this.state = {
name:'',
email:'',
phone:'',
};
this._makePay = this._makePay.bind(this);
}
_makePay() {
let amount = 300;
let d = new Date();
let txid = d.getTime();
let productId = "Consulting";
let name = this.state.name;
let email = this.state.email;
let phone = this.state.phone;
let surl = "https://www.payumoney.com/mobileapp/payumoney/success.php";
let furl = "https://www.payumoney.com/mobileapp/payumoney/failure.php";
let id = "xxxxxx";
let key = "xxxxxx";
let sandbox = true; //Make sure to set false on production or you will get error
fetch('https://athirst-desertions.000webhostapp.com/payu-hash.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
key: key,
txnid: txid,
amount: amount,
productinfo: productId,
firstname: name,
email: email,
phone: phone,
}),
})
.then((response) => response.text())
.then((hash) => {
var test = hash.replace(/\"/g, "");
let options = {
amount: amount,
txid: txid ,
productId: productId,
name: name,
email: email,
phone: phone,
id: id,
key: key,
surl: surl,
furl: furl,
sandbox: sandbox,
hash: test
};
console.log("this is then funciton====", options)
PayuMoney.pay(options).then((d) => {
console.log("payumoney===>",d);
}).catch(e => {
console.log(e);
});
})
}
static navigationOptions = { title: 'Consult Doctor',};
render() {
return (
<ScrollView>
<ImageBackground source={require('../assets/bg.png')} style={styles.container} >
<Image
source={require('../btnimage/consult_dr_header.jpg')}
style={{width:420, height:300, marginTop:20}}
/>
<View style={{marginTop:100, marginLeft:20, marginRight:20, marginBottom:200}}>
<TextInput
placeholder = "Descrbe your problem in detail"
placeholderTextColor="white"
onChangeText = {(TextInputText) => this.setState({name:TextInputText})} />
<TextInput
placeholder = "Descrbe your problem in detail"
placeholderTextColor="white"
style = {styles.textInput}
onChangeText = {(TextInputText) => this.setState({email:TextInputText})} />
<TextInput
placeholder = "Descrbe your problem in detail"
placeholderTextColor="white"
style = {styles.textInput}
onChangeText = {(TextInputText) => this.setState({phone:TextInputText})} />
<TouchableOpacity style={styles.btnstyle}
onPress={this._makePay}>
<Text style={{textAlign: 'center', color: 'blue',}}> Submit </Text>
</TouchableOpacity>
</View>
</ImageBackground>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
width: null,
height: null,
},
textInput:{
width: 300,
color: 'white',
},
});
Мой бэкэнд-код выглядит так:-
<?php
$HostName = "localhost";
$DatabaseName = "xxxxxxxxxx";
$HostUser = "xxxxxxxxx";
$HostPass = "xxxxxxxxx";
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
$obj = json_decode(file_get_contents('php://input'), true);
if(isset($obj["txnid"]))
{
$merchant_key = "xxxxxx";
$salt = "xxxxx";
$txnid = $obj['txnid'];
$amount = $obj['amount'];
$productinfo = $obj['productinfo'];
$firstname = $obj['firstname'];
$email = $obj['email'];
$phone = $obj['phone'];
$query = "INSERT INTO `pay_table` ( txnid, amount, productinfo, firstname, email, phone ) VALUES ('$txnid', '$amount', '$productinfo', '$firstname', '$email', '$phone')";
$hash = $merchant_key."|".$txnid."|".$amount."|".$productinfo."|".$firstname."|".$email."|".$phone."|".$salt;
$hashkey = strtolower(hash('sha512', $hash));
$result = $conn->query($query);
if ($result == 1)
{
$data = $hashkey;
//header('Content-type: application/json');
}
else
{
$data["message"] = "data not saved successfully";
$data["status"] = "error";
}
}
else
{
$data["message"] = "Format not supported";
$data["status"] = "error";
}
echo json_encode($data);
?>
Мой ответ такой: -
'this is then funciton====', { amount: 300,
txid: 1538136491771,
productId: 'Consulting',
name: 'All',
email: 'So',
phone: '335689',
id: 'xxxxxxx',
key: 'Xxxxxxx',
surl: 'https://www.payumoney.com/mobileapp/payumoney/success.php',
furl: 'https://www.payumoney.com/mobileapp/payumoney/failure.php',
sandbox: false,
hash: '4c9a9dfdfb909cf8f93cefb1f26c736f404b339c8e77d98a2f95f1af879c6a8c06c6f23352f39a180272d15c181b98c70bf1dff7009ef5a732c4ae7da5f9a0fa' }