【发布时间】:2015-07-21 20:08:52
【问题描述】:
在我目前使用MEAN 堆栈的实现中,对于选择在线支付的客户,我创建了一个像这样的超链接。
<div>
<a class="btn btn-pram-primary btn-block" href="node/public/orders">Online Payment</a>
</div>
我用闲置代码在节点中截取这个 url。
var sendRequestToPayU = function( req, res, next ) {
console.log('In sendRequestToPayU' );
var post_data = querystring.stringify({
'txnid': '1',
'amount': '100',
'productinfo' : 'ABCD',
'firstname' : 'UserName',
'email' : 'user@user.com',
'phone' : '9876543210'
});
request({
url: 'https://test.payu.in/_payment', //URL to hit
method: 'POST',
headers: {
'Content-Type': 'MyContentType',
'Content-Length': post_data.length
},
body: post_data //Set the body as a string
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
res.html(body).send();
}
});
};
为了正确支付,控制权应该转移到支付网关站点,但是在上面编码的过程中,我不确定如何将控制权重定向到支付网关?
是否应该在浏览器上处理,而不是通过创建表单和表单操作应该是支付网关的 URL?
如果我遵守这条规则?我的盐和商家 ID 不应该对客户可见吗?
请建议我适当的方式来追求这一点。
【问题讨论】:
-
对您自己的站点执行操作的表单怎么样,您使用后端处理付款 -> 第三方网关。但是,大多数第 3 方支付都有自己的嵌入式平台,可以轻松地包含在您的网站中。
-
问题是我不知道如何从快递/节点服务器发送发布请求,以便我的客户登陆支付网关页面。
-
因此,您需要一个中间件来执行其他操作,例如联系第 3 方服务器。我喜欢使用来自 npm 的
request模块,但还有其他选择。有了请求,我只需要编写request.post('http://example.com', responseHandler).form(formData);This is an example 脚本来查询第 3 方服务器。 -
我的问题是将收到的来自支付网关的响应发送给客户端。它应该像重定向一样。
-
您可以通过使用您的角度
$http服务成功回调来做到这一点。因此,您通过$http服务发送客户端拥有的任何信息,并使用第 3 方响应进行回复。$http => express => 3rd party => express => $http