Purchases
Retrieve purchase information and determine purchase status for products bought by players.
Read time 3 minutesLast updated 10 hours ago
Unity IAP fetches purchase information from the store so your application can recognize and fulfil what players have bought. This ensures that your game can deliver content or entitlements to users based on their purchase history, even if they bought items outside your app or on another device. A purchase is represented as an
OrderOrderRetrieve purchases
Purchases made by the user can be retrieved from the store. However, consumable products must be tracked by your application after they are consumed, because stores don't return consumables that have already been fulfilled. For non-consumable products and subscriptions, the store accurately returns these purchases when you callFetchPurchasesCheckEntitlementDetermine purchase status
You can determine the status of a purchase in two ways:- Use to determine if the
Orderis aOrder,PendingOrder,ConfirmedOrderorDeferredOrder.FailedOrder - Use to receive
CheckEntitlement, which returnsEntitlementStatus,EntitledButNotFinished,EntitledUntilConsumed,FullyEntitledorNotEntitled.Unknown
Purchase attributes
Attribute | Description |
|---|---|
| A unique identifier for the purchase. |
| The purchased product. |
| The quantity of the product purchased. |
| Receipt data for validating the purchase with the store. |
Purchase states
State | Description |
|---|---|
| The purchase has been paid but not yet fulfilled. |
| The purchase has been fulfilled and acknowledged. |
| The purchase failed due to an error. |
| The purchase is waiting for payment. |
Process purchases
TheOnPurchasePendingOnPurchasePendingOnPurchasePending// Handle restore on initializationprivate async void Start(){ // Setup, e.g. add listeners to your StoreController... await m_StoreController.Connect(); // Fetch previous purchases (includes confirmed orders) m_StoreController.FetchPurchases();}// Handle new purchases and pending transactionsprivate void OnPurchasePending(Order order){ ProcessPurchase(order);}// Handle fetched purchases (includes previously confirmed orders)private void OnPurchasesFetched(Orders orders){ foreach (var confirmedOrder in orders.ConfirmedOrders) { ProcessPurchase(confirmedOrder); }}// Your ProcessPurchase logicprivate void ProcessPurchase(Order order){ var productId = order.Info.PurchasedProductInfo[0].productId; if (IsNonConsumable(productId)) { // Grant non-consumable product GrantProduct(productId); } // Handle other product types as needed}
Purchase acknowledgement and reliability
Unity IAP requires you to explicitly acknowledge purchases to ensure that purchases are reliably fulfilled, even during network outages or application crashes. If a purchase is paid for but not fulfilled, Unity IAP delivers the purchase to your application the next time it initializes. This process prevents purchases from being lost when the purchase flow is interrupted or when purchases are completed while the application is offline. After successfully fulfilling a purchase, callConfirmPurchasePendingOrderSave purchases to the cloud
If you are saving consumable purchases to the cloud, you must callConfirmPurchasePending