反应原生中的 Payumone 集成 [英] Payumoney integration in react-native

查看:47
本文介绍了反应原生中的 Payumone 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 react-native 中集成 payumoney 支付网关,但是当我按下支付"按钮时出现错误手机屏幕上java.lang.double 无法转换为java.lang.string".

I am trying to integrating payumoney payment gateway in react-native but when I pressed "Pay" button I got an error "java.lang.double cannot be cast to java.lang.string" on the mobile screen.

我在整个 google 中搜索了代码,但我进入了 node js 作为后端.

I searched the whole google for the code but I got in node js as backend.

我的JS文件是这样的:-

My JS file is like this:-

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',
  },
});

我的后端代码是这样的:-

My backend code like this:-

<?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' }

推荐答案

这可能是解决方案晚了,但问题与您的数量有关,金额应为 300.0 倍值.

This might be late to the solution, but issue is related to your amount, amount should be 300.0 a double value.

请尝试通过此

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 Server Side Code:

<?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 问题链接

这篇关于反应原生中的 Payumone 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