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. Dismiss Notice

ConfirmPendingPurchase doesn't seem to always work

Discussion in 'Unity IAP' started by Volcore, Nov 2, 2020.

  1. Volcore

    Volcore

    Joined:
    Jan 14, 2020
    Posts:
    24
    Hi,

    we're using the Unity IAP system currently at version 2.1.1. We verify the purchases with the server, perform de-duplication there, etc.

    We're running into an issue where the UnityIAP system will report a certain Google Play transaction. After the server confirms the purchase (even in the case of a duplicate it confirms the purchase again), the client then calls `ConfirmPendingPurchase`. This works most of the time, but for some purchases they will be re-discovered every single time the application is started. So far, I have not found a way to "get rid" of those purchases, but `ConfirmPendingPurchase` definitely doesn't seem to work.

    One particular thing I've noticed is that the Unity IAP subsystem itself will print this in the log for one of the problematic transactions:


    11-02 15:51:57.497 I/Unity ( 900): Already recorded transaction GPA.XXXX-XXXX-XXXX-37949

    11-02 15:51:57.497 I/Unity ( 900): UnityEngine.Purchasing.PurchasingManager:ProcessPurchaseIfNew(Product)

    11-02 15:51:57.497 I/Unity ( 900): UnityEngine.Purchasing.PurchasingManager:OnProductsRetrieved(List`1)

    11-02 15:51:57.497 I/Unity ( 900): UnityEngine.Purchasing.JSONStore:OnProductsRetrieved(String)

    11-02 15:51:57.497 I/Unity ( 900): System.Action:Invoke()

    11-02 15:51:57.497 I/Unity ( 900): UnityEngine.Purchasing.Extension.UnityUtil:Update()



    It actually prints this log 4 times.

    The code path is:

    • We call FetchAdditionalProducts to get all products
    • If one of the products has the transactionid field set, we will send this to the server to get verified
    • Once verification is completed, we call ConfirmPendingPurchase
    The other code path is similar but triggers the verification through the ProcessPurchase callback.

    This seems to have worked well, but we recently upgraded Unity IAPs to 2.1 and since then we've been seeing this issue.

    Are we doing anything wrong here? Is there a way to tell if a product with a transactionid is confirmed/unconfirmed?

    PS: We need the FetchAdditionalProducts code path as ProcessPurchase isn't called reliably for some recoveries and purchases that didn't go through correctly the first time around.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are looking into this issue. It seems related to receiving receipts during initialization for products that haven't been loaded yet via FetchAdditionalProducts. I will try to keep this thread updated. In the meantime, you might want to avoid using FetchAdditionalProducts if possible and load all products up front.
     
  3. Volcore

    Volcore

    Joined:
    Jan 14, 2020
    Posts:
    24
    Thanks for the quick reply! In our case, we can't really avoid `FetchAdditionalProducts` as we're pushing down additional product IDs from the server and dynamically update the list.
     
    JeffDUnity3D likes this.
  4. SamuelSavaria

    SamuelSavaria

    Joined:
    Dec 5, 2019
    Posts:
    4
    Hi!

    I can confirm that I'm seeing a similar issue on our end.
    The purchase recovers properly, but when trying to purchase the same (consumable) product again, the user gets a DuplicateTransaction error.
    We do call ConfirmPendingPurchase at the same time as giving the rewards.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you using FetchAdditionalProducts?
     
  6. SamuelSavaria

    SamuelSavaria

    Joined:
    Dec 5, 2019
    Posts:
    4
    Yes we are getting the product list from our server. We have different calls to fetch different shops (coins, energy, offers, etc). So we might register some products much later in the app lifecycle.

    Also note we are on Unity 2019.4.12f1 LTS.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    It appears that we may have issues when using FetchAdditionalProducts. In particular, when we receive a receipt during IAP initialization for a product that has not been loaded yet. We are looking into this, and hope to address the issue soon.
     
  8. SamuelSavaria

    SamuelSavaria

    Joined:
    Dec 5, 2019
    Posts:
    4
    Hi Jeff!

    I've ran a couple of tests and I can confirm that initializing all my products on UnityPurchasing.Initialize works.

    However, this is not a viable option for us as our architecture relies on loading new products at various points in the game.

    Do you have an ETA for when a fix could be provided?
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry no ETA but given the high priority, I would expect within a few weeks.
     
  10. Volcore

    Volcore

    Joined:
    Jan 14, 2020
    Posts:
    24
    Any workarounds? Like being able to tell if this purchase/transaction has already been processed from the request.

    This is affecting real users, right now, so we're thinking about adding our own client-local de-duplication.
     
    Last edited: Nov 6, 2020
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    No work arounds that we are aware of.
     
  12. SamuelSavaria

    SamuelSavaria

    Joined:
    Dec 5, 2019
    Posts:
    4
    @Volcore From our testing, recovery seems to work if you call Initialize UnityIAP with the products you'd like to recover.
    So on our end, we will try to fetch the list of pending products from our server, then initialize UnityIAP with those products.
    If this works properly, it will be our workaround until Unity fixes this issue.