Am I getting these steps right for checking a user's in-app billing subscription?
I am making an Android app that sells an in-app monthly subscription. Before I dive into it too much, does this outline of how this should be done seem about right? I am using the Google Play Android Developer API.
The first time the app is installed, send the following in sendBillingRequest():
- CHECK_BILLING_SUPPORTED. If not, don't bother making the "buy" UI.
- RESTORE_TRANSACTIONS. If there were transactions, save the user's purchase token.
When the user makes a purchase:
- Save the purchase token.
- Send a GET request with the purchase token to the Google Play Developer API to verify the subscription.
- If subscription is valid, save the subscription expiration and initiation dates. Provide access to purchased data.
- If subscription is not valid, remove the purchase token. Do not provide access to purchased data and draw "not purchased" version of the UI.
Each time the app is started up, check if you have a saved purchase token.
If the purchase token doesn't exist:
- Do not provide access to purchased data and draw "not purchased" version of the UI.
If the purchase token exists, check the expiration date and initiation time:
- If (expired) or (initiation was over one month ago)
- Send a GET request with the purchase token to the Google Play Developer API to verify the subscription.
- If purchase is valid, update the saved expiration and initiation dates. Provide access to purchased data.
- If purchase is not valid, remove saved purchase token and expiration and initiation data. Do not provide access and draw "not purchased" version of the UI.
- Else
- Provide access to purchased data.