我正在尝试在我的 node.js 应用程序中实现 Paypal IPN 验证。我正在使用 express 框架。
这是我的代码:
app.post('/paypal', function(req,res){
console.log("IN PAYPAL !! req.body : "+req.body);
var ipn = require('paypal-ipn');
ipn.verify(req.body, function callback(err, msg) {
if (err) {
console.log("Error:"+err);
} else {
//Do stuff with original params here
console.log("req.body.payment_status :"+req.body.payment_status+" msg: "+msg);
res.end();
if (req.body.payment_status == 'Completed') {
//Payment has been confirmed as completed
}
}
});
});
我正在使用 paypal-ipn为此。
当我尝试从 Paypal Sandbox 发送 IPN 消息时,我收到了这条消息
IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.
但是当我在 curl 的帮助下尝试从终端发送示例消息时,我在我的服务器应用程序中收到请求并且它正在显示日志
IN PAYPAL !! req.body : [object Object] req.body.payment_status :Pending msg: VERIFIED POST /paypal 200 572ms
最佳答案
我明白了。我没有在我的服务器上监听端口 443 (https)。
var https = require('https'),
fs = require('fs');
var httpsOptions = {
key: fs.readFileSync('path/to/private/key'),
cert: fs.readFileSync('path/to/certs')
}
http.createServer(app).listen(app.get('port'), function() {
console.log("server listening on port " + app.get('port'));
});
https.createServer(httpsOptions, app).listen(443,function () {
console.log("server listening on port " + 443);
});
Paypal 将 IPN 消息发送到 https 端口 443(我认为)。反正我明白了...
关于node.js - 使用 node.js 进行 Paypal IPN 验证 - express 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13621906/