PayPal IPN节点express bodyParser

我试图让贝宝ipn工作我的node.js快递应用程序,我必须validationipn的信息,一旦我收到“通过发回内容的顺序,他们收到的确切顺序和之前的命令_notify-validation”。 他们给出的例子是这样一个查询string:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate&mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&payer_id=LPLWNMTBWMFAY&tax=0.00&...&payment_gross=19.95&shipping=0.00 

但是,因为我使用bodyParser,request.body是一个json对象。 如果我要附加“cmd = _notify-validate”并将其发回,我将如何接收它作为一个简单的查询string,并发送它作为一个简单的查询string,而不会摆脱bodyParser? 我仍然需要这个路由上的jsonparsing版本来实际解释数据。 另外,在服务器端发送POST是什么样的? (我只是做res.send(str)?)

我用节点paypal-ipn模块,事实certificate一个JSONparsing的机构是好的。 我使用这个模块的主要问题是确保使用res.send(200)做出响应,否则paypal的ipn会不停地发送消息大约一分钟。 以下是帮助的代码:

 exports.ipn = function(req,res){ var params = req.body res.send(200); ipn.verify(params, function callback(err, msg) { if (err) { console.log(err); return false } if (params.payment_status == 'Completed') { // Payment has been confirmed as completed // do stuff, save transaction, etc. } }); } 

既然你问过如何做一个HTTP POST请求,这就是你怎么做的。

 var options = { host: 'example.com', port: '80', path: '/pathname', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length } }; var post_req = http.request(options, function (res) { res.setEncoding('utf8'); var chunks = ''; res.on('data', function (chunk) { chunks += chunk; }); res.on('end', function() { console.log(chunks); }); }); post_req.write(post_data); post_req.end(); 

我也为这个IPN努力工作了一两天。 我有一个类似的问题与bodyparser和url编码。

以下是NodeJS中的一些工作示例代码,用于监听传入的IPN消息并根据Paypal沙箱进行validation。

https://github.com/HenryGau/node-paypal-ipn

您可以在tests文件夹中通过mocha subscriptionMessage.js运行subscriptionMessage.js来模拟/模拟PayPal IPN消息。

希望能帮助到你。

Interesting Posts