To handle pending google play transactions we have to check the int value of google.purchaseState, which for a pending state returns 4. The Unity IAP enum only handles states 0, 1 and 2.
To clear up the confusion about documentation - it seems that Unity’s IAP is using the getOriginaljson purchaseState value which returns 4, instead of calling google billing’s getPurchaseState() method call which would return the correct enum value 2 according to Purchase.PurchaseState | Android Developers
Thank you for the request!
I’ve written a ticket for the team so we can make it easier to obtain the purchase state at any time and also update the documentation.
Was there a specific case where you needed the purchaseState?
We do already use the getPurchaseState internally to handle pending transactions properly:
-Deferred purchases will call the IGooglePlayConfiguration.NotifyDeferredPurchase
-Once they change to a purchased state, the IStoreCallback.OnPurchaseSucceeded will be called
When fetching purchases, the IStoreCallback.OnAllPurchasesRetrieved will also return purchases that have the getPurchaseState() PURCHASED
Hi, do you know in which version this was introduced? As of ~4.1.5(?) we need to check the purchase state, as players were exploiting pending transactions to trigger in-app purchases.
I just saw the changelog of 3.2.0 - maybe instead of that hack that is recommended it would be better to extend that example code with a IsPurchasedProductDeferred() call?
Also in the “store specific details” example code it’s suggested to iterate over “google.purchaseState” which is however the raw json value from getOriginaljson, instead of the getPurchaseState() enum value
These were introduced before 4.1.5, but I just noticed there’s another other case where this isn’t checked. We will investigate this to see if it can be improved.
The IsPurchasedProductDeferred() does the same thing as the “hack”. This can be used for now, but it would be better if we made the state available if there’s a need to validate other states than only deferred.
Thanks for pointing out to the documentation containing errors, we will go over it and fix this at the same time!
sorry just to clarify - is this ‘hack’ a Unity IAP package oddity, or does the official google play billing libraryactually return 4 for purchase state?