Purchases
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 Order
object. The Order
contains all relevant details about the purchase and provides information needed to track and manage it with the store.
Retrieve 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 call FetchPurchases
or CheckEntitlement
.
Determine purchase status
You can determine the status of a purchase in two ways:
- Use
Order
to determine if theOrder
is aPendingOrder
,ConfirmedOrder
,DeferredOrder
orFailedOrder
. - Use
CheckEntitlement
to receiveEntitlementStatus
, which returnsEntitledButNotFinished
,EntitledUntilConsumed
,FullyEntitled
,NotEntitled
orUnknown
.
Purchase attributes
Attribute | Description |
---|---|
transactionId | A unique identifier for the purchase. |
product | The purchased product. |
quantity | The quantity of the product purchased. |
receipt | Receipt data for validating the purchase with the store. |
Purchase states
State | Description |
---|---|
Pending | The purchase has been paid but not yet fulfilled. |
Completed | The purchase has been fulfilled and acknowledged. |
Failed | The purchase failed due to an error. |
Deferred | The purchase is waiting for payment. |
Process purchases
The OnPurchasePending
callback is invoked when a purchase is made and is awaiting fulfillment. Your application should fulfill the purchase at this point, for example by unlocking local content or sending the purchase receipt to a server to update a server-side game model.
Note that OnPurchasePending
may be called at any point following a successful initialization. If your application crashes during execution of the OnPurchasePending
handler, then it is invoked again the next time Unity IAP initializes. Consider implementing your own de-duplication logic.
Note: If you don't confirm purchases, the store sends back the purchases, and some stores may even refund it automatically to protect the users.
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, call ConfirmPurchase
with the relevant PendingOrder
to acknowledge the purchase to the store.
Note: For consumables, once you acknowledge the purchase, the store does not return it again. Always persist consumable rewards remotely. If you store consumable rewards locally, you risk losing data with no way to restore it.
Save purchases to the cloud
If you are saving consumable purchases to the cloud, you must call ConfirmPurchase
only once you have successfully persisted the purchase.
When returning Pending
, Unity IAP keeps transactions open on the underlying store until confirmed as processed, ensuring consumable purchases are not lost even if a user reinstalls your application while a consumable is in this state.