从publates.subscriptionsv2.get获取用户数据

发布于 2025-02-13 12:21:13 字数 2409 浏览 1 评论 0原文

我正在使用Firebase作为后端构建一个Android应用程序。 Firebase将用于身份验证,存储,Firebase数据库中的某些数据以及使用云功能。

subsriptions 在我的应用程序中,在我的应用程序中,带有Google Play Play Billing Billing Billing库V5。

购买和确认订阅后,我想进行一些服务器端验证,在此开始我的问题。我创建了云功能 - 谢谢你们 - 到酒吧/子主题并验证订阅,我称为 google api-方法: a>。成功响应后,我想将此数据写入我的数据库。 响应我得到的这里

这是一个功能:

exports.insertFromPubSubTopic = functions.pubsub.topic('mytopic').onPublish(async(message, context) => {
if (message.json.subscriptionNotification) {
    console.log("ok - we have message.json.subscriptionNotification")
    try {
        await authClient.authorize();
        const subscription = await playDeveloperApiClient.purchases.subscriptionsv2.get({
            packageName: data.packageName,
            token: data.subscriptionNotification.purchaseToken
        });

        if (subscription.status === 200) {
            // Subscription response is successful.
            console.log("subscription.status===200")
            var message = {
                'data': data
            }
            return firestore.collection('billing-verified').add(message)
        }
    } catch (error) {
          // Logging error for debugging
        console.log(error)
    }
    return {
        status: 500,
        message: "Failed to verify subscription, Try again!"
    }
} else {
    console.log('Test event... logging test');
    //return admin.firestore().collection('mp-billing-messages-error').add(data)
    return firestore.collection('mp-billing-messages-error').add(data)
}
})

我的问题是:如何从成功返回的订阅对象中获取用户的数据,以便我可以存储在Firestore数据库类似 - 此购买是由该用户进行的。

我知道Firebase和Google Playbilling与众不同,并且具有不同的目的和功能。但是,假设我有没有在我的应用中登录的匿名用户。因此,我对她一无所知,到目前为止无法在Firebase中识别她。然后她得到并购买了订阅。有人对如何从经过验证的购买对象获取有关此用户的数据有什么建议?任何建议都会有所帮助。

I am building an Android App, using Firebase as Backend. Firebase will be used for authentication, storage, some data in firebase database, and also using cloud functions.

There are subsriptions in my app with Google Play Billing Library v5.

After the subscription is purchased and acknowledged, I'd like to do some server side verification, where my problems begin. I have created cloud function - thank you guys - that listens to pub/sub topic and to verify the subscription I call the google api - Method: purchases.subscriptionsv2.get . After the successful response, I'd like to write this data to my database.
Response I get is ok in the form of JSON object like here

This is the function:

exports.insertFromPubSubTopic = functions.pubsub.topic('mytopic').onPublish(async(message, context) => {
if (message.json.subscriptionNotification) {
    console.log("ok - we have message.json.subscriptionNotification")
    try {
        await authClient.authorize();
        const subscription = await playDeveloperApiClient.purchases.subscriptionsv2.get({
            packageName: data.packageName,
            token: data.subscriptionNotification.purchaseToken
        });

        if (subscription.status === 200) {
            // Subscription response is successful.
            console.log("subscription.status===200")
            var message = {
                'data': data
            }
            return firestore.collection('billing-verified').add(message)
        }
    } catch (error) {
          // Logging error for debugging
        console.log(error)
    }
    return {
        status: 500,
        message: "Failed to verify subscription, Try again!"
    }
} else {
    console.log('Test event... logging test');
    //return admin.firestore().collection('mp-billing-messages-error').add(data)
    return firestore.collection('mp-billing-messages-error').add(data)
}
})

My question is: How do I get user's data from successfully returned subscription object, so that I can store in firestore database something like - this purchase was made by this user.

I know Firebase and GooglePlayBilling are not related and have different purposes and functionalities. But let's say I have anonymous user who did not login in my app. So I don't know anything about her and cannot identify her in firebase so far. And then she gets and buys the subscription. Does anyone have any suggestions of how do I get the data about this user from verified purchased object?? Any suggestion would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文