Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Already recorded transaction - Not restoring purchase.

Discussion in 'Unity IAP' started by vitorfgd, Oct 4, 2018.

  1. vitorfgd

    vitorfgd

    Joined:
    Nov 4, 2014
    Posts:
    20
    Hello, I'm using IAP on a mobile game that is available on Android. I'm working with Google Play Services and had some problems with conflicts between other SDK.

    To be sure that the problem was indeed solved, I decided to reimport most of the SDK and APIs I use in my game, including the Unity IAP 1.20, using the services tab. The problem is that my game DOES recognize the purchase but is not restoring it on Android.

    When reading through the logcat, I got the message:
    Already recorded transaction GPA.[...]


    When I click the button to purchase it, I'm getting:
    OnPurchaseFailed: FAIL. Product: '[...]', PurchaseFailureReason: DuplicateTransaction


    But the game is not processing this update and my nonConsumable is never set to true. I'm using the IAP script provided at: https://unity3d.com/pt/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game with few changes, such as, I removed the subscription and added my own to the nonConsumable products. I also set the variable using:

    ES3.Save <bool> ("adRemoval", true);


    Under:
    PurchaseProcessingResult


    When I debug it. "adRemoval" is always false.

    [EDIT1]Just to be sure, I added a simple Debug.Log on PurchaseProcessingResult, because the function should be called for each product owned by user and the function is never called.
    [EDIT2] I'm currently using Android 7.1.
    [EDIT3] This seems to work fine in editor, the problem is when I build it. I get the message UnityIAP Version: 1.21 and OnInitialized: PASS, other then that. Nothing works.
     
    Last edited: Oct 4, 2018
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Restore on Android only works during app reinstall. Is ProcessPurchase called when you first make the purchase? Keep in mind that you can't test IAP on your Android device with your developer user account, you need to create tester accounts. Also, if this product is configured as a non-consumable, then a second purchase would indeed be a duplicate (not allowed) transaction.
     
  3. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    After testing for a while, I have concluded that ProcessPurchase method will be called only when the customer purchases a non-consumable product for the first time or during app reinstall. When the customer restarts the game, ProcessPurchase won't be called, so we have to think of a way to store the transaction record when a customer purchases a non-consumable product for the first time?
     
  4. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    No, Unity can automatically restore non-consumable product when restarting game. Make sure to uncheck "Consume Purchase" in the IAP Button. I just found out..

    Edit: Actually no, unchecking "Consume Purchase" will only leave the product in pending state, we still have to find a way to store the transaction record.
     
    Last edited: Jun 13, 2019
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    That is correct, you need a system for inventory management. Some developers use PlayerPrefs, but it's not entirely secure.
     
  6. ltomov

    ltomov

    Joined:
    Aug 3, 2017
    Posts:
    95
    Are there any plans to fix this?

    When implementing IAP in JAVA (non-unity apps) this works fine, and you can get the list of purchases (non-consumables) with an API call, not only when you reinstall.

    So this is clearly a Unity bug.

    Having to keep an inventory of purchases outside of the Play Store would be a ridiculous solution - full of bugs and customer frustration.

    It's worth mentioning that this is a limitation of the Amazon IAP - this is where you need to keep a local inventory, with Google you can use this API: BillingClient.queryPurchases(BillingClient.SkuType.INAPP)

    Please make this work in Android, this is a terrible bug.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please check with IAP 2.2.4, it should work now. It was an async issue.
     
  8. ltomov

    ltomov

    Joined:
    Aug 3, 2017
    Posts:
    95
    I updated, it seems to work now, thanks a lot!