Custom Store Products

Sell products billed by your own system, such as Paddle, Polar or your own backend, on Superwall paywalls in an iOS app: with no purchase code, or with your own PurchaseController.

A custom store product is a product on a Superwall paywall that the App Store doesn't bill. Your own billing system, such as Paddle, Polar or your own payment backend, takes the payment. The paywall shows the product like any other, with its price, period and trial.

This page covers the iOS app. The server side, which is where most of the work is, is in Custom Stores.

How it works

  1. A user taps a custom store product on a paywall.
  2. Your billing system's checkout opens.
  3. The customer pays. Your billing system tells your server, and your server reports the purchase to Superwall.
  4. Superwall grants the product's entitlements, and the SDK unlocks access.

Completing the checkout never grants access by itself. Access always comes from step 3.

Before you start

  • Set up a custom store, its products and your server. Start with the quickstart.
  • Add the custom store product to a paywall, like any other product.

Choose how the checkout opens

Option 1: Checkout endpointOption 2: PurchaseController
Purchase code in your appNoneA PurchaseController
Who opens the checkoutSuperwallYour app
Who sets the subscription statusSuperwallYour app
iOS SDK4.19.0+4.15.0+

Use option 1 unless you need to present the checkout yourself.

Option 1: Checkout endpoint

Superwall asks your server's checkout endpoint for a checkout URL and opens it. Your app has no purchase code.

  1. 1

    Configure Superwall without a PurchaseController

    Superwall.configure(apiKey: "MY_API_KEY")

    Superwall then manages the subscription status. It includes the entitlements your server reports.

  2. 2

    Let the checkout return to your app

    After paying, the customer lands on a Superwall page that opens your app again through its URL scheme.

    1. Give your app a custom URL scheme.
    2. Enter it as the Apple custom URL scheme in the dashboard's app settings.
    3. Pass incoming links to Superwall.handleDeepLink(_:):
    .onOpenURL { url in
      Superwall.handleDeepLink(url)
    }
  3. 3

    Set the store's checkout endpoint

    In the dashboard, open the custom store and set its endpoint under Checkout. See Checkout endpoint.

When the user taps the product, the checkout opens in the browser. After they pay and return, the paywall closes as purchased once your server's event has arrived. If they leave the checkout, the paywall stays open.

A store with a checkout endpoint uses it even when your app has a PurchaseController, for example for RevenueCat. Your controller still sets the subscription status, so include Superwall.shared.entitlements.web in it, as in Set the subscription status.

Option 2: PurchaseController

The SDK calls your PurchaseController when the user taps a product. For a custom store product, your controller asks your server for a checkout, opens it, and reports the result.

What your server needs

One route that your app calls, protected by your app's own sign-in. It creates a checkout in your billing system and returns its URL:

  • Take the user from the session you verified, never from the request body. Anyone could otherwise attach a purchase to another user's account. Store it in the checkout's metadata as the app_user_id your events send.
  • Take custom_transaction_id from the request body and store it in the checkout's metadata too. Your events send it back to attribute the revenue to the paywall.
  • Send the customer back to a URL that opens your app, such as myapp://checkout?status=completed, or myapp://checkout?status=closed when they leave.

The controller

import AuthenticationServices
import SuperwallKit
import UIKit

final class CheckoutPurchaseController: NSObject, PurchaseController {
  private let server = URL(string: "https://billing.example.com")!
  // The session must stay alive while the checkout is open.
  private var session: ASWebAuthenticationSession?

  func purchase(product: StoreProduct) async -> PurchaseResult {
    // App Store products: let Superwall buy them with StoreKit.
    if product.sk1Product != nil || product.sk2Product != nil {
      return await Superwall.shared.purchase(product)
    }

    do {
      let checkout = try await createCheckout(for: product)
      let returned = try await open(checkout)
      guard returned.queryItem("status") == "completed" else { return .cancelled }
      await refreshSubscriptionStatus()
      return .purchased
    } catch let error as ASWebAuthenticationSessionError where error.code == .canceledLogin {
      return .cancelled
    } catch {
      return .failed(error)
    }
  }

  func restorePurchases() async -> RestorationResult {
    await refreshSubscriptionStatus()
    return .restored
  }

  /// Asks your server for a checkout for the signed-in user.
  private func createCheckout(for product: StoreProduct) async throws -> URL {
    struct Body: Encodable {
      let product_id: String
      let custom_transaction_id: String?
    }
    struct Checkout: Decodable { let url: URL }

    var request = URLRequest(url: server.appendingPathComponent("app/checkout"))
    request.httpMethod = "POST"
    request.setValue("Bearer \(Session.current.token)", forHTTPHeaderField: "Authorization")
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.httpBody = try JSONEncoder().encode(
      Body(
        product_id: product.productIdentifier,
        custom_transaction_id: product.customTransactionId
      )
    )
    let (data, response) = try await URLSession.shared.data(for: request)
    guard (response as? HTTPURLResponse)?.statusCode == 200 else {
      throw URLError(.badServerResponse)
    }
    return try JSONDecoder().decode(Checkout.self, from: data).url
  }

