I have an Android app with one in-app purchase users can buy.
As per Google documentation, I run queryPurchases()
at startup to check whether the app should start as free version or paid version.
Here's the doc from Google:
Call queryPurchases() at least twice in your code:
Every time your app launches so that you can restore any purchases that a user has made since the app last stopped.
In your onResume() method because a user can make a purchase when your app is in the background (for example, redeeming a promo code in Play Store app).
The local Google Play service caches the user purchases so the function works even in offline mode.
I've done it and it works great.
However, if I clear the cache of the Google Play app or I wait 8-12 hours in offline mode the queryPurchases()
method returns an error (the method is unable to fetch purchases because the local Google Play cache expired). If I reconnect the device to the network I get everything working again.
Now, looking online for a solution, it seems highly discouraged to store the inapp purchases locally on the app internal storage to cope with this problem.
My app is meant to be used offline but I don't like the idea of reverting it to free version if the queryPurchases()
fails (it would be very annoying from the user point of view). Nor I like the idea of "giving the benefit of the doubt" and start in paid version if the queryPurchases()
fails (users may start exploiting this behavior).
For the time being the app just shows a popup error message asking to connect the device to the internet. Users that experience this problem (their Google Play cache get invalidated while their device is offline) are complaining that the app is not a truly offline app because they see a popup message asking them to connect to the internet, and they are right.
What should I do?
Cache the result of queryPurchases locally yourself. Then fall back to that result if offline. Then your only failure case is if someone buys something then quickly goes offline, which is a real corner case (and in that case they need to connect).