Search Unity

[Solved] "You already own this item" for no-consumables when disabling internet right after buying

Discussion in 'Unity IAP' started by Revolter, Apr 25, 2018.

Thread Status:
Not open for further replies.
  1. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Reproducible on both Android and iOS
    -Start purchase process
    -Press buy in native window
    -Disable internet as fast as possible
    -OnPurchaseFailed will be called
    -When you try to buy again you get "You already own this item" dialogue
    -OnPurchaseFailed called again with Reason: UserCancelled

    It will be fixed by itself after some time, so it's not a huge issue.

    Edit: Using Unity 2017.3.1p1
     
    Last edited: Apr 25, 2018
  2. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    I double checked, this actually happens for consumables
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide the device logs since you are able to reproduce. On Android, I generally use "adb logcat | grep -i unity". On Windows you can substitute findstr for grep.
     
  4. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Attaching, hope this helps.
     

    Attached Files:

  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you point to the line(s) in the logs where the issue occurs? Can you confirm it is at the line "Purchase response code:-1005" . Debug.Log statements will show in the logs and would be recommended for troubleshooting.
     
  6. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    The easiest thing would be to follow OnApplicationPause calls.

    Line 7388: Initiating purchase
    Line 7390: OnApplicationPause: true and disabling wifi

    Line 7779: OnApplicationPause false and coming back
    Line: 7884: OnPurchaseFailed

    (Pausing the app again to enable wifi)

    Line 10005: Next attempt to purchase
    Line 10280: Failed response

    and again same result
    Line 11853: Failed response

    and again same result
    Line 13938: Failed response
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Thank you for the additional information. So to disable the Wifi, you hit Home to background the app, then go to Settings/Wifi, correct? My transactions go through too quickly when I try that. I can try again.
     
  8. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi @Revolter ,
    I guess that the issue happened after sending purchase request, but before response was returned from Google server.
    So at the client side OnPurchaseFailed() was fired with reason UserCancelled, and at the Google server side the product was already owned.

    The response code was "-1005" (User canceled) after disabling WiFi.

    Usually, Unity IAP would consume a Consumable product again at next launch if it didn't consume the product successfully.
    But in your case, Unity IAP didn't receive the receipt. So it cannot consume the product without its transaction id.
    And when you tried to buy the product again, Google Play IAP server returned -1005(User canceled) because you have already owned it.

    This user has the same problem. He posts some detailed steps and offered 2 workarounds.
    https://productforums.google.com/forum/#!category-topic/play/apps--games/kol0IGX511I

    Workarounds:
    1. Reboot the device.
    2. Clear data of Google Play Store App.

    Usually, Unity IAP will retrieve all already owned products during initialization via getPurchases(), and then try to consume them.
    getPurchases() retrieves products from cache in Version 3 API.
    So if the Internet is turned off before purchase response comes back, Google Play Store will not have this response data and then it can't offer an already owned product to Unity IAP. That's why Unity IAP can't consume it.

    Rebooting device or clear data of Google Play Store App might force getPurchases() retrieving data from Google server. Then Unity IAP gets the already owned product receipt, fire ProcessPurchase() and consumes it finally.

    I have tried these 2 workarounds and proved them.

    These links might also help.
    https://answers.unity.com/questions/1136298/unity-iap-services-consuming-already-owned-items.html
    https://forum.unity.com/threads/solved-errors-when-products-fail-to-be-consumed.428831/
     
  9. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Thanks a lot for your help @JeffDUnity3D and @unityjingyao
    Rebooting the device works indeed, we will be suggesting it to our players with the issue.
     
Thread Status:
Not open for further replies.