"Fetch" and localized prices from App Stores manually



  • Hej,
    instead of IAPItem component I'm using my own -> ProductPurchase script, which works just fine when it comes to purchasing, but now I have obvious problem with 'fetching' to get localized prices.

    How can I use that scripting part for fetching/localizing in my own "ProductPurchase" script? since you are using 'IAPItem' component for that purpose. I have problems calling Init(Product product) function, e.g accessing UnityEngine.Purchasing class.
    Appreciate any tips! Thanks.



  • Hi,

    the IAPManager provides access to the Unity IAP interface if you would like to get product information manually. Note that the store data is not set right away, since it is fetched asynchronously, meaning you cannot access it e.g. on app launch directly. Here's the reference on getting a product's price string:

    IAPManager.controller
    IStoreController.products
    ProductCollection.WithID
    Product.metadata
    ProductMetadata.localizedPriceString



  • Ok, I'm trying to call this function in Start() in order to get product meta -> currency:
    GetIAPIdentifier(productId);

    public string GetIAPIdentifier(string storeId)
    {
        #if SIS_IAP
        if (controller != null && controller.products != null)
        {
            Product product = controller.products.WithStoreSpecificID(storeId);
            if (product != null)
                return product.definition.id;
    
            string pr = product.metadata.localizedPriceString;
            price[0].text = pr;
        }
        #endif
        return storeId;
    }
    

    *it's not in the first scene, but in Shop scene; productId is product identifier.

    But it doesn't work, looks like 'controller' or 'controller.products' is null?

    I'm using public UILabel[] price; [NGUI type] to set a reference to Price string for Buy button in my "ProductPurchase" script. I only need to fetch Price string, to display local currency.

    How can I access it correctly from IAP group/ settings manually?
    a scripting hint/example perhaps? Appreciate it!



  • If the controller or controller.products is null, either you misconfigured your settings (billing initialization fails) or you are trying to access it too early.

    I would recommend adding an event to the IAPManager's OnInitialized method. Try to access the product data within Start() in your shop scene, but also subscribe to the event in case it goes off at some later point while within the shop scene.

    If you can't access the data at all, insert more Debug.Log messages at each step to see exactly where it fails. Hope this helps!



  • @Baroni said in "Fetch" and localized prices from App Stores manually:

    If the controller or controller.products is null, either you misconfigured your settings (billing initialization fails) or you are trying to access it too early.

    Ok, thanks! I will try to follow your advice.

    I don't think misconfiguration is a case since I already tested Shop in production - it is possible to buy products, it works fine. So.. I have problem with accessing and timing?



  • So Unity IAP examples states that not only controller, but also

    extensions
    

    must be not null.

    When these 2 things are not null then we can get localized price in next way:

    IAPManager.controller.products.WithID(productId).metadata.localizedPriceString)
    

Log in to reply