Google in-app billing: How to get the information about subscription renewal in the backend?
I have an Android app and a backend server as service for the app. With in-app billing, the app user can gain extra features and access to a cloud, managed by the backend server and so on. The Google In-app billing API describes how to purchase in-app products and how to secure them, but the renewal process seems to be very ill-conceived.
If a subscription will be renewed automatically, the following happens:
Billing continues indefinitely at the interval and price specified for the subscription. At each subscription renewal, Google Play charges the user account automatically, then notifies the user of the charges afterward by email. For monthly and annual subscriptions, billing cycles will always match subscription cycles, based on the purchase date. (Seasonal subscriptions are charged annually, on the first day of the season.)
When the subscription payment is approved, Google Play provides a purchase token back to the purchasing app through the In-app Billing API. Your apps can store the token locally or pass it to your backend servers, which can then use it to validate or cancel the subscription remotely using the Google Play Developer API.
My backend will check the expiry date by the latest purchase token (delivered by the initial purchase) and will recognize that the purchase is expired. If the user does not repurchase, it will delete all the user's data within one month.
How does Google think that I get this information on the backend server if the user never opens the app? The only thing that this Google Play Developer API returns, is the whole subscription with the expiry time and a lot of other fields, but I need to pass the purchaseToken as parameter. I don't know the new purchaseToken as long as the user does not open the APP (and indirectly sends it to the backend). I already think about implementing an Android service or something similar which continously invokes
getPurchases() and sends the information to the backend (which is pretty resource-intensive). Even if he opens the app, figuring out what the expiry time of his latest active subscription is, is pretty error-prone, not to mention, that I somehow have to figure out in the backend, what purchase record is valid now and if he even extended his subscription. AS I understand it right, after renewal, there are at least two purchase entries (one for the initial purchase, one for the renewal and I wonder, if the initial purchase record will receive any change, for example the creation date or expiry date. Lot's of obscurities at the moment).
To cut a long story short, is there a clean concept about handling this use case 'Figuring out if the user renewed his subscription' properly?