简体   繁体   English

Firebase的云功能:测试购买时触发购买

[英]Cloud Functions for Firebase: purchase trigger on test purchase

I'm trying to implement purchase verification using Cloud Functions for Firebase. 我正在尝试使用Cloud Functions for Firebase实施购买验证。 Here is my index.js 这是我的index.js

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.updateDbOnPurchase = functions.analytics.event('in_app_purchase').onLog(event => {
    const uid = event.data.user.userId;
    const famKey = getFamKey(uid)
    console.log("UID: ${uid}, famKey: ${famKey}")
    admin.database().ref('/users/${uid}/famKey').then(snap => {
        if (snap.exists()) {
            admin.database().ref('/families/${famKey}/paydata/expire').set(Math.round(new Date().getTime()/1000) + 2592000)
        }
    });
});

In my app I implemented In-App subscription, pushed APK to alpha track and made test purchase. 在我的应用中,我实现了应用内订阅,将APK推送到Alpha跟踪并进行了测试购买。 But this code never triggered. 但是此代码从未触发过。

So, I have following questions: 因此,我有以下问题:

  1. Does In-App subscription works with in_app_purchase event? 应用内订阅可与in_app_purchase事件一起使用吗?

  2. Is it works with test purchases? 它适用于测试购买吗? Or I must test on real purchase? 还是我必须对真实购买进行测试?

  3. Will event be triggered on subscription renewal? 续订会触发事件吗?

  4. Is it possible to get purchase SKU in this code? 是否可以用此代码购买SKU?

  5. In case of pirate using Freedom / Lucky Patcher will this code be triggered? 如果使用Freedom / Lucky Patcher进行盗版,是否会触发此代码? Does Firebase performs purchase verification over Google Play, or I must implement it myself? Firebase是否通过Google Play执行购买验证,还是我必须自己实施验证?

With a month delay (long time after I finished implementing it using Database trigger), I received answer from Firebase support: 有了一个月的延迟(我完成使用数据库触发器实施它的时间很长),我收到了Firebase支持的答复:

Hi Dima, 嗨Dima,

Sorry for the delay in my response. 很抱歉延迟回复。 Please see the answers to your questions below: 请在下面查看您问题的答案:

  1. Does In-App subscription works with in_app_purchase event? 应用内订阅可与in_app_purchase事件一起使用吗?

In-App subscription does not trigger the in_app_purchase event, since no renewal, refunds, monthly/early subscriptions are counted towards in_app_purchases. 应用内订阅不会触发in_app_purchase事件,因为没有续订,退款,每月/早期订阅都计入in_app_purchases。

  1. Is it works with test purchases? 它适用于测试购买吗? Or I must test on real purchase? 还是我必须对真实购买进行测试?

Firebase Analytics automatically filters out test purchases, so it wouldn't trigger the function's "in_app_purchase" event. Firebase Analytics自动过滤掉测试购买,因此不会触发该函数的“ in_app_purchase”事件。

  1. Will event be triggered on subscription renewal? 续订会触发事件吗?

Subscription renewal will not trigger the "in_app_purchase" event because In-App Subscription does not trigger the "in_app_purchase" event. 订阅续订不会触发“ in_app_purchase”事件,因为应用内订阅不会触发“ in_app_purchase”事件。

  1. Is it possible to get purchase SKU in this code? 是否可以用此代码购买SKU?

I assume that what you want to obtain is the product ID. 我假设您要获取的是产品ID。 You can obtain the product ID by accessing the event.user.appInfo properties from the function. 您可以通过从函数访问event.user.appInfo属性来获取产品ID。

  1. In case of pirate using Freedom / Lucky Patcher will this code be triggered? 如果使用Freedom / Lucky Patcher进行盗版,是否会触发此代码? Does Firebase performs purchase verification over Google Play, or I must implement it myself? Firebase是否通过Google Play执行购买验证,还是我必须自己实施验证?

Firebase Analytics performs some measure of purchase verification on both iOS and Android. Firebase Analytics在iOS和Android上执行某种形式的购买验证。 However, this only affects your analytics data. 但是,这只会影响您的分析数据。 If you want to combat piracy in your app, you need to implement verification yourself. 如果您想打击应用程序中的盗版行为,则需要自己实施验证。

Let me know if you have any other questions. 如果您还有其他问题,请告诉我。

Hope, this will be useful for someone 希望这对某人有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM