IAP Restore - Android

I have used Unity’s codeless IAP and set up consumable and non consumable products, all work when testing via google play on an android device.

The non consumable items cannot be purchased again once they have been bought, the purchase fails.
I guess this is google saying you have already bough the product.

I am aware of the restore function in the codeless IAP but i am not certain how this works, my non consumable items are setup so a boolean is set to true once purchased. I am looking for a way to reinstate the boolean values if there has been a reinstall.

I think because my non-consumables are set up via variables when reinstalling they are not restoring the variable values and working, although google does seem to pick up they have been purchased.

I want to be able to read if the item has been purchased and then take action to set up the variable as true so the non consumable will be active when the user reinstalls.

Any help or advice would be greatly appreciated, I am not a coder so simple explanations would be brilliant!! :slight_smile:

@a_deo_et_rege

This is expected behavior for Unity IAP, although technically, Google Play doesn’t have the concept of Non-Consumable.

You actually don’t even need to use the Restore option in Codeless IAP. Restoration of Non-Consumable products happens automatically on Google Play.

After you re-install, Unity IAP will check with Google Play to see if you are entitled to any of the products you have added to your Catalog. If you are, then Unity IAP will call ProcessPurchase for each of the products that need to be Restored.

So whatever you are using in your ProcessPurchase callback will be the same for a new purchase and a restored process.

However, it is important to note that this happens as soon as the app is started. So you will need to be ready to fulfill your purchases as soon as your app starts.

If your Purchasing UI is not ready, you can use the IAP Listener that was added recently. It works similar to Codeless IAP, but it doesn’t have any UI associated with it. It simply has the callbacks.
https://docs.unity3d.com/Manual/UnityIAPCodelessIAP.html

3 Likes

On reinstalling the game, the Boolean for show no ads is not set back to true? I have monitored this and it doesn’t seem to be setting it back.

I think i could do this in code though, i suspect from what you have mentioned it would be through ProcessPurchase.

So id check if the item has been purchased and reinstate the relevant variables.

Are the any simple code tutorials that you can recommend that would help with this??

Thanks for taking the time to reply its appreciated.

@a_deo_et_rege What Boolean value are you referring to? Can you show your code, and a screenshot of your Inspector for your IAPButton settings.

1 Like

Hi Jeff sorry for the late reply, this may be an issue as i am using a plugin called Fungus for unity as a non coder this is easier to help me develop in unity than programming. This works on flow charts and blocks were you put the code.

Link to Asset Store

The code less IAP buttons on fail and completion fire to 2 different blocks and the booleans are set up and controlled within fungus.
IE if don’t show ads boolean is true - Dont show ads etc

If i can get a script that checks if the items have been purchased I sort of know how to code this into fungus or at least to return in fungus what is required. So if the no ads had been purchased and this with some coding came back as true I can then direct it to fungus to do the required setting of the boolean.

Sorry i am not very coding orientated, if you would still like to see the buttons and screen shots happy to do so, the whole thing seems to work at least with test purchases but it doesn’t as mentioned reinstate any non consumables.

thanks again for your time and patientce

Unfortunately I’m not familiar with Fungus nor could we offer specific support. In your case, we don’t currently offer inventory management, but is something we are considering for a future release. In the meantime, you would want to persist the purchase information locally and set the Boolean values accordingly at startup. Be sure to test during uninstall/reinstall. You would want to check with Fungus how they would recommend persisting data between sessions, and persist the value in the IAP button purchase success.

Unity 2018.2.11f
Restore purchase don’t work for nonConsumeable product in Android.
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
This function wont call, but should. Any suggesions?

UnityIAP logs:

11-02 12:03:30.512: I/UnityIAP(7336): Inventory refresh successful. (response: 0:OK)
11-02 12:03:30.512: I/UnityIAP(7336): The number of owned skus is0
11-02 12:03:30.512: I/UnityIAP(7336): The number of purchased skus is1
11-02 12:03:30.512: I/UnityIAP(7336): The number of subscriptions purchased history is0
11-02 12:03:30.569: I/UnityIAP(7336): Finish transaction:GPA.3350-5197-4664-50581
2 Likes

@Sparkline_1 Android does not have a Restore purchase method. It happens on reinstall only. Please see the post on June 21 from ap-unity. Please provide steps to reproduce in your situation, and the code that you are using.

