Documentation

In-App Purchasing

Client API

SDK API

In-App Purchasing

Create your catalog programmatically

Use the CatalogProvider class to define your catalog in code for flexible or runtime-driven configurations.
Read time 1 minuteLast updated 18 hours ago

You can define your catalog directly in code using the
CatalogProvider
class. This approach gives you full programmatic control over your catalog configuration and is useful in complex scenarios, such as if you have a game with a very large catalog that constantly adds new items in large quantities.
If your catalog is static and you prefer a visual setup, you can configure listings using the IAP Catalog window in the Unity Editor instead. Refer to Create a catalog in the Editor for instructions on that approach.
Note
For a Direct to Consumer (D2C) payment provider, you need to create a remote catalog.
To define catalog listings programmatically:
  1. During the initialization stage, create an instance of the
    CatalogProvider
    class.
  2. Use the
    AddProduct()
    method to add each listing, or
    AddProducts()
    to add multiple listings at once.
  3. For each listing, specify a unique cross-store
    Product ID
    and
    Product Type
    .
The following example shows how to add a consumable listing with the ID
100_gold_coins
to a
CatalogProvider
, and later call
FetchProducts()
to retrieve the defined listing.
using UnityEngine;using UnityEngine.Purchasing;public class MyIAPManager { public MyIAPManager () { var catalog = new CatalogProvider(); catalog.AddProduct("100_gold_coins", ProductType.Consumable); // Connect to the store catalog.FetchProducts(UnityIAPServices.DefaultProduct().FetchProductsWithNoRetries); }}
Note
Use the
CatalogProvider
class to configure store-specific IDs and other advanced configurations directly in code.

Additional resources