我读过这里 ,它是可以直接发送IPN到谷歌云功能。 我对火力地堡上运行的index.js文件我的谷歌云功能。
我建立了我的PayPal按钮的IPN发送到网页上我的web应用程序。
下面是我跑断谷歌云功能/火力地堡的功能中的一个例子:
// UPDATE ROOMS INS/OUTS
exports.updateRoomIns = functions.database.ref('/doors/{MACaddress}').onWrite((change, context) => {
const beforeData = change.before.val();
const afterData = change.after.val();
const roomPushKey = afterData.inRoom;
const insbefore = beforeData.ins;
const insafter = afterData.ins;
if ((insbefore === null || insbefore === undefined) && (insafter === null || insafter === undefined) || insbefore === insafter) {
return 0;
} else {
const updates = {};
Object.keys(insafter).forEach(key => {
updates['/rooms/' + roomPushKey + '/ins/' + key] = true;
});
return admin.database().ref().update(updates); // do the update}
}
return 0;
});
现在的问题:
1)我想尽快添加其他功能,从贝宝处理IPN,因为我有一个交易。 我将如何去吗?
如果解决了第一个问题,我会庆祝的答案是正确的。
2)怎么会,谷歌的云功能,甚至是什么样子?
我将创建另外一个问题,如果你能解决这个问题之一。
请注意我用的火力地堡(没有其他的数据库也PHP)。
IPN仅仅是试图达到给定的端点的服务器。
首先,你必须确保你的火力计划支持第三方请求(它是在免费的计划不可用)。
在此之后,你需要做一个HTTP端点,就像这样:
exports.ipn = functions.http.onRequest((req, res) => {
// req and res are instances of req and res of Express.js
// You can validate the request and update your database accordingly.
});
它将提供https://www.YOUR-FIREBASE-DOMAIN.com/ipn
基于@Eliya科恩回答:
你的火力点函数创建一个函数,例如:
exports.ipn = functions.https.onRequest((req, res) => {
var reqBody = req.body;
console.log(reqBody);
// do something else with the req.body i.e: updating a firebase node with some of that info
res.sendStatus(200);
});
当您部署功能,去你的火力控制台项目和检查功能。 你应该有这样的事情:
复制该网址,去贝宝,修改要触发购买按钮,向下滚动到第3步,并在底部类型:
notify_url = 这里粘贴URL
保存更改。
您现在可以测试您的按钮,并检查您的火力点云功能登录选项卡上的req.body。
感谢这里的答案,尤其是这个要点: https://gist.github.com/dsternlicht/fdef0c57f2f2561f2c6c477f81fa348e ,
..终于研究出了解决办法,以验证在云FUNC IPN的要求:
let CONFIRM_URL_SANDBOX = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
exports.ipn = functions.https.onRequest((req, res) => {
let body = req.body;
logr.debug('body: ' + StringUtil.toStr(body));
let postreq = 'cmd=_notify-validate';
// Iterate the original request payload object
// and prepend its keys and values to the post string
Object.keys(body).map((key) => {
postreq = `${postreq}&${key}=${body[key]}`;
return key;
});
let request = require('request');
let options = {
method: 'POST',
uri : CONFIRM_URL_SANDBOX,
headers: {
'Content-Length': postreq.length,
},
encoding: 'utf-8',
body: postreq
};
res.sendStatus(200);
return new Promise((resolve, reject) => {
// Make a post request to PayPal
return request(options, (error, response, resBody) => {
if (error || response.statusCode !== 200) {
reject(new Error(error));
return;
}
let bodyResult = resBody.substring(0, 8);
logr.debug('bodyResult: ' + bodyResult);
// Validate the response from PayPal and resolve / reject the promise.
if (resBody.substring(0, 8) === 'VERIFIED') {
return resolve(true);
} else if (resBody.substring(0, 7) === 'INVALID') {
return reject(new Error('IPN Message is invalid.'));
} else {
return reject(new Error('Unexpected response body.'));
}
});
});
});
同时也感谢:
收到PayPal IPN消息数据,您的听众必须遵循这个请求 - 响应流程:
监听监听,贝宝与每个事件发送HTTPS POST IPN消息。 来自PayPal接收IPN消息后,监听器返回一个空的HTTP 200响应于贝。 否则,贝宝重新发送IPN消息。 监听使用HTTPS POST发送完整的消息回PayPal。
前缀与CMD = _notify-验证变量返回的消息,但不改变的消息字段,所述字段的顺序,或从原来的消息的字符编码。