Search Unity

[Help] Dynamic Product Catalog: Custom ICatalogProvider with StandardPurchasingModule

Discussion in 'Unity IAP' started by OrioliBublar, Nov 20, 2018.

  1. OrioliBublar

    OrioliBublar

    Joined:
    Jun 28, 2017
    Posts:
    5
    I want to accomplish a dynamically updating list of available products, controlled by a backend. The ICatalogProvider interface is perfect for it. However, I can't seem to find a way to set it to my implementation anywhere, is there a better/preferred way of adding products dynamically, or should I just add them directly to the ConfigurationBuilder on startup?

    I also notice that the AbstractPurchasingModule that the StandardPurchasingModule inherits from has an IPurchasingBinder but it's protected so I can't access it...

    This is kinda what I would expect to be possible:
    Code (CSharp):
    1.  public class MyIAPStore : IStoreListener, ICatalogProvider
    2.     {
    3.         public MyIAPStore()
    4.         {
    5.             var module = StandardPurchasingModule.Instance();
    6.             // module.SetCatalogProvider(this); <- either this
    7.             var builder = ConfigurationBuilder.Instance(module);
    8.  
    9.             builder.useCatalogProvider = true;
    10.             // builder.SetCatalogProvider(this); <- or this
    11.             UnityPurchasing.Initialize(this, builder);
    12.         }
    13.  
    14.         void ICatalogProvider.FetchProducts(Action<HashSet<ProductDefinition>> callback)
    15.         {
    16.             var products = new HashSet<ProductDefinition>();
    17.             // Fetch the products
    18.             callback(products);
    19.         }
    20.     }
     
    Qray5000 likes this.
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446