我读过 here可以将 IPN 直接发送到 Google 云功能。我的 Google Cloud 函数在 Firebase 上的 index.js 文件上运行。
我已经设置了我的 Paypal 按钮以将 IPN 发送到我的网络应用程序上的页面。
这是我在 Google Cloud Functions/Firebase 上运行的功能之一的示例:
// 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) 我想添加另一个功能,以便在我有交易时立即处理来自 Paypal 的 IPN。我该怎么做?
如果解决了第一个问题,我会将答案标记为正确。
2) Google 云功能会是什么样子?
如果你能解决这个问题,我会提出另一个问题。
请注意,我使用的是 Firebase(没有其他数据库,也没有 PHP)。
最佳答案
IPN 只是一个尝试到达给定端点的服务器。
首先,您必须确保您的 firebase 计划支持第 3 方请求(它在免费计划中不可用)。
之后,您需要创建一个 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.
});
关于firebase-realtime-database - 如何将 Paypal IPN 分派(dispatch)到 Google Cloud 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634222/