[Solved] IStoreController.InitiatePurchase(product) not being executed/hanging

Hi guys,
I’ve been trying to implement IAP for a while now for my Google Play game, which has been published. I’ve noticed that the call to the function InitiatePurchase() isn’t completing as during runtime.

Giving the result of line: errorText.text = “InitializedPurchase”.ToString(); never being executed, the last thing to be executed correctly is the “Purchasing product asych…”. Any ideas what’s going wrong I’ve referenced this tutorial:

and followed the UnityDocs, with no luck.

private void BuyProductID(string productId)
    {
        // If Purchasing has been initialized ...
        if (IsInitialized())
        {
            // ... look up the Product reference with the general product identifier and the Purchasing
            // system's products collection.
            Product product = m_StoreController.products.WithID(productId);
            // If the look up found a product for this device's store and that product is ready to be sold ...
            if (product != null && product.availableToPurchase)
            {
                Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                errorText.text = (string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                // asynchronously.
                m_StoreController.InitiatePurchase(product);
                errorText.text = "InitializedPurchase".ToString();
            }
            // Otherwise ...
            else
            {
                // ... report the product look-up failure situation
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
                errorText.text = "Failed Purchase".ToString();
            }
        }
        // Otherwise ...
        else
        {
            // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
            // retrying initiailization.
            Debug.Log("BuyProductID FAIL. Not initialized.");
            errorText.text = "Not Initialised".ToString();

        }
    }

Please provide your device logs. On Android, I generally use “adb logcat | grep -i unity”

Hey, did you ever solve this? I am having the exact same problem.

How does one get the log file out of a tablet?

https://discussions.unity.com/t/699654 . And the Sample IAP project is here: https://discussions.unity.com/t/700293

Thanks!

Like Luucccc, my call to InitiatePurchase() just seems to do nothing. It never returns, but it doesn’t block, either. Could it be throwing an exception?

Please post the logs

Haven’t been able to get those out of it, but I wrapped a try/catch block around my call to InitiatePurchase and found it was throwing this exception:

Exception: Error: called non-existent method System.Boolean UnityEngine.VR.VRSettings::get_enabled

What version of Unity are you using?

Looks like this is being discussed in another thread on this forum.

Yes, you might want to hold off on Unity 2019 while we continue to investigate. It works as described on previous versions.

I am also not getting response after purchase , below is the logs which i think might causing problem

MissingReferenceException: The object of type ‘AsyncWebUtil’ has been destroyed but you are still trying to access it.

Your script should either check if it is null or you should not destroy the object.

UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/MonoBehaviourBindings.gen.cs:62)