Yes I mean reinstall. As I understand: After reinstall system checks if account has purchased items and if it get some it fires ProcessPurchase function.
So in my case system see 1 paid sku but wont fire this function. My code is taken from here https://unity3d.com/ru/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game
I have only 1 nonconsumeable product.

How did you define the product as non-consumable, please show your specific code. Also, what version of IAP are you using?

what about restoring purchases after an app update (not reinstall), because I did change the “savings” system in my app and my players lost access to their IAPs, I thought the restore was automatic, but it seems it isnt. Im using the script from this tutorial Unity IAP - Unity Learn

@Daahrien You need to handle inventory management yourself, but is a feature we are considering for a future release. You can use PlayerPrefs to store purchase information, but it has limitations. Restore only happens with non-consumables and subscriptions during reinstall.

Hi @JeffDUnity3D , Android just started their restore feature on April 15. Don’t I have any other option to restore the subscription from anytime I want? like iOS?. Android Have a ‘getPurchase()’ method to get the purchase status manually at any time.

Hi all!

@JeffDUnity3D (and anyone else with knowledge about this kind of issue), we have a couple of freemium apps, with a single IAP available in each to unlock the full version, and we’re having problems with the users not being able to restore the fullversion-iap after they’ve restored their devices from a backup. The encrypted info we’ve stored in PlayerPrefs then isn’t valid because the unique ID of the device has changed so the purchase has to be restored in order to unlock it again, but it seems the app already has stored some internal information at that point (info following the backup restored version of the app) that it has already done the initial purchase call so PurchaseProcessingResult() won’t be called automatically again.

Looking at the adb logcat I can see the following:
Normally, when the restore is working, the call to
OnInitialized(IStoreController c, IExtensionProvider e) is followed by a call to
PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) and this follows in the log
UnityIAP: Finish transaction:GPA.***

But in the case of the backup-restored apps the OnInitialized is instead followed by a
Unity : Already recorded transaction GPA.*** and then the
UnityIAP: Finish transaction:GPA.***
and as you can see, no call to PurchaseProcessingResult in between.

Is there a way to intercept the call causing the Unity : Already recorded transaction GPA.*** output and handle the receipt data there? Or if not, is it possible to query the Google Play store through the UnityIAP lib to get the receipt of previous purchases to manually process them and unlock the app again?

Asking the users to delete and reinstall the app has been our approach up until now, but this is not an ideal solution due to:

  • Many of our android users seem to now grasp what it means to do a full uninstall of the app, and instead just end up deleting it from the launcher homescreen, which doesn’t solve the issue, causing confusion and frustration
  • Deleting the app obviously makes them loose all their data and stuff built in the apps, progress etc is lost.

Did this just start occurring with IAP 1.22? Only non-consumables and subscriptions would be expected to Restore upon reinstall. But Restore does look to be affected in 1.22 regardless, and we are continuing to investigate.

Yes we’re talking non-consumables (unlock the full version of the game, one-time purchase). We’re currently on an older version of the Unity IAP lib, 1.19.0

Android Restore only happens upon actual uninstall/reinstall. Often studios will save user info to the cloud, instead of PlayerPrefs, so the data is available across devices and platforms.

We don’t use logins (we mainly do kids games) so I don’t think we can store it in a cloud service and therefor we have to store it locally. So I think either we can change to storing it in a non-device-specific encryption which would allow the users to just copy the storage blob to another device and still run it (with the copy/piracy implications that will have), or we get the restore via Google Play to work properly. We’re getting these support messages from older apps as well that are using UnityIAP 1.15.0, that when they restore the device (or setup a new one) from a backup, uninstall the app and install it again, the restore function in the android app isn’t called so they’re not able to restore the purchase.

I see in the release notes for 1.22.0 that there’s a new method to manually call the restore method on Android but I’m also reading you’ve detected some problems with it. Do you think it’s safe to go ahead and upgrade to 1.22.0 and manually call initiate the restore, or are you guys close to finding a fix for the error you’ve found?

There should be no issues with Restore on versions of IAP prior to 1.22 when coded correctly. The Sample IAP project on this forum works without issue during restore. I would wait to test with 1.22, it does have some issues with Restore.

Hi there! In my app ProcessPurchase is also not called after app reinstall. I’m on Unity 2018.4 with updated IAP. I have to make Restore button that simply tries to purchase again. In case of already owned item I consider that restore is succeeded. Anyway, some debug/check steps can be helpful because I even don’t know where to start. Codeless IAP is cool thing, but Restore feature should work clear. At least work)