Android in-app purchase checks buyer offline

I use the application (managed) in the application in my application, using billing services, when the user wants to buy a product, he will make a purchase request that requires the Internet, even if the user has already bought this product. therefore, for the convenience of users, I do this if the user bought the item, then the value will be stored in the general privilege. and when the user clicks on this particular element, then he checks the common prefix. the value that the user has acquired, either not or not, and then go to the purchase request, show his / her item. My question is, what is the safe way? or should i do something else?

+6
source share
2 answers

It is not safe. I would dissuade you from such a check. You better go for the standard approach and use the getPurchases () method. You can call this method at any time (even offline), and if the user has purchases, they will be returned back from this method. Here is a sample code:

IInAppBillingService service; // initialize it first Bundle response = service.getPurchases(3, "you app package", "inapp", null); int responseCode = response.getInt(KEY_RESPONSE_CODE); if (responseCode == RESPONSE_OK) { ArrayList<String> purchases = response.getStringArrayList(KEY_INAPP_PURCHASE_ITEM_LIST); ... } 

From the curse, you need to check that the purchases are signed with the correct certificate, and the purchase status is not canceled. But it is much safer than storing data in shared properties. Another advantage of this approach is that after the user reinstalls the application, all purchases will be automatically available there too.

+8
source

A full example of this method is in the TrivialDrive example application, and it works for me, but I am thinking of an offline case. The Google Play app caches purchases and gives answers to getPurchases (3, "pkg", "inapp", null) offline, but it works endlessly or is there something like a timeout for this cache ...

+1
source

All Articles