Search Unity

[iOS] Duplicate Transaction error on purchases

Discussion in 'Unity IAP' started by xLeo, Dec 18, 2020.

  1. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide steps to reproduce
     
  2. unity_59XljCrEyCy65Q

    unity_59XljCrEyCy65Q

    Joined:
    Apr 1, 2020
    Posts:
    1
    @JeffDUnity3D
    Using a sandbox account, buy a subscription
    Let it auto renew and eventually expire in 6 or so hours

    Try to renew plan and purchase again

    Duplicate Transaction error
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    How do you know it's expired? If it's an autorenewing subscription, it won't expire and the message would be expected.
     
  4. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    52
    I experience the same issue with IAP 3.2.3
    Any update?
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please compare to the latest version of IAP, and provide steps to reproduce.
     
  6. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    52
    sandbox account
    UnityIAP purchasing package v3.2.3

    following these steps, this bug can be repro~

    enter game
    restore
    restore completed with no product
    try to purchase a subscription, then failed with duplicatetransaction
    (very new apple sandbox account? ever subscripted and canceled? you can try this two scenarios)
     
  7. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    52
    more information
    Unity v2018.4.36f1
    [iOS]
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Unity 2018 is no longer supported. Please test with an updated version of Unity and IAP 4.3.0. Did you explicitly cancel the subscription? Does Restore work if you don't? Is ProcessPurchase fired during restore? Please share the code you are using and the device logs when you see this behavior after you are able to upgrade.
     
  9. JoJoJoX

    JoJoJoX

    Joined:
    Jun 23, 2022
    Posts:
    52
    No, I CANNOT upgrade Unity version! It's huge!!!
    If you cant repro, you can stop check it~WTF
    I have no time to check it in a higher Unity version with higher IAP plugin version.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you answer my questions? I'm not sure what you mean by stop check it. I would not check older versions of IAP, I'm not sure of the purpose. Let's assume I find an issue, then we would fix it and include it in the next release where Unity 2018 and 2019 are no longer supported. So you would need to upgrade regardless. It's best to see first if the issue still occurs in the latest version, I don't see this issue in my testing.
     
  11. mindvivid

    mindvivid

    Joined:
    Nov 5, 2015
    Posts:
    1
    I got the same issue. I'm using Unity 2020.3.25 and the latest IAP package version 4.5.1.
    Same steps as others with ios app store sandbox account.
    I got the following log in xcode:

    2022-11-29 14:34:54.597494+0800  [49986:12918440] UnityIAP UnityEarlyTransactionObserver: Created
    2022-11-29 14:34:54.598386+0800 [49986:12918440] UnityIAP UnityEarlyTransactionObserver: Registered for lifecycle events
    Unity IAP: <b>Unity In-App Purchasing</b> requires <b>Unity Gaming Services</b> to have been initialized before use.
    - Find out how to initialize <b>Unity Gaming Services</b> by following the documentation <i>[URL]https://docs.unity.com/ugs-overview/services-core-api.html#InitializationExample[/URL]</i>
    or download the <i>06 Initialize Gaming Services</i> sample from <i>Package Manager > In-App Purchasing > Samples</i>.
    - If you are using the codeless API, you may want to enable the enable <b>Unity Gaming Services</b> automatic initialization by checking the <b>Automatically initialize Unity Gaming Services</b> checkbox at the bottom of the <b>IAP Catalog</b> window
    2022-11-29 14:35:01.366419+0800 [49986:12918440] UnityIAP: Requesting 3 products
    2022-11-29 14:35:01.415412+0800 [49986:12918440] UnityIAP: Requesting product data...
    2022-11-29 14:35:02.705530+0800 [49986:12918673] UnityIAP: Received 3 products
    2022-11-29 14:35:02.715720+0800 [49986:12918673] UnityIAP: No App Receipt found
    2022-11-29 14:35:02.722072+0800 [49986:12918440] UnityIAP: No App Receipt found
    2022-11-29 14:35:02.722830+0800 [49986:12918440] UnityIAP: Add transaction observer
    2022-11-29 14:35:02.722960+0800 [49986:12918440] UnityIAP UnityEarlyTransactionObserver: Request to initiate queued payments
    2022-11-29 14:35:28.456962+0800 [49986:12918440] UnityIAP: Restore transactions
    2022-11-29 14:35:28.457215+0800 [49986:12918440] UnityIAP: RestorePurchase
    2022-11-29 14:35:31.201155+0800 [49986:12918440] UnityIAP: UpdatedTransactions
    2022-11-29 14:35:31.246590+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226230
    2022-11-29 14:35:31.246977+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226231
    2022-11-29 14:35:31.247210+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226232
    2022-11-29 14:35:31.247426+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226233
    2022-11-29 14:35:31.247695+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226234
    2022-11-29 14:35:31.247910+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226235
    2022-11-29 14:35:31.248127+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226236
    2022-11-29 14:35:31.248414+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226237
    2022-11-29 14:35:31.248674+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226238
    2022-11-29 14:35:31.248981+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226239
    2022-11-29 14:35:31.249333+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226240
    2022-11-29 14:35:31.249557+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226241
    2022-11-29 14:35:31.249772+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226242
    2022-11-29 14:35:31.250035+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226243
    2022-11-29 14:35:31.250265+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226244
    2022-11-29 14:35:31.250480+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226245
    2022-11-29 14:35:31.250702+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226246
    2022-11-29 14:35:31.250916+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226247
    2022-11-29 14:35:31.251134+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226248
    2022-11-29 14:35:31.251346+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226249
    2022-11-29 14:35:31.251557+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226250
    2022-11-29 14:35:31.251774+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226251
    2022-11-29 14:35:31.251986+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226252
    2022-11-29 14:35:31.252198+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226253
    2022-11-29 14:35:31.252407+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226254
    2022-11-29 14:35:31.252625+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226255
    2022-11-29 14:35:31.252841+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226256
    2022-11-29 14:35:31.253074+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226257
    2022-11-29 14:35:31.253293+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226258
    2022-11-29 14:35:31.253506+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226259
    2022-11-29 14:35:31.253712+0800 [49986:12918440] UnityIAP: Finishing transaction 2000000214226260
    2022-11-29 14:35:31.255691+0800 [49986:12918440] UnityIAP: PaymentQueueRestoreCompletedTransactionsFinished
    2022-11-29 14:35:31.255984+0800 [49986:12918440] UnityIAP: Refresh app receipt
    2022-11-29 14:35:32.780852+0800 [49986:12918440] UnityIAP: RefreshReceipt status 1
    Unity IAP: <b>Unity In-App Purchasing</b> requires <b>Unity Gaming Services</b> to have been initialized before use.
    - Find out how to initialize <b>Unity Gaming Services</b> by following the documentation <i>[URL]https://docs.unity.com/ugs-overview/services-core-api.html#InitializationExample[/URL]</i>
    or download the <i>06 Initialize Gaming Services</i> sample from <i>Package Manager > In-App Purchasing > Samples</i>.
    - If you are using the codeless API, you may want to enable the enable <b>Unity Gaming Services</b> automatic initialization by checking the <b>Automatically initialize Unity Gaming Services</b> checkbox at the bottom of the <b>IAP Catalog</b> window
    2022-11-29 14:35:32.788132+0800 [49986:12918440] UnityIAP: PurchaseProduct: com.xxxxxxxxxxxxxxx
    2022-11-29 14:35:32.795932+0800 [49986:12918440] UnityIAP: UpdatedTransactions
    2022-11-29 14:35:32.796038+0800 [49986:12918440] UnityIAP: DuplicateTransaction error with product com.xxxxxxxxxxxxxxx and transactionId 2000000214226236
    onPurchaseFailedEvent(productId:xxxxxxxxxxxxxxx message:Duplicate transaction occurred)
    OnPurchaseFailed
     
    novaVision likes this.
  12. aVerrecchia

    aVerrecchia

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    34
    Hello @mindvivid It looks like the transaction 2000000214226236 was processed then the user tried to purchase that product again, which resulted in an DuplicateTransaction error.
    Could you provide more details on the product's type? If the processedPurchase for 2000000214226236 is still pending, then the DuplicateTransaction error is expected.
    Otherwise, it could be a known bug : [Purchasing or fetching iOS products firing Multiple events]. We will include a bugfix in our next major release.
     
  13. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    Same here on Unity 2021.3, IAP 4.5.1.
    We got subsription which need to be verified on login to get access to the app. Sometimes, randomly, our testers from external tester group in TestFlight gt this error on subscription purchase. Was weird to read here the Unity team doesn't know actually how subscriptions work in TestFlight sandbox - subscriptions are reset automatically, even if it's auto-renewable. That' why it's a sandbox! If you use a sandbox user for purchases you can set the auto-expire time in Apple Developer dashboard - from 5mins to 1h max. I assume when testers use their primary Apple ID for sandbox purchase subscriptiosn will reset in that range. I didn't figure out what time range exatly, but for sure, after 1 hour they will need to make the purchase again. Purhases restores will not work after it's expires as well - looks like Apple completely reset entire purchase history.
    I am not 100% sure it was always like that because current project is the 1st for me where we use Subscriptions. Before, working on consumable and non-consumable IAP ~year ago I don't remember such issues.

    So, regarding this bug - definitely it's Unity issue, by some reason it process 20+ purchases same time at a single purchase attempt. 4.5.2 changelog doesn't provide any fix for that. Furthermore we absolutely have no idea how does it works in production. Is there any stable IAP version?
     
    aVerrecchia likes this.
  14. aVerrecchia

    aVerrecchia

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    34
    Hello @novaVision the known [Purchasing or fetching iOS products firing Multiple events] bug will be fixed in our next major release (5.0.0). As of now, 4.5.2 is the latest stable IAP version.
     
    Fatkid11 likes this.
  15. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    @aVerrecchia the problem is that new "major" release will bring some other bugs together with some know issues fixes - unfortunately that's how Unity works according to my 8 years experience using Unity IDE.
    That's why for me is more important that such common feature for mobile platforms as IAP works as it should, without ****ing bugs on purchase attempt.

    Just try to understand how does it looks like from our app developers side! How can I move the app to production with that? You might be also noticed that December is one of the best time to release the apps.

    That's why I am asking again - what is the version of Unity IAP I can use NOW! without the purchase bug mentioned above. I don't wish to wait your major release and some month+ more until you fix your major release
     
  16. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    229
    For the multiple "Finishing Transaction", this is something we must do to inform Apple that we have processed the transaction, otherwise they will keep sending them again.

    What happens is that Apple sends back every previous transaction with a new transaction id. Most of those are no longer valid (expired, cancelled and/or refunded) and will simply end in the "Finishing Transaction" without doing anything, but the valid ones will go through your processPurchase where you can handle them.

    The reason you get these now is because subscriptions can be renewed which creates a new transaction every time. When Apple sends them all back, every past renewal triggers a new transaction too. Those do get ignored when they're no longer valid, but there's still the noise from the "Finishing transaction" being logged.
    Consumables are not stored on Apple's side so they are not sent back and non-consumables are usually a 1 time purchase so they don't get multiple transactions.

    We don't control which transactions we receive since we use a listener to get them from Apple. The only thing we can do is improve how we are sorting them to reduce how many reaches your processPurchase, but we still have to call the finishTransaction on each one of them. We will also look into the logging to reduce the noise generated by those that are no longer valid.

    There's no IAP version without this since it has always worked this way for Apple, but other than the noise from the logging, there should be no other impact.

    On your end, the important part is to process the purchases going through your processPurchase.
     
    akhror_unity likes this.
  17. hw_pete

    hw_pete

    Joined:
    Sep 11, 2020
    Posts:
    8
    Hi! Was just hoping to find out if there's an expected date / ballpark date for the 5.0.0 release? I'm seeing the same issue as previously reported and there doesn't seem to be any workaround I can do while waiting for v5.

    For clarity, the issue I'm seeing:

    1. Purchase subscription item.
    2. Wait for it to expire (not that long when in sandbox)
    3. Restore purchases (I see the transaction ID logged out as "UnityIAP: Finishing transaction 123456789" for example). Note that the ProcessPurchase callback is not triggered at all.
    4. Attempt to purchase the same item, get DuplicateTransaction error.

    Restarting the app and attempting to purchase without first doing a restore leads to a successful purchase.
     
  18. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    229
    Hello hw_pete,
    For the iOS products firing multiple events, we added the Product.appleProductIsRestored in 4.6.0 which allows you to ignore these in the processPurchase.

    For the case you are describing, unfortunately, there's not much we can do about it since Apple sends back the expired subscription in this case. Since that transaction was already confirmed on your side, we ignore it with a DuplicateTransaction error.
    This requires restarting the application for Apple to send the new transaction when attempting to purchase it. Subscriptions that auto-renew also require the application to be restarted to be updated, so this might be related.
     
    thorikawa likes this.
  19. nwtesting

    nwtesting

    Joined:
    Jan 31, 2019
    Posts:
    4
    hey I'm also facing this duplicate transaction issue frequently. Im facing in weekly and monthly subscription pack sandbox account.
     
  20. viku_99

    viku_99

    Joined:
    Dec 14, 2016
    Posts:
    11
    using unity version 2020.32f with IAP version 4.5.3 issue still exist and its annoying.
    @Yannick_D
    First Issue
    - process purchase method fires multiple times even there are two products still it fires multiple time.
    - Duplicate transaction issue
    steps (Apple Sandbox Env)
    1: go and restore
    2. try to puchase product
    3. get duplicate transaction error