Search Unity

Codeless IAP OnInitialized

Discussion in 'Unity IAP' started by Livealot, Jun 12, 2019.

  1. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    I'm hoping to connect the dots between the IAPDemo approach of creating an IStoreListener and the Codeless IAP approach. Both have an OnInitialized that gets called when everything is ready.

    I'm using the Automatically Initialize checkbox in the IAP catalog but I'm having trouble listening for OnInitialized. It is triggered in the default CodelessIAPStoreListener but not in my custom IStoreListener.

    Is there a way to listen to the listener so I can piggyback on the default trigger?

    There's an old thread that talks about some bools that I could ping, but I'd prefer to listen for the trigger from my custom script.

    I don't want to change CodelessIAPStoreListener.cs since that will be overwritten with every update, but it would be nice if that script fired events that we could listen for in our custom scripts

    [Solved] Codeless IAP and store initialization - Unity Forum
     
    Last edited: Jun 12, 2019
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    As a new user, it is confusing which approach/tutorial to follow. I would suggest trying to make that fork in the road clearer somehow. I'd also consider renaming it from "codeless" IAP to something like "basic" IAP or "simple" IAP which adds the connotation that it doesn't have all the bells and whistles of the full API
     
    LagGit likes this.
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    From https://docs.unity3d.com/Manual/UnityIAPCodelessIAP.html

    Codeless IAP is the easiest way to implement in-app purchases in your Unity app. The Unity Editor offers an interface for configuring basic IAP integration using minimal script writing. Note: You still need to use scripting to define how players access their newly purchased content.
     
  5. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    Yep, that's the exact spot I'm suggesting to be more clear about the fork. Currently, I just read "easiest" which sounds good to me with no downsides. I don't read any mention of reduced features/functionality with choosing this path. For example, the fact that you can't listen for OnInitialized like you can if you pick the other path.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can certainly extend the IAPButton.cs class if you wish
     
  7. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    I've already built the workaround I need, using the provided bools that are available. I'm just trying to post what I learned to help others avoid the dead-ends I hit.

    If CodelessIAPStoreListener.cs implemented everything that IStoreListener did, there wouldn't even be a fork to worry about or workaround needed. Folks could just start with the "easiest" codeless path, and then add functionality as needed following the tutorials for the full IAP.
     
    Plummers likes this.
  8. pjj_gpu

    pjj_gpu

    Joined:
    Dec 7, 2015
    Posts:
    3
    I agree. with Livealot, CodelessIAP is a great start until you realize you might need more control. One solution might be for Unity to convert CodelessIAPStoreListener.cs to a base with virtual functions? Then you don't have to change a standard code file that might be updated by Unity and you don't have to write everything yourself from scratch. You could easily add or replace functionality one method at a time. As Livealot mentioned you probably want to display OnInitialization error messages to your user in your UI. (Purchase errors ARE available as callbacks, however overall Initialization failure isn't exposed Codelessly, yet?)

    A separate issue.... would it be hard to add another failure reason:
    Existing
    PurchasingUnavailable = 0,
    NoProductsAvailable = 1,
    AppNotKnown = 2
    New
    NoInternet = 3
    Which would allow you to direct the user specifically to connect. PurchasingUnavailble might have several different causes I imagine? I know, in code I could ping a website to check internet connectivity myself, but I am lazy :)
     
    JeffDUnity3D likes this.
  9. eggtart

    eggtart

    Joined:
    Feb 4, 2013
    Posts:
    46
    Hi Livealot, could you describe the workaround that you have implemented? I just want to get the product metadata from the StoreController, but don't know how...
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The Sample IAP project mentioned previously has this code (don't use Codeless for this)
    Code (CSharp):
    1.  foreach (UnityEngine.Purchasing.Product item in m_StoreController.products.all)
    2.         {
    3.  
    4.             if (item.receipt != null)
    5.             {
    6.                 MyDebug("List Product = " + item.definition.id.ToString() + ", Trans = " + item.transactionID.ToString());
    7.             }
    8.         }
     
  11. eggtart

    eggtart

    Joined:
    Feb 4, 2013
    Posts:
    46
    Thanks!

    I found that I can get the products from CodelessIAPStoreListener.Instance.StoreController. But have to make sure that .initializationComplete is true.
     
    CreativeKinase likes this.
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You shouldn't be coding Codeless. It is not supported. If you need to code anything, that is a signal to use scripted IAP.