如何将Paypal IPN分配给Google Cloud功能? [英] How to dispatch a Paypal IPN to a Google Cloud function?

查看:153
本文介绍了如何将Paypal IPN分配给Google Cloud功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读此处,它可以发送IPN直接连接到Google云功能.我在index.js文件上的Firebase上运行了我的Google Cloud函数.

I've read here that it's possible to send an IPN directly to a Google cloud function. I have my Google Cloud functions running on Firebase on an index.js file.

我已经设置了Paypal按钮,以将IPN发送到Web应用程序上的页面.

I've set up my Paypal buttons to send the IPN to a page on my webapp.

以下是我正在使用Google Cloud Functions/Firebase运行的功能之一的示例:

Here is an example of one of the functions I'm running off 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.我将如何处理?

1) I want to add another function to process IPN from Paypal as soon as I have a transaction. How would I go about this?

如果解决了第一个问题,我会将答案标记为正确.

2)谷歌云的功能看起来如何?

2) how would that Google cloud function even look like?

如果您能解决这个问题,我将创建另一个问题.

请注意,我正在使用Firebase(没有其他数据库或PHP).

Note I am using Firebase (no other databases nor PHP).

推荐答案

IPN只是试图到达给定端点的服务器.

IPN is simply a server that tries to reach a given endpoint.

首先,您必须确保您的Firebase计划支持第三方请求(免费计划中不可用).

First, you have to make sure that your firebase plan supports 3rd party requests (it's unavailable in the free plan).

之后,您需要创建一个http终结点,如下所示:

After that, you need to make an http endpoint, like so:

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

这篇关于如何将Paypal IPN分配给Google Cloud功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