Purchasing Products Outside of a Paywall
Buy products outside a paywall with Superwall's purchase method on iOS, using StoreKit 1, StoreKit 2 or StoreProduct, then read the PurchaseResult.
If you're using Superwall for revenue tracking, but want a hand with making purchases in your implementation, you can use our purchase methods:
// For StoreKit 1
private func purchase(_ product: SKProduct) async throws -> PurchaseResult {
return await Superwall.shared.purchase(product)
}
// For StoreKit 2
private func purchase(_ product: StoreKit.Product) async throws -> PurchaseResult {
return await Superwall.shared.purchase(product)
}
// Superwall's `StoreProduct`
private func purchase(_ product: StoreProduct) async throws -> PurchaseResult {
return await Superwall.shared.purchase(product)
}For iOS, the purchase() method supports StoreKit 1, 2 and Superwall's abstraction over a product, StoreProduct. You can fetch the products you've added to Superwall via the products(for:) method. Similarly, in Android, you can fetch a product using a product identifier — and the first base plan will be selected:
private func fetchProducts(for identifiers: Set<String>) async -> Set<StoreProduct> {
return await Superwall.shared.products(for: identifiers)
}If you already have your own product fetching code, simply pass the product representation to these methods. For example, in StoreKit 1 — an SKProduct instance, in StoreKit 2, Product, etc. Each purchase() implementation returns a PurchaseResult, which informs you of the transaction's resolution:
.cancelled: The purchase was cancelled..purchased: The product was purchased..pending: The purchase is pending/deferred and requires action from the developer..failed(Error): The purchase failed for a reason other than the user cancelling or the payment pending.
How is this guide?
Observer Mode
Report StoreKit purchases made outside Superwall on iOS with observer mode, so the transactions show up in your dashboard. Covers StoreKit 1 and 2.
Game Controller Support
Let players navigate Superwall paywalls with a game controller on iOS. Turn on isGameControllerEnabled, then forward input with gamepadValueChanged.