docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class PurchaseService

    The service responsible for ordering products, fetching previous purchases and validating product entitlements.

    Inheritance
    object
    PurchaseService
    Implements
    IPurchaseService
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.Purchasing
    Assembly: Unity.Purchasing.dll
    Syntax
    public class PurchaseService : IPurchaseService

    Properties

    Apple

    Gets the Apple-specific purchase service extensions and functionality. Provides access to Apple App Store specific features and operations.

    Declaration
    public IAppleStoreExtendedPurchaseService? Apple { get; }
    Property Value
    Type Description
    IAppleStoreExtendedPurchaseService

    Google

    Gets the Google-specific purchase service extensions and functionality. Provides access to Google Play Store specific features and operations.

    Declaration
    public IGooglePlayStoreExtendedPurchaseService? Google { get; }
    Property Value
    Type Description
    IGooglePlayStoreExtendedPurchaseService

    Methods

    CheckEntitlement(Product)

    Checks the entitlement status for the specified product. This verifies whether the user is entitled to access the product's content.

    Declaration
    public void CheckEntitlement(Product product)
    Parameters
    Type Name Description
    Product product

    The product to check entitlement for. Must be a valid product from the store.

    ConfirmPurchase(PendingOrder)

    Confirms a pending purchase order, completing the transaction.

    Declaration
    public void ConfirmPurchase(PendingOrder order)
    Parameters
    Type Name Description
    PendingOrder order

    The pending order to confirm. This should be a valid pending order received from a purchase event.

    FetchPurchases()

    Fetches all previous purchases made by the user from the store. This will trigger OnPurchasesFetched or OnPurchasesFetchFailed events based on the result.

    Declaration
    public void FetchPurchases()

    GetPurchases()

    Gets an observable collection of the purchases fetched, confirmed and ordered.

    Declaration
    public ReadOnlyObservableCollection<Order> GetPurchases()
    Returns
    Type Description
    ReadOnlyObservableCollection<Order>

    The read-only observable collection of all purchases made.

    ProcessPendingOrdersOnPurchasesFetched(bool)

    Configures whether pending orders should be automatically processed when purchases are fetched from the store.

    Declaration
    public void ProcessPendingOrdersOnPurchasesFetched(bool shouldProcess)
    Parameters
    Type Name Description
    bool shouldProcess

    True to automatically process pending orders after fetching purchases, false to skip processing.

    Purchase(ICart)

    Initiates a purchase for all products in the specified cart.

    Declaration
    public void Purchase(ICart cart)
    Parameters
    Type Name Description
    ICart cart

    The cart containing products to purchase. All products in the cart will be processed for purchase.

    PurchaseProduct(Product)

    Initiates a purchase for the specified product.

    Declaration
    public void PurchaseProduct(Product product)
    Parameters
    Type Name Description
    Product product

    The product to purchase. Must be a valid, purchasable product from the store.

    RestoreTransactions(Action<bool, string?>?)

    Restores previously purchased transactions from the store. This is typically used to restore purchases on a new device or after reinstalling the app.

    Declaration
    public void RestoreTransactions(Action<bool, string?>? callback)
    Parameters
    Type Name Description
    Action<bool, string> callback

    Optional callback invoked when the restore operation completes. The first parameter indicates success (true) or failure (false), and the second parameter provides an error message if the operation failed.

    RestoreTransactionsInternal(Action<bool, string?>?)

    Internal implementation for restoring transactions. Handles the core logic for transaction restoration without external validation.

    Declaration
    protected virtual void RestoreTransactionsInternal(Action<bool, string?>? callback)
    Parameters
    Type Name Description
    Action<bool, string> callback

    Optional callback invoked when the restore operation completes. The first parameter indicates success (true) or failure (false), and the second parameter provides an error message if the operation failed.

    Events

    OnCheckEntitlement

    Event triggered when checking product entitlement status. Subscribe to this event to handle entitlement verification results.

    Declaration
    public event Action<Entitlement>? OnCheckEntitlement
    Event Type
    Type Description
    Action<Entitlement>

    OnPurchaseConfirmed

    Event triggered when a purchase has been successfully confirmed and completed. Subscribe to this event to handle successful purchase completion, such as granting in-game content.

    Declaration
    public event Action<Order>? OnPurchaseConfirmed
    Event Type
    Type Description
    Action<Order>

    OnPurchaseDeferred

    Event triggered when a purchase has been deferred by the store. This typically occurs when parental approval is required for the purchase.

    Declaration
    public event Action<DeferredOrder>? OnPurchaseDeferred
    Event Type
    Type Description
    Action<DeferredOrder>

    OnPurchaseFailed

    Event triggered when a purchase has failed to complete. Subscribe to this event to handle purchase failures and provide appropriate user feedback.

    Declaration
    public event Action<FailedOrder>? OnPurchaseFailed
    Event Type
    Type Description
    Action<FailedOrder>

    OnPurchasePending

    Event triggered when a purchase is pending confirmation or processing. Subscribe to this event to handle purchases that require additional processing before completion.

    Declaration
    public event Action<PendingOrder>? OnPurchasePending
    Event Type
    Type Description
    Action<PendingOrder>

    OnPurchasesFetchFailed

    Event triggered when fetching previous purchases from the store has failed. Subscribe to this event to handle errors in retrieving purchase history.

    Declaration
    public event Action<PurchasesFetchFailureDescription>? OnPurchasesFetchFailed
    Event Type
    Type Description
    Action<PurchasesFetchFailureDescription>

    OnPurchasesFetched

    Event triggered when previously made purchases have been successfully fetched from the store. Subscribe to this event to process and restore previously purchased content.

    Declaration
    public event Action<Orders>? OnPurchasesFetched
    Event Type
    Type Description
    Action<Orders>

    Implements

    IPurchaseService
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)