  /// Opens the checkout and waits until it returns to the app's URL scheme.
  @MainActor
  private func open(_ url: URL) async throws -> URL {
    try await withCheckedThrowingContinuation { continuation in
      let session = ASWebAuthenticationSession(url: url, callbackURLScheme: "myapp") {
        [weak self] url, error in
        self?.session = nil
        if let url {
          continuation.resume(returning: url)
        } else {
          continuation.resume(throwing: error ?? URLError(.cancelled))
        }
      }
      session.presentationContextProvider = self
      self.session = session
      session.start()
    }
  }
}

extension CheckoutPurchaseController: ASWebAuthenticationPresentationContextProviding {
  func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
    UIApplication.shared.connectedScenes
      .compactMap { ($0 as? UIWindowScene)?.keyWindow }
      .first ?? ASPresentationAnchor()
  }
}

private extension URL {
  func queryItem(_ name: String) -> String? {
    URLComponents(url: self, resolvingAgainstBaseURL: false)?
      .queryItems?.first { $0.name == name }?.value
  }
}

Session.current.token stands for your app's own credential. "myapp" is your app's URL scheme. customTransactionId needs SDK 4.19.0; on earlier versions, leave it out, and revenue isn't attributed to a paywall.

Pass the controller when you configure Superwall:

Superwall.configure(
  apiKey: "MY_API_KEY",
  purchaseController: CheckoutPurchaseController()
)

Set the subscription status

With a PurchaseController, your app sets Superwall.shared.subscriptionStatus. The entitlements your server reported are in Superwall.shared.entitlements.web, so you don't need a second source of truth:

extension CheckoutPurchaseController {
  @MainActor
  func refreshSubscriptionStatus() async {
    // Fetch what your server has reported to Superwall.
    await Superwall.shared.refreshCustomerInfo()
    var entitlements = Superwall.shared.entitlements.web

    // If you also sell App Store products, add their entitlements.
    var storeKitProductIds: Set<String> = []
    for await result in Transaction.currentEntitlements {
      if case .verified(let transaction) = result {
        storeKitProductIds.insert(transaction.productID)
      }
    }
    entitlements.formUnion(Superwall.shared.entitlements.byProductIds(storeKitProductIds))

    Superwall.shared.subscriptionStatus = entitlements.isEmpty ? .inactive : .active(entitlements)
  }
}

This needs import StoreKit and SDK 4.19.0 for refreshCustomerInfo(). Call it on launch, when the app comes to the foreground, and after every purchase and restore.

The customer can be back in your app a few seconds before your billing system's webhook reaches your server. If the entitlement isn't there yet after a completed checkout, wait a moment and call refreshSubscriptionStatus() again before you treat the purchase as inactive.

Keeping access up to date

Your server's events change access after the purchase too: a renewal extends it, and an expiration or refund ends it. The SDK picks these up when it refreshes entitlements:

  • After a custom store purchase (SDK 4.19.0+).
  • When the app comes to the foreground, unless it refreshed recently (SDK 4.19.0+).
  • When you call refreshCustomerInfo(), which always asks Superwall.

With option 1, nothing else is needed. With option 2, call your refreshSubscriptionStatus() at those times.

Trials

A custom store product can use the same trial variables as an App Store product. Superwall decides trial eligibility from the product's entitlements and the user's entitlement history, so a user who has held the entitlement before isn't offered a trial again.

  • Attach at least one entitlement to each custom store subscription product.
  • Report a free trial as an initial_purchase with period_type: "trial" and a price of "0".

Common mistakes

  • The checkout completes but the user stays locked out. Your server didn't report the purchase, or the event names a different app_user_id than the app identified. Check your server's logs for a rejected event.
  • The paywall doesn't close after paying (option 1). The purchase event didn't carry the checkout's custom_transaction_id. See After the customer pays.
  • Calling Superwall.shared.purchase(product) for a custom store product. That method buys App Store products. In a PurchaseController, check sk1Product and sk2Product first, as the example does.
  • Fetching a custom store product with Superwall.shared.products(for:). That method fetches App Store products.

Test it

  1. Send your server's events with environment: "sandbox" while you test.
  2. Open a paywall with the custom store product. Confirm its price and trial text.
  3. Buy it with your billing system's test card. Confirm the paywall closes and the feature unlocks.
  4. Leave a checkout without paying. Confirm the paywall stays open.
  5. Refund the purchase in your billing system, then call refreshCustomerInfo() or reopen the app later. Confirm access ends.
  6. In the dashboard, filter revenue charts to Sandbox and confirm the purchase is attributed to your paywall.

How is this guide?

On this page