Custom Purchase Controller

Use a custom purchase controller with the Unity SDK beta.

By default, Superwall handles purchase and restore flows through the native iOS and Android SDKs. Most Unity integrations should start there.

Use IPurchaseController only when another system, such as your own store abstraction or a third party purchase SDK, must complete purchases and restores.

Implement IPurchaseController

using System;
using Superwall;

public sealed class GamePurchaseController : IPurchaseController
{
    public void PurchaseFromAppStore(string productId, Action<PurchaseResult> completion)
    {
        // Complete the App Store purchase with your purchase system.
        // Then call completion with the result.
        completion(PurchaseResult.Purchased());
    }

    public void PurchaseFromGooglePlay(
        string productId,
        string basePlanId,
        string offerId,
        Action<PurchaseResult> completion
    )
    {
        // Complete the Google Play purchase with your purchase system.
        // Use basePlanId and offerId if your catalog needs them.
        // Then call completion with the result.
        completion(PurchaseResult.Purchased());
    }

    public void RestorePurchases(Action<RestorationResult> completion)
    {
        // Restore purchases with your purchase system.
        completion(RestorationResult.Restored());
    }
}

Pass the controller when configuring Superwall:

Superwall.Configure(
    "MY_PUBLIC_API_KEY",
    purchaseController: new GamePurchaseController()
);

Keep Subscription Status in Sync

When your purchase system is the source of truth, update Superwall whenever access changes.

Superwall.Shared.SubscriptionStatus = SubscriptionStatus.CreateActive(entitlements);

Or clear access:

Superwall.Shared.SubscriptionStatus = SubscriptionStatus.CreateInactive();

See Tracking Subscription State for a complete example.

How is this guide?

On this page