Checking IAP status when in offline mode? (Android)

I am really struggling to find the best option of checking for valid IAP purchases when the user is offline or has no network signal. It seems that calling IAP::refresh() and IAP::restore() only work if the user has network signal and so trying to discover whether the user has unlocked levels or items is impossible. With Google API it seems you can query getPurchases() even offline and it is accurate, but I can’t figure out how to achieve same or what to call in SDKBOX. My only thought is to store the data in local storage but that is very insecure.

I think it’s fair to ask user to be online if they perform a refresh and restore, because purchase transaction in google play can change for a number of reasons

  1. User ask for refund
  2. Price changed by developer
  3. IAP item removed by developer

Hi, my main issue is I need to retrieve the IAP status when the app launches even if they are offline. For example, if they make a purchase for “World 2” in a game, but then reopen the app later on when they don’t have Internet signal, I don’t see a way in this API to detect they’ve already purchased “World 2” so it will still be locked by default.

Hi @Nex

If you want to check later in offline mode whether that item is purchased or not then you can save their purchase status to a UserDefault value.

when your IAP is successful, then change the value like this -

UserDefault::getInstance()->setBoolForKey("world_2_unlocked", true);

and check when the app starts every time in a singleton class.

bool unlockedWorld2 = UserDefault::getInstance()->getBoolForKey("world_2_unlocked", false);

if the value for unlockedWorld2 is true then the world is already unlocked.
no need to check IAP status everytime.

Hope that helps.

Happy Coding… :smile: