Fetch your Remote Catalog
Fetch your Remote Catalog for a payment provider store.
Read time 2 minutesLast updated 11 hours ago
You need to create a script that connects to the
StoreControllerRemoteCatalogProviderFetchRemoteCatalogPaymentProvider.NameRemoteCatalogProviderFetchProductsFetchProductsIProductServiceStoreControllerReference information
The following elements are relevant when you fetch the Remote Catalog for payment providers:Parameter | Description |
|---|---|
| This is the class used to obtain the Remote Catalog to use along with IAP. The Remote Catalog is obtained from the IAP backend. |
| This is the starting point to communicate with IAP. You need to get the following services:
|
| This is a wrapper over |
| This is an identifier used to register a Direct to Consumer (D2C) payment provider with |
Fetch Remote Catalog example script
Refer to the following example script:using System.Collections.Generic;using System.Threading.Tasks;using UnityEngine;using UnityEngine.Purchasing;public class PurchaseManager : MonoBehaviour{ StoreController m_StoreController; // Called by the ServiceOrchestrator after Auth is complete public async Task InitializeIAP() { m_StoreController = UnityIAPServices.StoreController(PaymentProvider.Name); m_StoreController.OnPurchasePending += OnPurchasePending; await m_StoreController.Connect(); m_StoreController.OnProductsFetched += OnProductsFetched; // 1. Initialize the RemoteCatalogProvider RemoteCatalogProvider catalogProvider = new RemoteCatalogProvider(); // 2. Fetch the catalog explicitly for the Payment Provider var fetchRemoteCatalogResult = await catalogProvider.FetchRemoteCatalog(new List<string> { PaymentProvider.Name }); if (!fetchRemoteCatalogResult.Success) throw fetchRemoteCatalogResult.Exception!; // 3. Pass the remote definitions to the StoreController var productDefinitions = catalogProvider.GetProducts(); m_StoreController.FetchProducts(productDefinitions); } private void OnPurchasePending(PendingOrder order) { // Handle purchase validation and rewarding before confirming the order Debug.Log($"Order pending: {order.Info}"); } void OnProductsFetched(List<Product> products) { // Handle fetched products (e.g., populate UI) Debug.Log("Fetched products:"); foreach (var product in products) { foreach (var catalogListing in product.catalogListings.Values) { Debug.Log($"ID: {catalogListing.definition.id} - Price: {catalogListing.metadata.localizedPriceString}"); } } }}