firebase-realtime-database - 如何将 Paypal IPN 分派(dispatch)到 Google Cloud 函数?

标签 firebase-realtime-database paypal google-cloud-functions paypal-ipn

我读过 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.
});

它将在 https://www.YOUR-FIREBASE-DOMAIN.com/ipn 中可用

关于firebase-realtime-database - 如何将 Paypal IPN 分派(dispatch)到 Google Cloud 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634222/

相关文章:

ios - 错误 IOS 10 - 无法从 https ://mesu. apple.com/assets/for asset type com.apple.MobileAsset.TextInput.SpellChecker 复制 Assets 信息

android - 如何从 firebase 中的值中获取键

PayPal Rest API - 添加订阅计费协议(protocol)

google-cloud-dataflow - 值(value)提供者问题

javascript - 一旦 ("child_added")在非现有节点上不会失败但超时

javascript - 在 React componentDidMount 中使用 child_added 通过 key 访问 firebase 数据

java - 多次初始化 FirebaseDatabase.getInstance() 是否会影响性能?

用于类似亚马逊网站的 Paypal Masspay API

ios - 错误 - Paypal 中的 "The merchant does not accept payments of this type"

firebase - Cloud Functions for Firebase - 无法部署(操作中断。)