Please add google's pending enum state to Unity IAP package

Since we have to handle pending transactions according to the google docs explicitly, it seems weird that handling google play’s pending implementation with Unity IAP requires this hack from 2021 :

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.

  1. It would be great if Unity IAP could finally add the “Pending” enum ( 4 ) here :
    Enum GooglePurchaseState | In App Purchasing | 4.0.3 as it returns undocumented json values there.
  2. Or if Unity IAP would start calling getPurchaseState() and get us these in a separate enum that matches the google docs.

Also for some reason the entry for “GooglePurchaseState” is duplicated in the docs since version 3.0

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

Google’s integration docs have a note not to use the original json in this case :

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.

So for example this example code would validate pending purchases as valid purchases :
https://docs.unity3d.com/Packages/com.unity.purchasing@4.1/manual/UnityIAPValidatingReceipts.html#validating-receipts

  1. 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?

  2. 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.

  1. 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.
  2. Thanks for pointing out to the documentation containing errors, we will go over it and fix this at the same time!
1 Like

sorry just to clarify - is this ‘hack’ a Unity IAP package oddity, or does the official google play billing library actually return 4 for purchase state?

Because its 2024 and its still not documented as such on the official docs:
https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState

Or… is it that the Unity IAP package maps Purchase.PurchaseState.PENDING to 4 ?