Superwall

PurchaseController

A protocol for handling Superwall's subscription-related logic with your own purchase implementation.

This protocol is not required. By default, Superwall handles all subscription-related logic automatically.

When implementing PurchaseController, you must manually update subscriptionStatus whenever the user's entitlements change.

Purpose

Use this protocol only if you want complete control over purchase handling, such as when using RevenueCat or other third-party purchase frameworks.

Signature

public protocol PurchaseController: AnyObject {
  @MainActor
  func purchase(product: StoreProduct) async -> PurchaseResult
  
  @MainActor
  func restorePurchases() async -> RestorationResult
}

Parameters

MethodParametersReturn TypeDescription
purchaseproduct: StoreProductPurchaseResultCalled when user initiates purchasing. Implement your purchase logic here.
restorePurchasesNoneRestorationResultCalled when user initiates restore. Implement your restore logic here.

Returns / State

  • purchase() returns a PurchaseResult (.purchased, .failed(Error), or .cancelled)
  • restorePurchases() returns a RestorationResult (.restored or .failed(Error?))

When using a PurchaseController, you must also manage subscriptionStatus yourself.

Usage

For implementation examples and detailed guidance, see Using RevenueCat.

This is commonly used with RevenueCat, StoreKit 2, or other third-party purchase frameworks where you want to maintain your existing purchase logic.

How is this guide?

On this page