Purchase failed because Purchasing was not initialized correctly

I’m testing a consumable purchase on Android and I had it working once but then for an unknown reason it stopped working when I click the buy button.

When checking the ADB LOG it looks like there is a JSON error.

When it worked once I was using manual initialization i.e. not using the provided catalog and buttons.
Now I’m trying the IAP catalog and automatic Initialization but neither approaches are working anymore.

Not really sure what I’m doing wrong.

12-21 19:31:13.520 5075 5107 I UnityIAP: Starting in-app billing setup.
12-21 19:31:13.530 5075 5075 I UnityIAP: Billing service connected.
12-21 19:31:13.530 5075 5161 I UnityIAP: invoking callback
12-21 19:31:13.530 5075 5161 I UnityIAP: Checking for in-app billing 3 support.
12-21 19:31:13.535 5075 5161 I UnityIAP: In-app billing version 3 supported for games.starberry.coffeecorp
12-21 19:31:13.540 5075 5161 I UnityIAP: Subscriptions AVAILABLE.
12-21 19:31:13.545 5075 5161 I UnityIAP: Subscription upgrade and downgrade are AVAILABLE.
12-21 19:31:13.548 5075 5161 I UnityIAP: Subscriptions information parse AVAILABLE.
12-21 19:31:13.551 5075 5161 I UnityIAP: VR supported.
12-21 19:31:13.551 5075 5161 I UnityIAP: onIabSetupFinished: 0
12-21 19:31:13.551 5075 5161 I UnityIAP: Requesting 1 products
12-21 19:31:13.552 5075 5161 I UnityIAP: QueryInventory: 1
12-21 19:31:13.552 5075 5161 I UnityIAP: invoking callback
12-21 19:31:13.552 5075 5161 I UnityIAP: Querying owned items, item type: inapp
12-21 19:31:13.552 5075 5161 I UnityIAP: Package name: games.starberry.coffeecorp
12-21 19:31:13.552 5075 5161 I UnityIAP: Calling getPurchases with continuation token: null
12-21 19:31:13.558 5075 5161 I UnityIAP: Owned items response: 0
12-21 19:31:13.558 5075 5161 I UnityIAP: Sku is owned: games.starberry.coffeecorp.iap.tests.gold.one
12-21 19:31:13.559 5075 5161 I UnityIAP: Continuation token: null
12-21 19:31:13.559 5075 5161 I UnityIAP: Querying SKU details.
12-21 19:31:13.566 5075 5161 I UnityIAP: Querying owned items, item type: subs
12-21 19:31:13.566 5075 5161 I UnityIAP: Package name: games.starberry.coffeecorp
12-21 19:31:13.567 5075 5161 I UnityIAP: Calling getPurchases with continuation token: null
12-21 19:31:13.601 5075 5161 I UnityIAP: Owned items response: 0
12-21 19:31:13.601 5075 5161 I UnityIAP: Continuation token: null
12-21 19:31:13.601 5075 5161 I UnityIAP: Querying SKU details.
12-21 19:31:13.608 5075 5161 I UnityIAP: Querying owned items’ purchase history, item type: subs
12-21 19:31:13.608 5075 5161 I UnityIAP: Package name: games.starberry.coffeecorp
12-21 19:31:13.608 5075 5161 I UnityIAP: Calling getPurchaseHistory with continuation token: null
12-21 19:31:13.697 5075 5161 I UnityIAP: Purchase history response: 0
12-21 19:31:13.697 5075 5161 I UnityIAP: Continuation token: null
12-21 19:31:13.697 5075 5161 I UnityIAP: onQueryInventoryFinished: true
12-21 19:31:13.697 5075 5161 I UnityIAP: Inventory refresh successful. (response: 0:OK)
12-21 19:31:13.697 5075 5161 I UnityIAP: The number of owned skus is0
12-21 19:31:13.697 5075 5161 I UnityIAP: The number of purchased skus is1
12-21 19:31:13.697 5075 5161 I UnityIAP: The number of subscriptions purchased history is0
12-21 19:31:15.119 5075 5107 E Unity : Exception: Error: called non-existent method System.String SimpleJson.SimpleJson::SerializeObject(System.Object)
12-21 19:31:15.119 5075 5107 E Unity : at SimpleJson.SimpleJson.SerializeObject (System.Object ) [0x00000] in <00000000000000000000000000000000>:0
12-21 19:31:15.119 5075 5107 E Unity : at UnityEngine.Purchasing.PurchasingManager.OnProductsRetrieved (System.Collections.Generic.List`1[T] products) [0x00000] in <00000000000000000000000000000000>:0
12-21 19:31:15.119 5075 5107 E Unity : at UnityEngine.Purchasing.JSONStore.OnProductsRetrieved (System.String json) [0x00000] in <00000000000000000000000000000000>:0
12-21 19:31:15.119 5075 5107 E Unity : at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <00000000000000000000000000000000>:0
12-21 19:31:15.119 5075 5107 E Unity :
12-21 19:31:15.119 5075 5107 E Unity : (Filename: currently not available on il2cpp Line: -1)

Please use IAP 1.20.1 and the latest version of Unity. This issue was fixed already. And THANK YOU for providing the logs, it is always very helpful. If you are already using 1.20.1 and a recent version of Unity, we will need to revisit this issue.

1 Like

I am having a very similar error to summerian and I have checked and everything appears to be updated. I am going to manually update to unity 2018.3 to see if this fixes it.

And make sure you are using IAP 1.20.1 (it’s the latest in the asset store)

I’m already using IAP 1.20.1 and I just upgraded from 2018.3.b12 to Unity 2018.3.0f2 and now I’m getting another error.
I’m now using the codeless approach and created a button via the IAP menu. The product ID corresponds correctly to the Google Play setup.
When I click the button I see this in the log:

12-28 10:54:44.360 29888 29916 E Unity : Purchase failed because Purchasing was not initialized correctly
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.Logger:Log(LogType, Object)
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.Purchasing.CodelessIAPStoreListener:InitiatePurchase(String)
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.Events.UnityEvent:Invoke()
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.EventSystems.StandaloneInputModule:processTouchPress(PointerEventData, Boolean, Boolean)
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.EventSystems.StandaloneInputModule:processTouchEvents()
12-28 10:54:44.360 29888 29916 E Unity : UnityEngine.EventSystems.StandaloneInputModule:process()

@summerian That is a different issue, and may be caused by several things. Make sure you follow the directions here Unity - Manual: Configuring for Google Play Store . And make sure you test with a tester account and not your developer account.

1 Like

is it possible to test purchase from inside unity ??

No, you need to install on an actual device https://docs.unity3d.com/Manual/UnityIAPGoogleConfiguration.html and https://docs.unity3d.com/Manual/UnityIAPAppleConfiguration.html