Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Restoring Non Consumable Product is not working in Android 7.0

Discussion in 'Unity IAP' started by samzgamz, May 26, 2017.

  1. samzgamz

    samzgamz

    Joined:
    Sep 16, 2015
    Posts:
    40
    Hi

    I have a weird problem here where the restoration of non consumable products is working on one version of android but not on another.

    My Setup:
    Unity 5.6.1f1
    Unity IAP 1.11.1
    TargetSDK : API 25
    Platform under test : Android 7.0
    Device : Moto G 4th Gen


    Steps:
    1) The App was setup for closed alpha testing as described in the Unity documentation.
    2) I downloaded the app from the play store for the Alpha tester.
    3) I made the test purchase of non consumable product (there is only one in the app). The purchase was successful. The product gets unlocked successfully.
    4) I deleted the app and then reinstalled it from the Play Store on the same device.
    5) The expectation here is that on starting the App, the ProcessPurchase function would be automatically called and the product would be unlocked. However, the ProcessPurchase function does not get called. Instead the product is still available to purchase.
    6) If the user tries to buy the same product again, it throws up Duplicate Transaction error.
    7) Installing the same app on a different device works perfectly well and the product is automatically unlocked on application start.

    I have tried restarting the device, clearing out the Google Play App's cache multiple times, but nothing seems to work.
    I have tested out the exact same scenario on another old device running Android 4.0.4 and the issue does not occur on that device. ProcessPurchase gets called properly so the issue does not seem to be in my code.

    Is this a known issue or expected behaviour? Should I be treating the duplicate transaction error as an indication that the user already has purchased the product and unlock it when I see that error? Is anyone else facing the same issue? Could it possibly be a device specific issue?

    Any help would be much appreciated!
    Thanks!
     
  2. samzgamz

    samzgamz

    Joined:
    Sep 16, 2015
    Posts:
    40
    Ok, after playing around a while, here's what I found.

    From the logs I found, this:

    It finds correctly that there is an owned item and then finds a transaction associated and doesn't call ProcessPurchase. Also when I try to purchase the item again, it gives a "Duplicate Transaction" error.

    I looked on the internet and found that Unity maintains a duplicate transaction record (https://docs.unity3d.com/ScriptReference/Purchasing.UnityPurchasing.ClearTransactionLog.html). I uninstalled the app and looked into the phone's internal storage and found that there is still a folder with my app's package name in Android/data directory of my phone. This folder still had some Unity and Unity IAP cache data in it. I deleted the folder and then reinstalled the app. And this time everything worked correctly and the ProcessPurchase was called.

    Next I again uninstalled the app and reinstalled it and the problem again reoccurred. So now I had to use the "Clear Data" (which deletes the PlayerPrefs also!) option of my App and that deletes the transaction log and opening the App again solves the issue.

    So to sum up, here's the problem I am facing:
    1) Install the app and successfully purchase a non-consumable product.
    2) Uninstall the app.
    3) Reinstall the app on the same device and the non-consumable product is not automatically restored.
    4) It seems the unity transaction log persists (or gets recreated?) during the cycle which prevents the product from being unlocked.
    5) Use the App's "Clear Data" option which will delete the PlayerPref's as well.
    6) Now reopen the App and everything works correctly.

    I am facing this issue on Android 7.0 while doing test purchases. Any ideas why this could be happening? And is anyone else facing the same issue?

    Hoping for a resolution from the community.
    Thanks
     
  3. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Last edited: May 31, 2017
  4. samzgamz

    samzgamz

    Joined:
    Sep 16, 2015
    Posts:
    40
    @ap-unity ,
    Thanks for responding and helping out! Let me know if there is something I can do.