gradient blur
Engineering

Consumable Purchases with the Superwall SDK

Learn about how consumable purchases, like in-app currency and credits, work with the Superwall SDK for more flexible monetization beyond subscriptions.

glowingGraph

Jordan Morgan

Developer Advocate

Published

While Superwall is known for helping you grow your revenue with our extensive paywall testing suite, experiments and more — the Superwall SDK also supports consumable products, too. Things like coins for a game, credits for A.I. based apps and other similar products all work easily with Superwall.

The important thing to remember is that, by default, Superwall treats these purchases as an active "subscription" when they are purchased:

// This will be true when a consumable, or non-consumable, is purchased
if Superwall.shared.subscriptionStatus == .active {
    showSubscribedAccountView()
}

swift

ungroup Copy

And, if that's fine with you — then you're done here! There's nothing else you need to do. But, in some cases, you may not want this behavior. In those situations, there are two ways to think about it:

  1. If you always want a paywall to show no matter if they've bought a consumable, non-consumable or even have a subscription — then there are no code changes needed. Simply set your paywall's "Present Paywall" option (under Sidebar -> Settings) to "Always":

gradient blur
dashboard-header

Setting the presentation option for a paywall

  1. If you have more involved logic for determining if someone is subscribed, or you don’t want consumable or non-consumable purchases to mark them as subscribed, and you’d rather not update the paywall presentation settings individually — you can manually set the subscription status in Superwall.

This post covers the second case. In that scenario, we'll want to implement a purchase controller to:

  • Purchase products

  • Handle restores

  • And, most importantly, set the correct subscription status

Creating a purchase controller

A PurchaseController is created by adopting the PurchasController protocol and implementing two required functions for purchasing and restoring:

class PurchaseManager: PurchaseController {
    func purchase(product: SKProduct) async -> SuperwallKit.PurchaseResult {
        // Purchase a product
    }

    func restorePurchases() async -> SuperwallKit.RestorationResult {
        // Restore one
    }
}

swift

ungroup Copy

In these functions, you would use whatever avenue you rely on to purchase products. It could be StoreKit, your own server code or another third-party solution. Here's what it might look like:

class PurchasesManager: PurchaseController {
    func purchase(product: SKProduct) async -> SuperwallKit.PurchaseResult {
        let result = await SomeProductPurchaseUtil.purchase(product)

        switch result {
        case .success:
            return .purchased
        case .userCancelled:
            return .cancelled
        case .pendingPurchase:
            return .pending
        case .alreadyPurchased:
            return .restored
        case .failed(let error):
            return .failed(error)
        }
    }

    func restorePurchases() async -> SuperwallKit.RestorationResult {
        do {
            try await AppStore.sync()
            try await updateUserPurchases()
            return .restored
        } catch {
            return .failed(error)
        }
    }
}

swift

ungroup Copy

Handling subscription states

But, as I mentioned above, the critical component here is setting subscription states. In this case, you'll use the existing code you have (or would need to write) to listen for product purchases, subscription state changes from your own server, or whatever "source of truth" you use for a user's subscription state — and pass that over to Superwall:

class PurchasesManager: PurchaseController {
    let purchaseListener = PurchaseListener()

    init() {
        purchaseListener.subscriptionStatusChanged { status in
            switch status {
            case .onlyConsumables:
                Superwall.shared.subscriptionStatus = .inactive
            case .purchaseSubscription, purchasedBoth:
                Superwall.shared.subscriptionStatus = .active
            }
        }
    }

    func purchase(product: SKProduct) async -> SuperwallKit.PurchaseResult {
        let result = await ProductPurchase.purchase(product)

        switch result {
        case .success(let result):
            return .purchased
        case .userCancelled:
            return .cancelled
        case .pending:
            return .pending
        @unknown default:
            fatalError()
        }
    }

    func restorePurchases() async -> SuperwallKit.RestorationResult {
        do {
            try await AppStore.sync()
            try await updateUserPurchases()
            return .restored
        } catch {
            return .failed(error)
        }
    }
}

swift

ungroup Copy

The key is that, even if you don't use Superwall's subscriptionStatus in your code, you want it to always have the accurate state of someone's subscription status since it affects other parts of the Superwall SDK (such as presenting paywalls, for example).

Finally, you will need to pass this controller over to Superwall when you first initialize the Superwall SDK:

@main
struct MyApp: App {
    let purchaseUtil: PurchasesManager = .init()

