PayuMoney India 与 Node js 的集成

PayuMoney India integration with Node js

我正在尝试集成一个 nodejs 应用程序以与 PayUMoney 集成。我遵循 php 的说明和示例代码并在 node.js 中实施,但我收到 校验和错误

Error. We are sorry we are unable to process your payment.

Checksum Failed. Please contact your merchant.

这是代码。前端

<form method="post" id="payu-payment-form" action="https://test.payu.in/_payment">
    <input type="hidden" name="hash" value="hash"/>
    <input type="hidden" name="key" value="marchentKey"/>
    <input type="hidden" name="txnid" value="asc123"/>
    <input type="hidden" name="amount" value="1000" />
    <input type="hidden" name="productinfo" value="Product 1"/>
    <input type="hidden" name="firstname" value="Amit" />
    <input type="hidden" name="email" value="abc@gmail.com" />
    <input type="hidden" name="phone" value="123423233" />
    <input type="hidden" name="surl" value="http://localhost/success"/>
    <input type="hidden" name="furl" value="http://localhost/fail"/>
    <input type="hidden" name="service_provider" value="payu_paisa" />
    <button class="" type="submit" formtarget="_blank" >Buy</button>
</form>

Node.js

var txnid='asc123';
var amount=1000;
var produnctinfo='Product 1';
var firstname='Amit';
var email='abc@gmail.com';
var phone='123423233';
var surl='http://localhost/success';
var furl='http://localhost/fail';
var service_provider='payu_paisa';
var string = marchentKey +'|' +txnid+ '|' +amount+'|'+productinfo+'|'+firstname+'|'+email+'|'+phone+'|'+ surl +'|'+furl+'|'+service_provider+'|||||||'+salt;
var hash=sha512(string);

我认为问题出在您使用自定义名称发布用户定义变量。 使用 udf1 而不是使用 service_provider.

<form method="post" id="payu-payment-form" action="https://test.payu.in/_payment">
    <input type="hidden" name="hash" value="hash"/>
    <input type="hidden" name="key" value="marchentKey"/>
    <input type="hidden" name="txnid" value="asc123"/>
    <input type="hidden" name="amount" value="1000" />
    <input type="hidden" name="productinfo" value="Product 1"/>
    <input type="hidden" name="firstname" value="Amit" />
    <input type="hidden" name="email" value="abc@gmail.com" />
    <input type="hidden" name="surl" value="http://localhost/success"/>
    <input type="hidden" name="furl" value="http://localhost/fail"/>
    <input type="hidden" name="phone" value="123423233" />
    <input type="hidden" name="udf1" value="payu_paisa" />
    <button class="" type="submit" formtarget="_blank" >Buy</button>
</form>

哈希计算

hash=sha512(key|txnid|amount|productinfo|firstname|email|udf1||||||||||SALT);

PHP 集成工具包中的测试密钥和 Salt 无法正常工作。所以使用我自己的测试密钥和盐并计算正确的散列它工作正常。

之前我使用 phone、surl、furl 和 service_provider 计算哈希值。不过应该是这样的

var string = marchentKey +'|' +txnid+ '|' +amount+'|'+productinfo+'|'+firstname+'|'+email+'|||||||||||'+salt;
var hash=sha512(string);

如果您发布的变量在其文档中未提及,即用户定义的变量,那么您应该将这些变量包括为 udf1、udf2..

var string = marchentKey +'|' +txnid+ '|' +amount+'|'+productinfo+'|'+firstname+'|'+email+'|'+udf1+'|'+udf2+'|||||||||'+salt;
var hash=sha512(string);

var service_provider='';

将服务提供商字段留空。 应该可以。