Search Unity

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

Discussion in 'Unity IAP' started by Luucccc, Apr 23, 2018.

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

    Luucccc

    Joined:
    Jan 22, 2018
    Posts:
    2
    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.
    Code (CSharp):
    1. private void BuyProductID(string productId)
    2.     {
    3.         // If Purchasing has been initialized ...
    4.         if (IsInitialized())
    5.         {
    6.             // ... look up the Product reference with the general product identifier and the Purchasing
    7.             // system's products collection.
    8.             Product product = m_StoreController.products.WithID(productId);
    9.             // If the look up found a product for this device's store and that product is ready to be sold ...
    10.             if (product != null && product.availableToPurchase)
    11.             {
    12.                 Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    13.                 errorText.text = (string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    14.                 // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
    15.                 // asynchronously.
    16.                 m_StoreController.InitiatePurchase(product);
    17.                 errorText.text = "InitializedPurchase".ToString();
    18.             }
    19.             // Otherwise ...
    20.             else
    21.             {
    22.                 // ... report the product look-up failure situation
    23.                 Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    24.                 errorText.text = "Failed Purchase".ToString();
    25.             }
    26.         }
    27.         // Otherwise ...
    28.         else
    29.         {
    30.             // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
    31.             // retrying initiailization.
    32.             Debug.Log("BuyProductID FAIL. Not initialized.");
    33.             errorText.text = "Not Initialised".ToString();
    34.  
    35.         }
    36.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide your device logs. On Android, I generally use "adb logcat | grep -i unity"
     
  3. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    677
    Hey, did you ever solve this? I am having the exact same problem.

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

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    677
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please post the logs
     
  7. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    677
    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
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What version of Unity are you using?
     
  9. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    677
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you might want to hold off on Unity 2019 while we continue to investigate. It works as described on previous versions.
     
  11. Velawoods

    Velawoods

    Joined:
    Apr 30, 2018
    Posts:
    5
    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.Action`1[T] responseHandler, System.Action`1[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.<FakePurchase>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
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @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.
     
  13. doomstudios

    doomstudios

    Joined:
    Mar 29, 2019
    Posts:
    1
    Hi everyone, I have the same problem, with IAP. Someone solved it?
    Thank you.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What error are you receiving? Please provide the relevant device logs.
     
  15. Marco6411

    Marco6411

    Joined:
    Dec 26, 2018
    Posts:
    1
    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?
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @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. https://forum.unity.com/threads/iap-troubleshooting-remove-and-reinstall-unity-iap.511747/
     
  17. Farbin-Fayza

    Farbin-Fayza

    Joined:
    Jan 12, 2017
    Posts:
    1
    @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.
     
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    It is a temporary bug only and is being fixed.
     
  19. genya127

    genya127

    Joined:
    Feb 7, 2017
    Posts:
    7
    @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.<FetchPurchases>b__0 (System.Collections.Generic.List`1 googlePurchases) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.GoogleQueryPurchasesService.HandleOnQueryPurchaseReceived (System.Action`1 onQueryPurchaseSucceed, System.Collections.Generic.List`1 googlePurchasesInSubs, System.Collections.Generic.List`1 googlePurchasesInApps) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.GoogleQueryPurchasesService+<>c__DisplayClass3_1.<QueryPurchases>b__1 (System.Collections.Generic.List`1 googlePurchasesInApps) [0x00000] in <filename unknown>:0
    at UnityEngine.Purchasing.GoogleQueryPurchasesService.HandleGooglePurchaseResult (UnityEngine.Pu
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    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://forum.unity.com/threads/sample-iap-project.529555/

    Please provide your results in a new thread, thanks.
     
Thread Status:
Not open for further replies.