【发布时间】:2019-08-26 04:37:03
【问题描述】:
我一直在尝试使用 AWS Api Gateway 来实现 Paypal 的 IPN,以获取 IPN 处理程序 url。该 api 与作为“接收器”的 Lambda 函数集成。
我已经使用 Paypal 的 IPN 模拟器测试了 api 网关 url。它适用于第一步,我收到此消息“IPN 已发送并且握手已验证”。
我现在的问题是下一步,我必须使用 HTTPS 帖子将收到的消息发送回 Paypal。我试了很多次,一直报这个错误:
{
"code": "ECONNREFUSED",
"errno": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 443
}
如果能帮我解决这个问题,我真的很感激。
我使用的是 node.js 8.10。这是我的 Lambda 函数:
exports.handler = (event, context, callback) => {
console.log('Received event:', JSON.stringify(event, null, 2));
// Return 200 to caller
console.log('sending 200 back to paypal');
callback(null, {
statusCode: '200'
});
// Read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
console.log('modifying return body...');
var body = 'cmd=_notify-validate&' + event.body;
callHttps(body, context);};
function callHttps(body, context) {
console.log('in callHttp()....');
var https = require('https');
var options = {
url: 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr',
method: 'POST',
headers: {
"user-agent": "Nodejs-IPN-VerificationScript"
},
body: body
};
const req = https.request(options, (res) => {
res.on('data', (chunk) => {
// code to execute
console.log("on data - can execute code here....");
});
res.on('end', () => {
// code to execute
console.log("on end - can execute code here....");
});
});
req.on('error', (e) => {
console.log("Error has occured: ", JSON.stringify(e, null, 2));
});
req.end();}
【问题讨论】:
标签: post https aws-lambda paypal-ipn