I have implemented Unity 5's IAP system through Google Play. I read a few guides that mention not to store completed purchases in PlayerPrefs because it is clear text and easy to hack, but none mention the correct way to "remember" purchases. For example, when re-installing an Anroid app, purchases are restored the first time the app runs by individual calls to this method defined in the Unity IAP API.

public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
        //my Playerpref save that I want to avoid is here.
        return PurchaseProcessingResult.Complete;

On subsuqent app runs, this method is not called again. Is there a way to query past purchases other than saving them in PlayerPrefs?


on Android the storeController has a list of purchased products when initialized successfully. So then you can use code that looks something like this and check if the item is bought :

Product product = storeController.products.WithID(productId);
 if (product != null && product.hasReceipt)
     // Owned Non Consumables and Subscriptions should always have receipts.
     // So here the Non Consumable product has already been bought.
     itemBought = true;

Restoring purchases is not needed on the Android platform. It is only needed on iOS.

|improve this answer|||||
  • \$\begingroup\$ also I wanted to note for others, while restoring through a special function is not needed on Android, one would need to set up the function I mention and use the code you posted to get everything working correctly. \$\endgroup\$ – Tartle Wizard Apr 18 '17 at 17:27
  • \$\begingroup\$ I made a follow up question concerning not being able to use the above method for times without internet: gamedev.stackexchange.com/questions/140345/… \$\endgroup\$ – Tartle Wizard Apr 25 '17 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.