Class IAPModule
Wraps Unity IAP v5 for product registration, purchase flow, receipt validation, and restore.
Uses the event-driven StoreController API. Supports an optional server-side validation
step via IIapPurchaseVerificator.
public static class IAPModule
- Inheritance
-
IAPModule
- Inherited Members
Fields
- OnRestorePurchases
Called for each product delivered during a restore flow. The second parameter is
trueif this product was the one pending before restore was triggered.
Properties
- Config
The config used to initialize this module.
- IsInitialized
Whether Unity IAP has been initialized and the store is ready.
Initialization
- Initialize(IAPModuleConfig, List<(string productId, ProductType productType)>)
Initializes Unity IAP v5 with the given product catalog and waits until the store is connected and products are fetched. Returns
falseif the product list is empty, the store fails to connect, or the initial product fetch fails.
Methods
- FetchAdditionalProducts(Action, Action<string>, ProductType, params string[])
Fetches additional products from the store that were not registered at initialization time.
onFailedreceives the failure reason string.
- GetISOCurrencyCode(string)
Returns the ISO 4217 currency code (e.g., "USD") for the given product ID.
- GetProductDescription(string)
Returns the localized product description for the given product ID.
- GetProductName(string)
Returns the localized product title for the given product ID.
- GetProductPrice(string)
Returns the localized price as a decimal for the given product ID.
- GetProductPriceString(string)
Returns the formatted price string (e.g., "$0.99") for the given product ID.
- PurchaseProduct(string, Action<Product>, Action<string>)
Initiates a purchase flow for the given product ID. Persists the pending product ID to PlayerPrefs so it can be recovered if the app crashes mid-transaction.
- PurchaseProduct(string, Action<Product>, Action<string>, Action)
Initiates a purchase with an additional
onStartValidatecallback that fires when server-side receipt validation begins.
- RestorePurchases()
Triggers an iOS purchase restore. Set OnRestorePurchases before calling to receive each restored product. No-op in the Editor.
- SetPurchaseVerificator(IIapPurchaseVerificator)
Sets the server-side purchase verificator. Call before any purchase is made. Ignored when UsePurchaseVerification is
false.
Events
- OnPurchaseStarted
Fired when a purchase flow begins. Wire to
AppLovinModule.AllowAppOpenAd(false)to suppress ads during checkout.
- OnPurchaseSucceeded
Fired after a purchase has been confirmed as successful. Parameters: the purchased
Productand the raw receipt string (order.Info.Receipt). Wire this to analytics logging calls such asAppsFlyerModule.LogPurchase.