Search Unity

Unity Codeless IAP - Purchase failed because Purchasing was not initialized correctly (iOS only)

Discussion in 'Unity IAP' started by Jimbo_Slice, Jun 23, 2019.

  1. Jimbo_Slice

    Jimbo_Slice

    Joined:
    Oct 1, 2015
    Posts:
    44
    Hi everyone,

    I would appreciate a bit of help. I have been stuck on this for days and it is really frustrating me. I feel like I have exhausted all the tutorials, docs, YouTube videos etc. so maybe someone has some first-hand experience that can help me out?

    I have one simple IAP in my mobile game implemented using Codeless IAP (version 1.22.0 with Unity 2019.1.0f2) - to remove ads. It works fine in the Editor and flawlessly on Android (it has actually been approved for publication on Google Play but this App Store release is delaying the launch).

    Things that I have done so far:

    - In-App Purchase has been added on App Store Connect and its status is 'Ready for Submission'. Can someone clarify... the ID for my IAP is "remove_adverts" in the IAP Catalog, should this be the same on the App Store or should I add the bundle identifier as well? e.g. com.CompanyName.AppName.remove_adverts

    - EDIT: All my Banking & Tax settings are set up and approved on App Store Connect

    - Ensured that my Purchasing script is attached to an empty GameObject that is never disabled etc. so it should initialize

    - In Unity IAP Catalog have ensured Apple SKU and Apple Team ID are the same as App Store Connect. Have also ensured everything is synced to UDP. Automatically initialise UnityPurchasing is set to true

    - Ensured that In-App Purchasing Capability is enabled in Xcode

    - Enabled StoreKit.framework in Xcode

    - Archived and Uploaded to App Store Connect through Xcode

    - Invited my Apple developer account to test the app through Test Flight. Is it problematic that the test account is the same as the developer account?

    Then when I install the app through TestFlight and run it I press the IAP button and nothing happens.

    My Device Log displays the following...




    Purchase failed because Purchasing was not initialized correctly

    UnityEngine.Purchasing.CodelessIAPStoreListener:InitiatePurchase(String)

    UnityEngine.Events.UnityAction:Invoke()

    UnityEngine.Events.UnityEvent:Invoke()

    UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)

    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)

    UnityEngine.EventSystems.StandaloneInputModule:processTouchPress(PointerEventData, Boolean, Boolean)

    UnityEngine.EventSystems.StandaloneInputModule:processTouchEvents()

    UnityEngine.EventSystems.StandaloneInputModule:process()



    (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 48)




    Any help would be greatly appreciated!

    J
     
    Last edited: Jun 23, 2019
  2. Jimbo_Slice

    Jimbo_Slice

    Joined:
    Oct 1, 2015
    Posts:
    44
    Just tried downgrading to Unity Codeless IaP 1.20 and the problem remains the same
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please compare your implementation to the sample IAP projects here. The first is scripted (my preference) and the second project is Codeless. The productIDs need to be the same, please show a screenshot of your IAP Catalog list, and the IAP as defined on Apple. https://forum.unity.com/threads/sample-iap-project.529555/ I might suggest to add Debug.Log statements in your code, they will show up when doing local iOS device testing . Make sure you have also hooked up the Purchase Failure event in your IAP button.
     
  4. Jimbo_Slice

    Jimbo_Slice

    Joined:
    Oct 1, 2015
    Posts:
    44
    So I am ashamed to say the issue was down to my human error :(

    Thanks for your reply Jeff
     
  5. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    73
    What was your error? I'm having the same problem.
     
  6. Jimbo_Slice

    Jimbo_Slice

    Joined:
    Oct 1, 2015
    Posts:
    44
    Mine was a slight difference in the product key (string) between my Unity Project and what I had configured on App Store Connect.

    Hope you get it sorted!
     
  7. simon_unity488

    simon_unity488

    Joined:
    Oct 23, 2019
    Posts:
    8
    I was having the exact same error messages but it turned out I was stupid enough to try to test my app without internet connection on my test device.
    The logs in XCode weren't sufficient enough to find this out.

    Probably not a lot of you will be dumb enough to make the same mistake as I did but make sure you have internet!
     
  8. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    118
    @simon_unity488 Are you saying that this error can be triggered just because a user clicks on the IAP button with internet turned off?

    Because we've been worried for weeks why we're getting several errors like this from our released app every day (GameAnalytics dashboard reported back about the errors). We also have codeless IAP and when we tested it on our own device (both sandbox and in the versions downloaded), we never had any issue and were able to complete the purchase. So perhaps the errors are harmless and just show that some people taps on the no-ads button when there's no internet?

    Would be nice for Unity to fix this and mute errors when the reason for purchase fail is no internet or just replace it with a warning instead.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    IAP will not initialize without the network, and should trigger OnInitializedFailed
     
  10. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    233
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  12. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    233
    Yes, I'm using CodelessIAP.
    Sorry for the typo, OnPurchaseFailed is not called for the IAP button.
    In my setup I only have an IAP button and one IAPListener, non of them can't handle OnInitializedFailed, but they don't receive OnPurchaseFailed after purchase attempt in case of init was failed.
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show a screenshot of your Inspector properties for your IAP Button, what method do you call for Purchase Failed?
     
  14. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    233
    Currently I'm using IAPListener.OnPurchaseFailed , so I had to remove OnPurchaseFailed callback from IAPButton (as I believe they do the same). If you need more context, here it is:
    - I'm using Application.logMessageReceived to detect and show errors and exceptions to users.
    - I'm receiving the error message from CodelessIAPStoreListener "Purchasing failed to initialize" in case when users don't have Internet access, so I had to ignore this error inside logMessageReceived callback.
    - I still don't know if IAP initialization failed or not, as all I have are IAPButton and IAPListener. It looks like I need to implement my own IStoreListener to know if IAP was initialized.
    - Users can open Game Shop and press Purchase button, and my app shows "loading" screen.
    - CodelessIAPStoreListener prints "Purchase failed because Purchasing was not initialized correctly".
    - IAPListener doesn't receive OnPurchaseFailed event, so my app stucks with "loading" screen.
    upload_2021-8-3_18-48-26.png
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You would not call OnPurchaseFailed from the IAP button like that, you are mixing Codeless with Scripted IAP, unfortunately a rather common mistake. You just put your own method there, and don't use any methods from UnityEngine.Purchasing. You are coding Codeless! A bit contrary. Just use Scripted IAP instead
     
    steril likes this.
  16. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    233
    Please explain what is my mistake? I use only IAPButton and IAPListener provided by Codeless package, and as these both scripts have callbacks, I use them in my Game Shop.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Since you need customization (checking for internet access or anything else), don't use Codeless. Use Scripted IAP instead. In other words, if you need to code, don't use Codeless, as the name implies. It's only for very basic use, like in a demo.
     
    deniz_eren likes this.
  18. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    233
    Ok, thanks for your time!