    init() {
        Superwall.configure(apiKey: "YourAPIKey", 
                            purchaseController: purchaseUtil)
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

swift

ungroup Copy

Wrapping up

Superwall's SDK isn't just for handling subscription-based models; it also supports consumable and non-consumable products, giving you flexibility in how you grow your apps. By using a purchase controller, you can have full control over the entire purchasing pipeline and subscription state management.

If you're new to Superwall, there's no better time to get started. We can help you grow your revenue, no matter your monetization strategy. Get started for free by signing up today.

gradient blur

Get a demo

We'd love to show you Superwall

Want to learn more?

  1. Fill out this tiny form →
  2. We'll prepare you a custom demo
  3. Walk you through Superwall
  4. Follow up and answer questions

Key features

  • Drag 'n Drop Paywalls
  • 200+ Custom Templates
  • Unlimited A/B tests
  • Surveys, Charts & More
Select...

By proceeding you consent to receiving emails and our terms.

gradient blur
shape-starshape-starshape-starshape-starshape-star

Customer Stories

Our customers refer to Superwall as their most impactful monetization tool. In their own words:

dashboard-header

Thanks to Superwall, we were able to 2x our iOS app profitability in just six months. It has greatly assisted our growth team in achieving exceptional results by facilitating high-frequency experimentation.

Mojo launch
Bernard Bontemps, Head of Growth
dashboard-header

Really excited about the progress we made recently on paywalls with Superwall. We got more than 50% increase in conversion for upsell screens. This is crazy.

Photoroom launch
Matthieu Rouif, CEO
dashboard-header

Superwall has completely changed the game for us. We’re able to run experiments 10x faster and unlock the ideal monetization model for our users.

RapChat launch
Seth Miller, CEO
dashboard-header

Superwall made testing paywalls so much faster. Instead of releasing a new version of the app each time, we were able to iterate on the winning paywalls much quicker. Thanks to that it increased our revenue per customer by 40%.

Teleprompter launch
Mate Kovacs, Indie Dev
dashboard-header

Superwall lets us move 10x faster on our monetization strategy. We can build and launch multiple paywall iterations without the need for client releases or complicated deploys. Our product iteration loop is days, rather than months because of Superwall.

Citizen launch
Jon Rhome, Head of Product
dashboard-header

Superwall enables Bickster’s marketing team to design and optimize app paywalls, freeing up engineering to concentrate on innovation. As a result, Superwall helped accelerate our install-to-subscription rates, lower engineering expenses, and cured our team’s frustration with the (once) time-consuming process of iterating on paywalls.

Bickster launch
Chris Bick, CEO
dashboard-header

Superwall has revolutionized our monetization strategy. It’s an essential tool that allows rapid paywall testing and optimization, leading to remarkable improvements in our subscription conversions and revenue generation. Can’t recommend Superwall enough for any app-based business.

Coinstats launch
Vahe Baghdasaryan, Sr. Growth
dashboard-header

Superwall has played an integral part of improving our subscription business. Compared to other providers, Superwall has proven superior in facilitating high-frequency experimentation allowing us to achieve an ideal monetization model, resulting in a significant increase in revenue.

Hornet launch
Nils Breitmar, Head of Growth
dashboard-header

Superwall is the single greatest tool we’ve used to help us increase our revenue. Our material wins from Superwall are greater than any tool we’ve worked with to date!

Pixite launch
Jordan Gaphni, Head of Growth
dashboard-header

Shout out to Superwall for helping us dial in our paywall — made a big impact on monetization, increasing revenue by more than 50% 💸

Polycam launch
Chris Heinrich, CEO
dashboard-header

Superwall increases revenue. Full stop. Being able to test paywalls on the fly and quickly analyze results has drastically increased our revenue and improved our monetization of users. Highly recommend this tool!

Hashtag Expert launch
Zach Shakked, Founder
Start for FREE

Simple win-win pricing

Interest aligned pricing. Contact us for a discount.

dashboard-header
Indie
Free
Up to 250 conversions per month
Access to every standard feature
Try it free

Standard Features

  • 250 Conversions a Month
  • Drag 'n Drop Paywall Editor
  • 200+ Paywall Templates
  • Unlimited A/B tests
  • Charts & Analytics
dashboard-header
Startup
$0.20/conversion
Pay as you go pricing that scales
Up to 5,000 conversions a month
Sign Up

Standard Features

  • 5,000 Conversions a Month
  • Drag 'n Drop Paywall Editor
  • 200+ Paywall Templates
  • Unlimited A/B tests
  • Charts & Analytics
dashboard-header
Growth
Flat-Rate
100% custom flat-rate pricing
Terms that make sense for you
Get a quote

Premium Features

  • Unlimited Conversions
  • We Build Your Paywalls
  • 4 Weekly Growth Meetings
  • Dedicated Slack Channel
  • Custom Integrations