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

OnPurchaseFailed,Duplicate transaction

Discussion in 'Unity IAP' started by drndfx, Mar 1, 2019.

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

    drndfx

    Joined:
    Jul 3, 2013
    Posts:
    89
    Hello,

    I put my test app on Google Play Store Test track and using a test account.

    I have a NoAds button. It worked the first time. It showed me item Buy screen. And I chose "Always approve this test purchase option".

    Now, I can no longer see that purchase screen and the NoAds button doesn't do anything. When I check the Debug it says. "OnPurchaseFailed,Duplicate transaction".
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    If you are using Codeless, make sure you check "Consume product" checkbox. If NoAds is a non-consumable (it should be), then DuplicateTransaction would be expected. You are not permitted to purchase a non-consumable a second time.
     
  3. drndfx

    drndfx

    Joined:
    Jul 3, 2013
    Posts:
    89
    Thanks.

    As a tester. How do i reset the transaction? So i can re-test how transaction works. Do i have to upload a new APK ?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, a single user can only buy a non-consumable once. You can't reset the transactionID. You don't need a new APK, just use a different product or a different user.
     
  5. drndfx

    drndfx

    Joined:
    Jul 3, 2013
    Posts:
    89
    Thanks.
     
  6. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    Hi Jeff, I am using consumable items and when I try buying the product, the OnPurchaseFailed method gives me the duplicate transaction message. I am doing every thing by your sample on https://forum.unity.com/threads/sample-iap-project.529555/ I tried to make a situation that the purchase become complete but not giving the item to user, to produce this problem.
    I am just wondering that is there an option to restore these failed purchases with a similar method ?
    Is my test account stuck in this duplicate transaction error for ever ?
    If the purchase is failed by a user, there is no possible way to restore the purchase so it becomes purchasable again?

    P.S. our app is in production, I'm using unity IAP version 3.0.2 and Unity LTS 2020.3.0
     
    Last edited: Apr 12, 2021
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So IAP worked in your testing, but stopped working when you published live? How did the original purchase fail, can you provide steps to reproduce? Do you return Pending or Complete from ProcessPurchase? Are you using scripted or Codeless IAP?
     
    Last edited: Apr 12, 2021
  8. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    Yes, IAP works and the app is in production for over a year but we are trying to refactor some problematic scripts.

    I'm using scripted IAP.

    The code implementation is alright. However, I was trying to put the purchased item in pending state until I confirm it with my Web server, so in the end of PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) method insted of ConfirmPendingPurchase.Complete I am setting it to ConfirmPendingPurchase.Pending and waiting for my server response and after that I use this method: m_StoreController.ConfirmPendingPurchase(product); which I believe makes the pending purchase being completed.
    So, when my server response time out and the product it not consumed by user I receive duplicate transaction when trying again.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Do your purchases work correctly if you return Complete directly from ProcessPurchase (as a test, only)? I've heard of other reports of ConfirmPendingPurchase not marking the product as consumed, same as you. I suspect there is a problem at our end. However, I'm not able to reproduce, and it works correctly for me. I use v1 of the Sample IAP Project that was designed for this very test, and upgraded it to IAP 3.0.2 https://forum.unity.com/threads/sample-iap-project.529555/
     
  10. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    Well, in the new implementation that I am working on, I am refactoring code to return Complete in ProcessPurchase instead of using ConfirmPendingPurchase but what is killing me is the remained unconsumed products which includes all of my consumable products and I'm really concerned that our users experience the same problem at some point. So until I get a satisfiable feedback from users, would you help me to solve this duplicate transaction error?

    Doesn't IAP have a way to restore purchased and not consumed products somehow ?

    by the way, thank you so much for the support:)
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, that is what we are doing. Are you able to test as I suggested? It would help to troubleshoot your issue. Are you changing topics and asking about restore now? If so, note that the restore operation on Google happens automatically for non-consumable and subscription products, you'll receive a ProcessPurchase for each such product during an app reinstall, for example. But your original error mention is regarding consumable products and the duplicate transaction error. I was hoping to troubleshoot and resolve that issue first.
     
  12. Olegleg

    Olegleg

    Joined:
    Mar 30, 2021
    Posts:
    47
    Do you acknowledge purchases on the server side?
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I spoke with the engineering team, and it is advised not to acknowledge purchases server side. We already do that in the client code. The typical flow is to validate the receipt only, server side.
     
  14. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    Yes, as I mentioned I have changed the implementation as you suggested. It may take a few days and bunch of different tests to see if the issue would be reproduced or not.

    However, until then, I would be glad if you could help me with the restoring purchases. thank you so much.
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry I don't follow. If you have a separate question regarding Restore, please open a new thread. The topic is not related. So you are not able to reproduce your duplicate transaction error? Or are you waiting to hear about errors from your users?
     
  16. alipaknahad

    alipaknahad

    Joined:
    Dec 22, 2020
    Posts:
    11
    We are testing the new implementation. And so far returning Complete from PurchaseProcessingResult have solved the problem.

    Thank you so much @JeffDUnity3D
     
  17. MTeplytskyi

    MTeplytskyi

    Joined:
    Jun 16, 2020
    Posts:
    26
    Hi! We are experiencing same problems as you heard of other reports. Seems that ConfirmPendingPurchase not working properly on ios, so we receive Diplicate Transaction error. Version of Unity is 2019.4.18, iap plugin version 2.1.1, iap package version is 2.2.1.

    I've also tried updating to IAP 3.0.2, but error is still present. Everything worked well until recently, one change that we made for the last week - only uploaded build to Test Flight

    Maybe you can help! Thanks
     
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I will check on iOS using IAP 3.0.2 . I do know that it works as expected on Google Play
     
  19. GregTinga

    GregTinga

    Joined:
    Jun 12, 2020
    Posts:
    9
    I am also seeing On IOS IAP vs 3.0.2, on Consumables the Duplicate Transaction Error is being received after a purchase has been made and ConfirmPendingPurchase called for the transaction before it.
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are checking.
     
  21. truongpd88

    truongpd88

    Joined:
    Sep 19, 2019
    Posts:
    3
    hello, we are facing the same issue with version IAP 2.2.1, we tried upgrade to the lastest version 3.0.2, but it does not help, we have been using this implementation in production for 4 years, this issue only just happened about 2-3 weeks ago because we tested it before release 3 weeks ago
     
  22. gamedev_co

    gamedev_co

    Joined:
    Apr 16, 2021
    Posts:
    6
  23. Andrew-Q

    Andrew-Q

    Joined:
    Jun 2, 2015
    Posts:
    3
    Hi. Same problem here on iOS. Return "Complete" in ProcessPurchase, but it doesn't consume the product. I've tried to manually consume all pending products, but that didn't help. Here's the manual consume function. It is called after IAP has initialized:

    Code (CSharp):
    1.     void ConfirmPendingPurchasesForAllProducts()
    2.     {
    3.         ProductCollection products = m_StoreController.products;
    4.  
    5.         for (int i = 0; i < products.all.Length; i++)
    6.         {
    7.             m_StoreController.ConfirmPendingPurchase(products.all[i]);
    8.         }
    9.     }
    10.  
     
  24. jannekai

    jannekai

    Joined:
    Nov 30, 2018
    Posts:
    1
  25. dfarrow

    dfarrow

    Joined:
    Jan 10, 2015
    Posts:
    3
    @jannekai I am also seeing this problem with "DuplicateTransaction" errors in iOS using a Sandbox Account. My consumable IAPs were working fine until about two days ago, but on Thursday we starting seeing this issue where consumables could only be purchased a single time when testing in TestFlight using Sandbox. I don't know if it is in production because we haven't launched yet, but this is holding up our launch.
     
  26. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I tested yesterday without issue https://forum.unity.com/threads/uni...gresult-pending-purchase.537924/#post-7055551
     
  27. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    We've also tried upgrading to newer versions and our test plan for purchases fail with the newer version, but works when we revert back.
    After the purchase comes through we mark the purchase as pending and then crash the app. With the older versions, when you run the app after initialize that purchase would returned in ProcessPurchase and we can send it to receipt validation but on newer versions we don't get any callbacks and that store item is permanently locked out with the "Duplicate Transaction" error. We've been mostly testing Android. We've tried multiple store versions but most recently 3.02. If you think this is a separate issue I can start a new thread. We're worried that the required google update will force us to upgrade to a version with a known issue.
     
  28. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I just tested your scenario on iOS using IAP 3.1.0 and I'm not seeing the issue. I'm using the Sample IAP Project v2 here and using the v1 Toggle button (to return Pending vs Complete from ProcessPurchase)

    https://forum.unity.com/threads/sample-iap-project.529555/#post-6950270

    * Launch the app
    * Purchase a consumable (gold50)
    * Prompted for Sandbox credentials
    * It says "You're all set!"
    * ProcessPurchase is triggered, return Pending
    * I swipe the app up to kill it
    * I restart, and immediately see ProcessPurchase for gold50 when IAP initializes
    * I return Complete from ProcessPurchase
    * I can purchase gold50 again
     
  29. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    I'm pretty sure it's Android only. We did some some failures in our test plans on iOS after the upgrade but they didn't have 100% repro rate.
     
  30. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I just ran the same test on Android, no issue. The Sample IAP Project was designed to test this very scenario.
     
  31. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    @JeffDUnity3D We've narrowed it down. It occurs when you crash right after sending the a receipt to be validated but before you get a response. Receipt validation marks a purchase as "acknowledged" and acknowledged purchases aren't sent to the client after reboot. So the purchase can't be marked as complete and if you try to purchase the sku it will mark is as duplicate. This behaviour has changed some time after 1.23.3.
     
  32. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you share your code? Can you be specific about "before you get a response". Our receipt validator doesn't mark the receipt as acknowledged. You shouldn't be using a Google API on the server to mark it as acknowledged, only verify the receipt. https://docs.unity3d.com/Manual/UnityIAPValidatingReceipts.html. What do you do differently IF you get response? If you mean the purchase remains in Pending state, then yes, Duplicate Transaction is expected. If a product is in Pending, you would expect ProcessPurchase to be triggered on next IAP initialization.
     
  33. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    Our player inventory exists purely on the server and the receipt validation backend is shared between a few large published games. They use "acknowledged" to mark that entitlements were created for a purchase.
    We are using the iaptestapp but using the companies receipt validation backend which does the google api calls. Changing that behaviour seems unlikely, but how do you suggest they do it? From the documentation it sounds like it is implemented as google intended.

    https://developer.android.com/google/play/billing/integrate
     
  34. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Those docs say
    • Verify the purchase on your server. (only)
    What company are you using for receipt validation? Please share your IAP code. And what response are you referring to? Is the transaction left in Pending? I spoke to engineering and we already do the acknowledge, doing it on the server would lead to undetermined behavior. But let's first follow your code path.
     
  35. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    Wizards of the Coast has shared services for receipt validation and entitlement fulfillment. I wouldn't be able to share that code with you but I have confirmed that they used acknowledged to mark purchases as fulfilled. I don't think there's any other significant code to share that isn't just the iap test app.
     
  36. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I'm not asking for server code. Do you mean the Sample IAP Project? I would need to see how you are handing the response from your server, and how it might affect the client. And can you answer, is the transaction left in Pending? Looking at the code will tell me. The Sample IAP Project uses a Try/Catch block around receipt validation, for example
     
  37. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    The bug occurs when we crash before we get a response from receipt validation.
    We get a new purchase.
    We send the purchase to be validated.
    We mark the purchase as pending.
    Then we force crash the app.

    The server validates the receipt creates the entitlements and marks it as acknowledged.

    When the player opens up the app that pending purchase isn't returned in ProcessPurchase. This is the behaviour that has changed in newer versions of Unity purchasing.
     
  38. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it. Unfortunately we are unable to reproduce and don't have any further suggestions at this time. The IAP Sample Project v1 at that same link provides a toggle to switch between Complete vs Pending as the ProcessPurchase return type at runtime, perhaps you could reproduce without a server side call, and just leave the status in Pending and crash the app as you suggest. Also, recent versions of Unity IAP contain the required and updated Google Billing Library v3. This may be why you are seeing different behavior with the new version of IAP. Also, how are you securely sending the user context from the device to the server to acknowledge the purchase on behalf of the user? Developer Payload has been deprecated, if you were using that approach.
     
    Last edited: Apr 30, 2021
  39. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    We can't mark the purchases as complete until we know the receipt was received and fulfilled.

    Do validate a receipt you only need to the token (receipt).

    https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get
    https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/acknowledge

    The problem is that acknowledged purchases are stuck in limbo. I don't think there's any reason to hold back acknowledge receipts if they are still pending.

    If you look at GoogleFinishTransactionService.cs in the FinishTransaction function you hold back Acknowledged purchases from being finished. You're trying not to acknowledge purchases that are already acknowledged (I don't think there's any problem with that) but what do you do with the rest of purchases that need to be finished?

    I have a feeling like our online receipt validation is working as expected. If so then Unity IAP doesn't properly support online receipt validation anymore but it could with just this small fix and not hold back pending acknowledged purchases.
     
  40. Olegleg

    Olegleg

    Joined:
    Mar 30, 2021
    Posts:
    47
    I have the same problem:
    https://forum.unity.com/threads/unity-iap-doesnt-consume-consumable-acknowledged-purchases.1092277/

    And I really don't know, why JeffDUnity3D doesn't want to fix this critical bug.
     
  41. RobbGraySBL

    RobbGraySBL

    Joined:
    Feb 4, 2014
    Posts:
    40
    @JeffDUnity3D Should I log a bug? Everything I've read from google says that acknowledging receipts is the recommended way to mark purchases as fulfilled. At the very least acknowledged purchases shouldn't break the system (generating errors and preventing further purchases).
     
  42. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Nope, you don't do that on the server. We already mark the receipts as acknowledged. And your hesitation to share your code or answer my questions is concerning. It seems to me we fixed a security exploit in the latest release, there is no bug. I'm locking this thread for further replies.
     
Thread Status:
Not open for further replies.