UnityEngine.Purchasing.AsyncWebUtil.Post (System.String url, System.String body, System.Action1[T] responseHandler, System.Action1[T] errorHandler, System.Int32 maxTimeoutInSeconds) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.EventQueue.SendEvent (UnityEngine.Purchasing.EventDestType dest, System.String json, System.String url, System.Nullable`1[T] delayInSeconds) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.JSONStore.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionID) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.FakeStore.<>n__0 (System.String id, System.String receipt, System.String transactionID) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.FakeStore+<>c__DisplayClass15_0.b__0 (System.Boolean allow, UnityEngine.Purchasing.PurchaseFailureReason failureReason) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.FakeStore.FakePurchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.FakeStore.Purchase (System.String productJSON, System.String developerPayload) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.JSONStore.Purchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) (at <50891d6b80fb4d02b58505065f8b0238>:0)

UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (UnityEngine.Purchasing.Product product, System.String developerPayload) (at /Users/builduser/buildslave/unity/build/Extensions/UnityPurchasing/Runtime/Purchasing/PurchasingManager.cs:60)

UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (UnityEngine.Purchasing.Product product) (at /Users/builduser/buildslave/unity/build/Extensions/UnityPurchasing/Runtime/Purchasing/PurchasingManager.cs:38)

Purchaser.BuyProductID (System.String productId) (at Assets/Lib/Purchaser.cs:132)

Shop.ShowBasket (System.String productId) (at Assets/Assets/UI/Shop/Source/Shop.cs:181)

TestInterface_BuyTest.OnLeftButtonClick () (at Assets/Assets/UI/TestInterface/Scripts/StateContent/TestInterface_BuyTest.cs:83)

UnityEngine.Events.InvokableCall.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:165)

UnityEngine.Events.UnityEvent.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)

UnityEngine.UI.Button.Press () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)

UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)

UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)

UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)

UnityEngine.EventSystems.EventSystem:Update()

Any idea how to fix it

@Velawoods Why are you seeing references to “fake store”? Is this on Android or iOS? The fake store is only used for demo purposes in the Editor, and does not actually perform real purchases or transactions.

Hi everyone, I have the same problem, with IAP. Someone solved it?
Thank you.

What error are you receiving? Please provide the relevant device logs.

Hi, everyone.
When i run the project on Unity all the IAP systems works fine, but when i run it on an Android device it gives me this error:

Exception: Error: called non-existent method System.Boolean UnityEngine.VR.VRSettings::get_enabled()

at UnityEngine.VR.VRSettings.get_enabled () [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Purchasing.GooglePlayAndroidJavaStore.Purchase (System.String productJSON, System.String developerPayload) [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Purchasing.JSONStore.Purchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (UnityEngine.Purchasing.Product product, System.String developerPayload) [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Purchasing.CodelessIAPStoreListener.InitiatePurchase (System.String productID) [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0

at UnityEngine.Events.UnityEvent.Inv

Currently i’m using IAP Buttons but even with the older method the result is the same.
Ideas on how to fix it?

@Marco6411 Yes! If you are using Unity 2019, then you will need to reinstall Unity to a location with no spaces in the path. C:\Program Files\Unity for example would have a space in it. Then reinstall IAP. We are aware of the issue, and working to fix in an upcoming release. If you are using a version prior, then you must say “Yes, I have made a backup” when prompted to update the API during the IAP import process. IAP Troubleshooting - Remove and Reinstall Unity IAP

@JeffDUnity3D Thanks a lot a lot a lot a lot a lot!!! I think this is a very critical issue, because by default most of the users install unity in C:\Program Files. And when they run the game in device, they just see that IAP is not working and find no reason for it. It should be mentioned boldly during installation so that no one puts space in the path.

It is a temporary bug only and is being fixed.

@JeffDUnity3D Do you mind to check this log? Why IAP not working on Android device? I confirmed that it is working on Editor

2021-02-05 19:54:50.457 9160-9160/com.dragonfoundry.novablitz E/Unity: MethodAccessException: Method UnityEngine.Purchasing.Product:set_transactionID (string)' is inaccessible from method UnityEngine.Purchasing.GoogleFetchPurchases:FillProductsWithPurchases (System.Collections.Generic.IEnumerable`1<UnityEngine.Purchasing.Models.GooglePurchase>)’

at UnityEngine.Purchasing.GoogleFetchPurchases+<>c__DisplayClass6_0.b__0 (System.Collections.Generic.List1 googlePurchases) [0x00000] in <filename unknown>:0 at UnityEngine.Purchasing.GoogleQueryPurchasesService.HandleOnQueryPurchaseReceived (System.Action1 onQueryPurchaseSucceed, System.Collections.Generic.List1 googlePurchasesInSubs, System.Collections.Generic.List1 googlePurchasesInApps) [0x00000] in :0
at UnityEngine.Purchasing.GoogleQueryPurchasesService+<>c__DisplayClass3_1.b__1 (System.Collections.Generic.List`1 googlePurchasesInApps) [0x00000] in :0
at UnityEngine.Purchasing.GoogleQueryPurchasesService.HandleGooglePurchaseResult (UnityEngine.Pu

Please open a new thread, this is a separate issue. We will need more information.

  • Codeless or Scripted IAP
  • Version of IAP (latest is 2.2.7)
  • Version of In App Purchasing library in Package Manager (latest is 2.2.2)
  • Type of product
  • Steps to reproduce (does it happen every time?)

You might compare to the code in the Sample IAP Project here https://discussions.unity.com/t/700293

Please provide your results in a new thread, thanks.