>

payumoney 지불 게이트웨이를 반응 네이티브에 통합하려고하는데 "Pay"버튼을 누르면 오류가 발생합니다 모바일 화면에서 "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' }

  • 답변 # 1

    이것은 해결책에 늦었을 수도 있지만 문제는 금액과 관련이 있습니다. 금액은 300.0의 이중 값이어야합니다.

    이것을 전달하십시오

    let options = {
        amount: 10.0,
        txid: "123123123" ,
        productId: "test",
        name: "Name",
        email: "test@gmail.com",
        phone: "8826343434",
        id: "393463",
        key: "LLKwG0",
        surl: "https://www.payumoney.com/mobileapp/payumoney/success.php",
        furl: "https://www.payumoney.com/mobileapp/payumoney/failure.php",
        sandbox: true,
        hash: "d829abecdaf9f2835787b3f56d1c7565721ca2501e6414438e61948dab435f102fc93213008cdfa3474691cadcc2dabdde64cd58c128dd2afcf3b389d617919c"
    };
    PayuMoney.pay(options).then((d) => {
        console.log(d); // WIll get a Success response with verification hash
    }).catch(e => {
        console.log(e); //In case of failture
    });
    
    

    PHP 서버 측 코드 :

    <?php
    echo makeHash("LLKwG0","123123123","10.0","test","Name","test@gmail.com");
    function makeHash($key, $txnid, $amount, $productinfo, $firstname, $email){
        $salt = "qauKbEAJ";
        $payhash_str = $key . '|' . checkNull($txnid) . '|' . checkNull($amount) . '|' . checkNull($productinfo) . '|' . checkNull($firstname) . '|' . checkNull($email) . '|||||||||||' . $salt;
        $hash = strtolower(hash('sha512', $payhash_str));
        return $hash;
    }
    function checkNull($value)
    {
        if ($value == null) {
            return '';
        } else {
            return $value;
        }
    }
    ?>
    
    

    참고 : Github 이슈 링크

  • 이전 Haskell 실행 파일에 필요한 OS 종속성 패키지를 어떻게 확인합니까?
  • 다음 php - htaccess 파일을 사용하여"http - //wwwexamplecom/pathquery-string=something"과 같은 url을 오류 페이지로 리디렉션하는 방법