Search Unity

[Solved] Unity IAP calling ProcessPurchase for same product two times

Discussion in 'Unity IAP' started by gilberto_lumentech, Sep 20, 2017.

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

    gilberto_lumentech

    Joined:
    May 6, 2016
    Posts:
    10
    Guys, when I'm buying a CONSUMABLE PRODUCT using Unity IAP on Android, the ProcessPurchase method is being called twice.

    This started to happens today. It's odd because our old builds (from June 2017) are being affected too (using an old Unity Version and old UnityIAP version). This never happened before. It only happens on Android.

    The transaction id and payload are both equal. The Unity is calling the ProcessPurchase one after another.

    Environment:
    Platform: Android
    Unity Version: 5.6.1p2
    Unity IAP Version: 1.13.1 and prior versions
     
    Last edited: Sep 20, 2017
  2. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    Seeing the same thing in older unmodified Android app.
    Does the Unity IAP talk to some Unity backend that perhaps is borked or is this a google thing?
     
  3. gilberto_lumentech

    gilberto_lumentech

    Joined:
    May 6, 2016
    Posts:
    10
    Good question.

    Waiting for feedback from Unity Team.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are not seeing this behavior in Beta/Alpha testing. Can you confirm this only occurs with actual purchases?
     
  5. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    We reproduced the issue with a sandbox purchase (android) as well this morning (again - with older app that was working fine the day before yesterday) - using
    5.6.1f1 and IAP [1.11.2]
     
    Last edited: Sep 20, 2017
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Which Android version are you using?
     
  7. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    "Android OS 7.0 / API-24 (NRD90M/G955FXXU1AQH3)"
    It's a Samsung Galaxy S8+ device (the one we reproduced this morning)
     
  8. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    In fact both users seeing the issue are Galaxy S8 and Android 7.0
     
  9. helton-lumentech

    helton-lumentech

    Joined:
    Feb 2, 2016
    Posts:
    3
    Hi,

    Two users reported this to us, so they are not using sandbox.

    Our versions are the one reported by gilberto-lumentech.

    Also it is an odd behaviour, sometimes the first purchase is correct(calls ProcessPurchase only once), but afterwards it calls always two times. We saw this buying consumables with users that already had non-consumables and with users that did not. It is pretty straight forward to occour and we traced this happening up to builds we did 3 months ago, we didn't want to go much far than that.

    In my case, It got even worst, the google play dialog bugged one time I was testing, instead of presenting the content of the IAP it presented crypted data, and after that, that item is stuck, everytime I try to buy it, it says that I already have it, although ProcessPurchase is never called for that item in my game, but I'm using sandbox.
     
  10. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    Saw the exact same behavior in reproducing this with sandbox account
     
    Last edited: Sep 20, 2017
  11. gilberto_lumentech

    gilberto_lumentech

    Joined:
    May 6, 2016
    Posts:
    10
    Since yesterday, we had more than one thousand duplicated purchases. They were real purchases (not sandbox ones).
     
  12. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    If it helps - we are NOT using unity analytics nor are we using unity receipt validation.
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @jamiel_mf Can you clarify? This thread is about the IAP ProcessPurchase callback being called twice for each purchase. Unity IAP requires Unity Analytics to be enabled.
     
  14. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    Uhhh.... I was basing that solely on the UCB project has an option to 'enable analytics' which I took to mean that it was disabled. Looks like our project DOES have analytics enabled. Is that communication with Unity perhaps the cause of the double ProcessPurchase invocation?

    By the way - WHY does IAP require analytics to be turned on?
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @jamiel_mf We are still investigating the double purchase issue. The services share code resources.
     
  16. gilberto_lumentech

    gilberto_lumentech

    Joined:
    May 6, 2016
    Posts:
    10
    Exactly.
    If I purchase consumable A, then the method is called twice. It does not happens always... It's like 90% of the time.
     
  17. posibillian_tech

    posibillian_tech

    Joined:
    Jan 31, 2017
    Posts:
    12
    Hi, same problem here, Huawei CAM-L2 Android 6.0, LG-D802 Android 5.0.2.
    I cannot reproduce the error in an emulator like BlueStacks.
    Of course we validate the receipt in the backend so there is no actual double purchase, just a silent error, but still, this doesn't happens with iOS, I think.

    09-20 17:16:30.097 10413-10413/? I/UnityIAP: NotifyUnityOfPurchase​

    That's the line before the double call, if that helps.
     
  18. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    Hi @gilberto_lumentech Thank you for reporting this and sharing all these details. I've not been able to reproduce this yet. I've not tested on 5.6.1x yet, however.

    Are the double-purchases seen in log files on the device, or via external log files / analytics?

    Which "payload" are you referring to in the first post of this thread?

    Is there a complete device log-file you would be comfortable sharing with us which demonstrates this issue?

    FYI we use the Google Play "orderId" primarily or "purchaseToken" secondarily for the Unity IAP "transactionId".(Sandbox purchases no longer include orderId as of early 2016, so we use whichever is available.)
     
  19. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    Hi @helton-lumentech thank you for this information. What sort of data was shown in the dialog? Was it garbage data? Or could it be a translation / localization?
     
  20. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    nathanf-unity likes this.
  21. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    relevant?
    https://stackoverflow.com/questions/46343521/in-app-purchase-seems-to-be-called-multiple-times

    But alas - this would require a new client compile with latest libraries - and this is happening with our clients in the field that have been static for weeks...
     
    nicholasr likes this.
  22. jamiel_mf

    jamiel_mf

    Joined:
    Aug 31, 2016
    Posts:
    9
    Wouldn't this (as the google
    Wouldn't this require a client re-compile as the google play billing library is a client-side codebase? That doesn't appear to be the case here.
     
  23. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @jamiel_mf Not necessarily, if Google Play was updated recently on the device for example. And it could be a server-side issue, but unconfirmed at this time.
     
  24. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I'm not seeing the issue using Unity 2017.2.0b10 on an NVIDIA tablet with a Beta test app. Is anyone here seeing the issue with 2017.2 ?
     
  25. wwcolter

    wwcolter

    Joined:
    Nov 4, 2016
    Posts:
    28
    For what it's worth, we are seeing the same issue with both our live build and the new build we're testing. Both are using Unity 5.6.3p1.

    We started seeing duplicates sent on September 5th but only a tiny percentage of our successful GP purchases sent a duplicate. Over the past week the percent has dramatically increased and now we are seeing between 50-75% of our GP purchases sending duplicates. Google often slowly rolls out new updates so I'm suspecting this has something to do with it.

    I responded with the paragraph above on Google's issue tracker and would encourage anyone else noticing it to post.
     
    Last edited: Sep 22, 2017
    nicholasr and nathanf-unity like this.
  26. wwcolter

    wwcolter

    Joined:
    Nov 4, 2016
    Posts:
    28
    More information:

    We see duplicates when the device is using Google Play Store version 8.1.73. On our devices that are using 8.2.38, the issue does NOT occur.

    Unfortunately a lot of our devices that are on store version 8.1.73 claim they're up to date and will not update to 8.2.38.
     
    nicholasr likes this.
  27. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I tested with Google Play Store 8.1.73.S-all and Google Play Services 11.5.09, Unity 5.6.3f1 and IAP 1.13.3, Android 6.0.1 and not seeing the issue.
     
    nicholasr likes this.
  28. wwcolter

    wwcolter

    Joined:
    Nov 4, 2016
    Posts:
    28
    Google responded with

    This will be fixed soon.
    However, your integration with billing flow should work even when onPurchasesUpdate was triggered multiple times, since it could happen anyway. For example, if somebody was buying in parallel on another device with the same @gmail account. And people in some countries (e.g. Spain) do share their @gmail accounts rather frequently with many friends and family members.

    Please, check TrivialDrive_v2 implementation to get an idea, how to gracefully handle such situations: https://github.com/googlesamples/android-play-billing/blob/master/TrivialDrive_v2/shared-module/src/main/java/com/example/billingmodule/billing/BillingManager.java
    The scenario they described isn't the same as ours (two separate legitimate receipts vs a single duplicated receipt) but the point stands: our client/backend systems should be robust enough to not allow duplicate receipts within milliseconds of each other. Ours was a case of a distributed backend having two different servers handling the duplicate requests at the same time without any locking.

    Thanks for all the posts and help on this!
     
    Last edited: Sep 25, 2017
Thread Status:
Not open for further replies.