node.js - 使用 node.js 进行 Paypal IPN 验证 - express 应用程序

标签 node.js paypal express paypal-ipn paypal-sandbox

我正在尝试在我的 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/

相关文章:

asp.net-mvc-4 - 自定义 DotnetOpenauth Paypal 客户端( key 不存在)

node.js - node-websocket-server : possible to have multiple, 单独的 "broadcasts"用于单个 node.js 进程?

c++ - 将二进制字符串/文件内容从 c++ 传递到 Node js

php - Paypal : Get a response of "txn_type= recurring payment " instead of "txn_type= recurring_payment_profile_created" for the first Time

php - paypal 集成支付

node.js - 在express中使用passport-ldapauth nodejs模块进行身份验证

node.js - 如何将 Typescript 定义添加到 Express req 和 res

node.js - 语法错误 : Unexpected token import - import * as gulp from 'gulp'

javascript - for 循环和 forEach 循环在 ejs 中不起作用

node.js - ExpressJS 中的 API 错误处理和数据验证