简体   繁体   English

Cloud Function Firebase 添加内购的解决方法

[英]Cloud Function Firebase solution to adding in app purchases

I am building a Flutter app that uses Firebase as its backend, everything works with cloud functions.我正在构建一个 Flutter 应用程序,它使用 Firebase 作为其后端,一切都适用于云功能。 I am trying to implement in-app purchases.我正在尝试实施应用内购买。 I want the app to work like this:我希望应用程序像这样工作:

The user buys a subscription -> User in Firestore becomes a Premium User用户购买订阅 -> Firestore 中的用户成为高级用户

When any event happens with his subscription like it reaching the end it should update the status of the user in Firestore.当他的订阅发生任何事件(如订阅结束)时,它应该更新 Firestore 中的用户状态。

I've searched a lot with solutions like Adapty but I do not quite understand how to implement a server-side call to a cloud function of mine that will update the user on Firestore depending on its subscription state. I see there should be some client-side code that checks if the user is still subscribed, but I do not want that at all, I want everything to be done server-side, so it's secure.我用 Adapty 之类的解决方案进行了很多搜索,但我不太了解如何实现对我的云 function 的服务器端调用,该调用将根据其订阅 state 更新 Firestore 上的用户。我看到应该有一些客户端- 检查用户是否仍然订阅的端代码,但我根本不想要那个,我希望一切都在服务器端完成,所以它是安全的。 After the user pays, the server should handle all the updates in Firestore, the client just needs to get the data about the user being premium in Firestore or not.用户付费后,服务器要处理Firestore中的所有更新,客户端只需要获取用户在Firestore中是否付费的数据即可。

I thought that you could do a cloud function that takes care of billing directly, but I do not know how I could connect Flutter purchases to a cloud function without going through the insecure client side.我以为你可以做一个云 function 直接负责计费,但我不知道如何在不通过不安全的客户端的情况下将 Flutter 购买连接到云 function。

How should I model this?我应该怎么model这个? It seems to be very simple but I do not quite understand how to implement such a simple subscription system with Firebase Cloud Functions.看起来很简单,但是我不太明白如何用Firebase Cloud Functions实现这么简单的订阅系统。 I think it all goes down to being able to implement some kind of automated call to a cloud function when something happens to the user subscription, but how can I do that?我认为这一切都归结为能够在用户订阅发生问题时实现对云 function 的某种自动调用,但我该怎么做呢? I am open to any technology that implements such a billing model that works on Flutter and Firebase Cloud Functions.我对任何实现这种在 Flutter 和 Firebase Cloud Functions 上运行的计费 model 的技术持开放态度。

To implement a server-side call to a cloud function and update the user on Firestore with Cloud Functions, you can handle events in Cloud Firestore with no need to update client code and can make Cloud Firestore changes via the DocumentSnapshot interface.要实现对云 function 的服务器端调用并使用 Cloud Functions 在 Firestore 上更新用户,您可以在 Cloud Firestore 中处理事件而无需更新客户端代码,并且可以通过DocumentSnapshot接口进行 Cloud Firestore 更改。 You can find the detailed documentation here .您可以在此处找到详细的文档。

Also as per your requirements you can check the codelab .另外,根据您的要求,您可以查看代码实验室

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

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