Purchases
Retrieve purchase information and determine purchase status for products bought by players.
Read time 1 minuteLast updated 5 months ago
Unity IAP fetches purchase information from the store so your application can recognize and fulfill 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... m_StoreController.OnPurchasePending += OnPurchasePending; m_StoreController.OnPurchasesFetched += OnPurchasesFetched; await m_StoreController.Connect(); // Fetch previous purchases (includes confirmed orders) m_StoreController.FetchPurchases();}// Handle new purchases and pending transactionsprivate void OnPurchasePending(PendingOrder order){ ProcessPurchase(order);}// Handle fetched purchases (includes previously confirmed orders)private void OnPurchasesFetched(Orders orders){ foreach (var confirmedOrder in orders.ConfirmedOrders) { if (confirmedOrder.CartOrdered.Items().FirstOrDefault()?.Product.definition.type != ProductType.Consumable) { // Mark non-consumable and subscription products as entitled on fetch, as they only need to be granted once MarkAsEntitled(confirmedOrder.CartOrdered.Items().FirstOrDefault().Product); } }}// Your ProcessPurchase logicprivate void ProcessPurchase(PendingOrder order){ foreach (var product in order.CartOrdered.Items()) { // Grant product GrantProduct(product); } // Confirm the order to finalize the transaction m_StoreController.ConfirmPurchase(order);}
Reflect purchase state in your UI
Keep your buy buttons in sync with the purchase and entitlement state that Unity IAP reports, rather than treating them as always available. Syncing button states prevents duplicate purchase attempts, avoids offering a product the player already owns, and gives clear feedback while a purchase is processing. The correct mapping depends on the product type.Non-consumables and subscriptions
Non-consumable and subscription products are entitled once and shouldn't be offered for purchase while the user owns them. AfterFetchPurchasesCheckEntitlementFullyEntitled- Non-consumables: Show an Owned state. Non-consumables are purchased once and owned forever, so no further action is needed unless the purchase is later refunded.
- Subscriptions: Show a Manage or Renew action. Unlike non-consumables, subscriptions can expire or be canceled, so provide a mechanism for the player to manage, renew, or cancel them.
Consumables
Consumables are normally available for purchase. Don't deactivate the buy button based on entitlement.NotEntitledPendingOrderOnPurchasePendingEntitledUntilConsumedCheckEntitlement- Grant the reward.
- Call .
ConfirmPurchase - Re-enable the buy button.
Update the button state during purchase flow
Deactivate the buy button when the purchase starts, whether you callPurchaseProductShowPurchaseOptionCallback | Description |
|---|---|
| The purchase is paid and awaiting fulfillment. This order can be a new purchase or an unconfirmed order redelivered at launch. After you fulfill and confirm the order, set the resolved state: owned for a non-consumable product or subscription, or buyable for a consumable product. For more information, refer to Process purchases. |
| The order has been fulfilled and acknowledged. Use this callback to set the final owned state for non-consumable products and subscriptions if you don't do so in |
| The purchase failed or the player canceled it. Return the button to its buyable state. |
| The purchase is deferred and waiting to complete, such as for Ask to Buy approval. Show a waiting state instead of re-enabling the button. |
| Purchases retrieved on launch or restore. Set the owned state for any non-consumable products and subscriptions the player already owns. |
| The fetch couldn't complete, including when the device is offline and the status is |
StoreControllerPurchase 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, callConfirmPurchasePendingOrderAcknowledge purchases persisted to the cloud
If you are saving consumable purchases to the cloud, you must callConfirmPurchasePending