# 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` [#implement-ipurchasecontroller]

```csharp C#
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:

```csharp C#
Superwall.Configure(
    "MY_PUBLIC_API_KEY",
    purchaseController: new GamePurchaseController()
);
```

Keep Subscription Status in Sync [#keep-subscription-status-in-sync]

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

```csharp C#
Superwall.Shared.SubscriptionStatus = SubscriptionStatus.CreateActive(entitlements);
```

Or clear access:

```csharp C#
Superwall.Shared.SubscriptionStatus = SubscriptionStatus.CreateInactive();
```

See [Tracking Subscription State](/docs/unity/quickstart/tracking-subscription-state) for a complete
example.