简体   繁体   English

Android 应用内计费订阅状态更改回调

[英]Android In-App Billing Subscription status change callbacks

I'm writing an app that will support in-app subscriptions.我正在编写一个支持应用内订阅的应用。 The subscriptions will enable my users to use a number of services and benefits outside the Android world.订阅将使我的用户能够使用 Android 世界之外的许多服务和好处。 I know that I can use Google Play Developer API to query the status of a subscription, but due to the nature of the offered services and benefits, it is not very convenient to do that.我知道我可以使用 Google Play Developer API 来查询订阅的状态,但是由于所提供的服务和好处的性质,这样做不是很方便。 I was wondering if there is a way to get notified about the status of the subscription when it changes.我想知道是否有办法在订阅更改时获得有关订阅状态的通知。 Something like a web hook for example.例如,类似网络钩子的东西。

I wanted to post a comment in response to yours, but apparently this was too long.我想发表评论以回应您的评论,但显然这太长了。 In addition to that, it is also kind of an answer to your question, so I thought this might be a good thing to just post it as an answer instead.除此之外,它也是对您问题的一种回答,所以我认为将其作为答案发布可能是一件好事。 Maybe it even solves your problem.也许它甚至可以解决您的问题。

So, regarding your comment.所以,关于你的评论。 You don't necessarily have to do it that way.您不一定必须这样做。 Now, I don't know your system requirements, but I'll just share mine and hope it helps you out.现在,我不知道您的系统要求,但我只是分享我的,希望对您有所帮助。

Save Users and Subscriptions on your server (database tables).在您的服务器上保存UsersSubscriptions (数据库表)。 Have a check_at column on the Subscriptions table, besides a renew_at one.check_at对列Subscriptions表,除了一个renew_at之一。 Suppose the user has a monthly subscription created on the 1st of January.假设用户在 1 月 1 日创建了每月订阅。 On that first day, you call your server from Android after the purchase is finished, save the subscription details, then set renew_at as February 1st and check_at as February 4th, considering you set 3 days as delay for transaction failure in Google Play Developer Console.在那第一天,你叫从Android的服务器的购买完成后,保存的订阅详细信息,然后集renew_at为2月1日和check_at为2月4日,考虑到你集3天为延迟在谷歌Play开发者控制台的交易失败。 This way, the user has time from 1st February to 3rd February to change credit card details if the payment fails on the 1st.这样,如果在 1 日付款失败,用户就有时间从 2 月 1 日到 2 月 3 日更改信用卡详细信息。 Then on the 4th you will check the Google Play API for subscription details.然后在 4 日,您将检查 Google Play API 以获取订阅详细信息。 But don't disable premium functionality during 1st-4th February.但不要在 2 月 1 日至 4 日期间禁用高级功能。 Disable it on the 4th if the subscription was canceled.如果订阅被取消,请在 4 日禁用它。 This way, premium content is not delayed nor tampered with in any way.这样,优质内容不会以任何方式延迟或篡改。 If the subscription end date returned by the API is in the future, then it was renewed, so you should keep premium activated.如果 API 返回的订阅结束日期在未来,则它已续订,因此您应该保持高级激活状态。 Now, how do you check it monthly on the 4th you may ask.现在,您可能会问,您如何在每月 4 日检查它。 Use some kind of scheduler to schedule tasks on the database.使用某种调度程序来调度数据库上的任务。

This way you remove the need to rely on webhooks.通过这种方式,您无需依赖网络钩子。 Although I agree, webhooks would've been more efficient and probably even easier to implement.虽然我同意,但 webhooks 会更有效率,而且可能更容易实现。

Let me know if you have any questions or there are some flaws in the system I described.如果您有任何问题或我描述的系统中存在一些缺陷,请告诉我。

Take a look at Real Time Notifications using Google Cloud's PubSub service.查看使用 Google Cloud 的 PubSub 服务的实时通知 It sends notifications of payment/subscription events like: new buy, renewal, cancellation etc. It includes the token which can be used to retrieve additional info from the API like you do now.它发送付款/订阅事件的通知,例如:新购买、续订、取消等。它包括可用于从 API 检索附加信息的令牌,就像您现在所做的那样。

You can also configure this PubSub Subscription to call a custom webhook (which still needs to query the PubSub) on each message that you receive.您还可以将此 PubSub 订阅配置为对您收到的每条消息调用自定义 webhook(仍需要查询 PubSub)。

You can use our service https://qonversion.io to track all your subscription events both on Android and iOS, and send the events with web hooks just where you need it.您可以使用我们的服务https://qonversion.io跟踪您在 Android 和 iOS 上的所有订阅事件,并在您需要的地方发送带有网络钩子的事件。 Plus there are a number of out of the box integrations like Amplitude, AppsFlyer, Facebook ads and many more...此外,还有许多开箱即用的集成,如 Amplitude、AppsFlyer、Facebook 广告等等......

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

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