In-App Purchases #

In-app purchases enable you to monetize your games and generate revenue. By offering in-game items or content for purchase, you can create a revenue stream beyond the initial purchase price of the game. This is particularly important for free-to-play games, which rely on in-app purchases to generate revenue.

They can also be used to improve the player experience, providing additional options and flexibility within the game. For example, players may be able to purchase additional lives, power-ups, or access to new levels or content.

You can use the IAPSystem to manage in-app purchases.

Initialize the IAP system #

The IAP system relies on the Economy System and an ILogger, both must be passed in as dependencies via the constructor.

1
2
var iapSystem = new IAPSystem(economySystem, Logger);
systems.Add(iapSystem);

Adding products #

You can manually add products which are not defined in the Economy system. These product definitions could come from the Unity IAP definitions.

1
2
3
4
5
6
var productDefinitions = new List<ProductDefinition>
{
    new ProductDefinition("<productId>", ProductType.Consumable)
};

await iapSystem.AddProductsAsync(productDefinitions);

Purchasing a store item #

You can purchase a store item defined in the Economy system.

1
2
3
4
5
// Get a store item
var storeItem = economySystem.StoreItems.First();

var purchaseEventArgs = await iapSystem.BuyProductAsync(storeItem);
Debug.Log($"Receipt: {purchaseEventArgs.purchasedProduct.receipt}");

You can also purchase an item by product ID.

1
var purchaseEventArgs = await iapSystem.BuyProductByIdAsync("<productId>");

Processing a purchase #

You can process a purchase.

1
2
var processingResult = iapSystem.ProcessPurchase(purchaseEventArgs);
Debug.Log($"Processing result: {processingResult}");

Restoring purchases #

You can restore purchases.

1
await iapSystem.RestorePurchasesAsync();

Getting localized product price #

You can get the localized product price.

1
2
var price = iapSystem.GetLocalizedProductPrice(storeItem);
Debug.Log($"{storeItem.Name} price: {price}");

You can also get a localized product price by product ID.

1
var price = await iapSystem.GetLocalizedProductPriceById("<productId>");