Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Understanding IAP on Sample project

Discussion in 'Unity IAP' started by Suduckgames, Apr 19, 2019.

  1. Suduckgames

    Suduckgames

    Joined:
    Nov 28, 2016
    Posts:
    218
    Hi all, I am trying to figure out how the IAP system works in order to implement it. But I have a lots of question about it, just looking at the sample project and documentation doesn't seem to be enough.

    I just download the sample project > Update the iap plugin to 1.22.0 > I add a product throught the IAP Catalog window (instead of code) and then I use this piece of code ( in OnInitialized to be sure this is initializated) to show the items in the console as suggested in the "browsing products" documentation

    Code (CSharp):
    1.  
    2.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    3.     {
    4.         MyDebug("OnInitialized: PASS");
    5.  
    6.         m_StoreController = controller;
    7.         m_StoreExtensionProvider = extensions;
    8.  
    9.  
    10.         foreach (var product in controller.products.all)
    11.         {
    12.             MyDebug(product.metadata.localizedTitle);
    13.             MyDebug(product.metadata.localizedDescription);
    14.             MyDebug(product.metadata.localizedPriceString);
    15.         }
    16.     }
    17.        
    However this code doesn't show the product added throught the IAP Catalog window. If I eliminate the products added by code , it fails because there is no products available ( even 1 is added by the catalog.)

    I tryed also using
    Code (CSharp):
    1.     builder.useCatalogProvider = true;
    but the result is the same

    If I start a project from scratch. It only shows the catalog items if the "programatically" items are added along them. If I comment these lines
    Code (CSharp):
    1.         //builder.AddProduct(GOLD_50, ProductType.Consumable);
    2.         //builder.AddProduct(NO_ADS, ProductType.NonConsumable);
    3.         //builder.AddProduct(SUB1, ProductType.Subscription);
    Then, no product is showed

    I have some questions:

    1.- Why is this happening?
    2.-Also, in the documentation the manager is not a monobehaviour but in your sample project, it is. What is the best practices regards initilizating the IAP system?
    3.- I have 2 scenes (menu and game) and I will like to implement IAP in both sides, Should I make a static IAPmanager?
    4.- When I should initializate the IAP system? At the awake of the game, or when I want to show the IAPs?

    Hope you can give more insights about how this works.

    Thank you in advance and sorry about my english
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    1) Here is the code that I use to fetch the products from the catalog:

    StandardPurchasingModule module = StandardPurchasingModule.Instance();
    ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
    ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
    IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, catalog);
    UnityPurchasing.Initialize(this, builder);
    MyDebug("Initialized IAP!");

    2) Should not matter

    3) Yes

    4) Generally at the very start of the game
     
  3. space_bar

    space_bar

    Joined:
    Jun 21, 2019
    Posts:
    4
    The documentation on unity IAP is extremely poor. The documentation only describe the codeless IAP while briefly mentioning scripting. The reference of UnityIAP is hard to find and I could not find IAPConfigurationHelper. Only searching for useCatalogProvider yielded this result in the search engine.
    It will be very helpful to get these documentation/references updated. In addition the unity IAP tutorial has hardcoded all the catalog information and hence this information is completely missing.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What are you attempting to do? I've never needed to use IAPConfigurationHelper. Granted, your point about documentation is correct, we are waiting on the all Package Manager release soon. To add your products in the Catalog via scripting:

    Code (CSharp):
    1. ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog();
    2. foreach (ProductCatalogItem product in catalog.allProducts)
    3. {
    4.     MyDebug("Product = " + product.id);
    5. }
    I would recommend starting with the Sample IAP Project here: https://forum.unity.com/threads/sample-iap-project.529555/
     
  5. space_bar

    space_bar

    Joined:
    Jun 21, 2019
    Posts:
    4
    I have found my answer thanks to this thread. The reason to use IAPConfigurationHelper is so that I do not have to rewrite the code of copying the product definition, metadata which IAPConfigurationHelper already does.

    However, my point was more around just lack of documentation. For instance, even ProductCatalog is missing from documentation. Its just very hard to find something you don't know

    It is hard to locate the right IAP project because documentation links to https://learn.unity.com/tutorial/unity-iap#5c7f8528edbc2a002053b46e which has no reference to product catalog.

    The lack of documentation around IAP has been brought up multiple times (https://forum.unity.com/threads/where-has-unity-iap-scripting-reference-gone.660454/).

    I think just adding the link of the IAP project in the documentation (where scripting is mentioned) will be super helpful. Hope you consider this while the work is still in progress.