Payumoney付款集成中的哈希密钥生成错误

时间:2019-04-24 07:23:01

标签: javascript php payment-gateway payumoney

我正在尝试将Payumoney集成到我的网站中。在Payumoney提供的演示代码上,填充其他数据时会自动创建哈希值。但是在我的代码中,它不起作用(未创建哈希值)。

我的代码是

    <?php

    if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0){
    //Request hash
       $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';    
       if(strcasecmp($contentType, 'application/json') == 0){
           $data = json_decode(file_get_contents('php://input'));
           $hash=hash('sha512', $data->key.'|'.$data->txnid.'|'.$data->amount.'|'.$data->pinfo.'|'.$data->fname.'|'.$data->email.'|||||'.$data->udf5.'||||||'.$data->salt);
           $json=array();
           $json['success'] = $hash;
           echo json_encode($json);

       }
        exit(0);
       }

    function getCallbackUrl()
    {
       $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
       return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . 'response.php';
       }

    ?>

   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" >

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"> 
   </script>


    <?php if (($rowcart['status']) == 1){ ?>

                                                           <?php 

       if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0){
       //Request hash
       $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';   
        if(strcasecmp($contentType, 'application/json') == 0){
           $data = json_decode(file_get_contents('php://input'));
            $hash=hash('sha512', $data->key.'|'.$data->txnid.'|'.$data->amount.'|'.$data->pinfo.'|'.$data->fname.'|'.$data->email.'|||||'.$data->udf5.'||||||'.$data->salt);
            $json=array();
            $json['success'] = $hash;
            echo json_encode($json);

        }
        exit(0);
    }

                                                            function getCallbackUrl()
    {
        $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . 'response.php';
     }

                                                        ?>
                                                        <form action="<?php ?>" id="payment_form" method="POST">
    <input type="hidden" id="udf5" name="udf5" value="BOLT_KIT_PHP7" />
    <input type="hidden" id="surl" name="surl" value="<?php echo getCallbackUrl(); ?>" />


    <div class="dv">
    <span class="text"><label>Merchant Key:</label></span>
    <span><input type="text" id="key" name="key" placeholder="Merchant Key" value="" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Merchant Salt:</label></span>
    <span><input type="text" id="salt" name="salt" placeholder="Merchant Salt" value="" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Transaction/Order ID:</label></span>
    <span><input type="text" id="txnid" name="txnid" placeholder="Transaction ID" value="<?php echo  "Txn" . rand(10000,99999999)?>" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Amount:</label></span>
    <span><input type="text" id="amount" name="amount" placeholder="Amount" value="6.00" /></span>    
    </div>

    <div class="dv">
    <span class="text"><label>Product Info:</label></span>
    <span><input type="text" id="pinfo" name="pinfo" placeholder="Product Info" value="P01,P02" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>First Name:</label></span>
    <span><input type="text" id="fname" name="fname" placeholder="First Name" value="" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Email ID:</label></span>
    <span><input type="text" id="email" name="email" placeholder="Email ID" value="" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Mobile/Cell Number:</label></span>
    <span><input type="text" id="mobile" name="mobile" placeholder="Mobile/Cell Number" value="" /></span>
    </div>

    <div class="dv">
    <span class="text"><label>Hash:</label></span>
    <span><input type="text" id="hash" name="hash" placeholder="Hash" value="" /></span>
    </div>

                                                            <button class="btn btn-xs"
                                                                    style=" background:#94c348; font-size:13px; width:100%;color:#FFFFFF" type="submit" value="Pay" onclick="launchBOLT(); return false;">
                                                                Make Payment
                                                            </button>
                                                        </form>
    <?php } ?>


    <script type="text/javascript"><!--
     $('#payment_form').bind('keyup blur', function(){
        debugger;
         $.ajax({
          url: 'profile.php',
          type: 'post',
          data: JSON.stringify({ 
            key: $('#key').val(),
            salt: $('#salt').val(),
            txnid: $('#txnid').val(),
            amount: $('#amount').val(),
            pinfo: $('#pinfo').val(),
            fname: $('#fname').val(),
            email: $('#email').val(),
            mobile: $('#mobile').val(),
            udf5: $('#udf5').val()
          }),
          contentType: "application/json",
          dataType: 'json',
          success: function(json) {
            debugger;
            if (json['error']) {
             $('#alertinfo').html('<i class="fa fa-info-circle"></i>'+json['error']);
            }
            else if (json['success']) { 
                $('#hash').val(json['success']);
            }
          }
        }); 
    });
//-->
</script>
   <script type="text/javascript"><!--
    function launchBOLT()
    {
         alert("hi");
        bolt.launch({
        key: $('#key').val(),
        txnid: $('#txnid').val(), 
        hash: $('#hash').val(),
        amount: $('#amount').val(),
        firstname: $('#fname').val(),
        email: $('#email').val(),
        phone: $('#mobile').val(),
        productinfo: $('#pinfo').val(),
        udf5: $('#udf5').val(),
        surl : $('#surl').val(),
        furl: $('#surl').val(),
        mode: 'dropout' 
       },{ responseHandler: function(BOLT){
        console.log( BOLT.response.txnStatus );     
       if(BOLT.response.txnStatus != 'CANCEL')
         {
            //Salt is passd here for demo purpose only. For practical use keep salt at server side only.
                 var fr = '<form action=\"'+$('#surl').val()+'\" method=\"post\">' +
        '<input type=\"hidden\" name=\"key\" value=\"'+BOLT.response.key+'\" />' +
        '<input type=\"hidden\" name=\"salt\" value=\"'+$('#salt').val()+'\" />' +
        '<input type=\"hidden\" name=\"txnid\" value=\"'+BOLT.response.txnid+'\" />' +
        '<input type=\"hidden\" name=\"amount\" value=\"'+BOLT.response.amount+'\" />' +
        '<input type=\"hidden\" name=\"productinfo\" value=\"'+BOLT.response.productinfo+'\" />' +
        '<input type=\"hidden\" name=\"firstname\" value=\"'+BOLT.response.firstname+'\" />' +
        '<input type=\"hidden\" name=\"email\" value=\"'+BOLT.response.email+'\" />' +
        '<input type=\"hidden\" name=\"udf5\" value=\"'+BOLT.response.udf5+'\" />' +
        '<input type=\"hidden\" name=\"mihpayid\" value=\"'+BOLT.response.mihpayid+'\" />' +
        '<input type=\"hidden\" name=\"status\" value=\"'+BOLT.response.status+'\" />' +
        '<input type=\"hidden\" name=\"hash\" value=\"'+BOLT.response.hash+'\" />' +
        '</form>';
            var form = jQuery(fr);
            jQuery('body').append(form);                                
            form.submit();
        }
     },
         catchException: function(BOLT){
             alert( BOLT.message );
         }
   });
    }

    </script>

在payumoney提供的代码上,当填写所有表单数据时,哈希代码会自动创建, 从表单数据创建哈希值是否需要任何额外的代码?

有帮助吗?预先感谢

0 个答案:

没有答案