Handling Payouts (DIsappearing from product.definition)

I have populated my products in the Product Catalog overlay in the Editor. At RunTime I load the product catalog and then use the ConfigurationBuilder to set up and initialise my store.

If I then query the value of product.definition.payout amongst the items in storeController.products.all, the payout value is always null - the data doesn’t carry across.

Yet it seems that on purchase when a purchaseEvent is created, the purchase event includes the payout data (I assume Unity IAP queries the catalog on purchase of a productId to append it).

My question is what is the reason for this inconsistency? It means that in my UI if I wanted to order my list by payout quantity (which I have a use case for) then instead of querying product.definition.payout.quantity from the storeController list, I have to get the IDs from the StoreController list and cross reference them against the Catalog (like Unity seems to do on purchase).

What is the logic? I have to jump through hoops due to inconsistency.

2 Likes

Thank you for the report.

After verification, I have confirmed the issue and we will be fixing this soon.

1 Like

Yeah, today it’s still null.

To fix it, I cache the ProductCatalogPayout object from HandleIAPCatalogLoaded.completed

Explanation:
The request.asset which is Json datas of the ProductCatalogItem can be deserialize to ProductCatalog to get your catalog datas that you have defined in the IAPCatalog, and yeah, ProductCatalogItem contains the Payout.

private Dictionary<string, ProductCatalogPayout> payoutByProduct = new();

private void HandleIAPCatalogLoaded(AsyncOperation Operation)
{
    var request = Operation as ResourceRequest;
    var catalog = JsonUtility.FromJson<ProductCatalog>((request.asset as TextAsset).text);

    //Builders

    foreach (var product in catalog.allProducts)
    {
          builder.AddProduct(product.id, product.type);
          payoutByProduct.Add(product.id, product.Payouts.FirstOrDefault());
    }
}

Then you may get the Payout by your function in your IAP class

public ProductCatalogPayout GetProductPayout(Product product)
{
    return payoutByProduct.TryGetValue(product.definition.id, out var payout) ? payout : null;
}