How to easily test In-App Purchases 🛍️


This content has been written in commercial collaboration with RevenueCat.

However the approach I describe will work with any iOS app, regardless of whether or not it uses RevenueCat đź‘Ť


If you’ve ever worked on an iOS app that relied on In-App Purchases (which I’ll abbreviate as IAPs), you’ve probably experienced how challenging it is to thoroughly test that your IAPs are working correctly.

That’s because IAPs sit at a particularly tough intersection:

  • on the one hand, the user flows around IAPs can get complex really fast: restoring purchases, upgrading or downgrading from one plan to another, subscription price increase notifications, etc.

  • on the other hand, IAPs are often the main source of revenue for the apps that use them, and so broken IAPs in production can have really bad consequences for the company behind the app

However, it seems that Apple did notice that this was becoming an issue, because a few years ago they introduced a new feature in Xcode that makes testing IAPs much easier than before: StoreKit Configuration Files.

Why do we need StoreKit Configuration Files?

Let’s consider this simple iOS app which only displays this View:

As you can see, this View attempts to load three products from StoreKit using their productIds.

And when a Product loads successfully, the View will then display a Button that allows the user to purchase that Product.

However, if you run this code in your Simulator, you will notice that none of the products seem to load successfully:

This is actually perfectly normal: for now we haven’t configured any purchasable Product inside App Store Connect.

But we’re going to see that, thanks to StoreKit Configuration Files, it’s actually possible to locally test this purchasing flow, without the need to make any change on App Store Connect!

How to setup a StoreKit Configuration File

To create a StoreKit Configuration File inside Xcode, simply click on File > New > File… in the menu.

From that, make sure to select the option StoreKit Configuration File:

Then you’ll simply need to give a name to your StoreKit Configuration Fie:

If your app already has IAPs set up in App Store Connect, it’s strongly recommended to check the box Sync this file with an app in App Store Connect.

This way the StoreKit Configuration File will be automatically generated and kept synchronized with accurate data coming from App Store Connect đź‘Ś

However, for the purpose of this email we’re going to create the content of the StoreKit Configuration File manually, because it makes it easier to understand how it works.

So let’s open this new StoreKit Configuration File!

The file is currently empty, so let’s follow the instruction and Click the "+" button to add an in-app purchase or subscription:

We’re going to select Add Non-Consumable In-App Purchase, as it’s the easiest one to setup.

We’re then asked to set a Reference Name and a Product ID:

Here, make sure that you use the same Product ID than the one you’ve set inside your code!

We’re almost done, the last thing we need to do is to define some localized Display Name and Description:

(Don’t skip setting the localized Display Name and Description, otherwise your IAP won’t be displayed!)

If you want, you can also modify the price that will be displayed when making the purchase:

Now we’re almost ready to use our new StoreKit Configuration File!

There’s only one step left: we need to let Xcode know that it should use that file when running the app.

As it’s already the case with many other many runtime options, this is configured through the project’s scheme.

So click on the current scheme and select Edit Scheme…:

And then simply select the StoreKit Configuration File you’ve just created:

And now if you run your app again in the Simulator, you’ll see that the Product we have defined inside the StoreKit Configuration File now successfully loads.

Even better: you will also be able to purchase it!

What else can a StoreKit Configuration Files do?

Being able to locally mock the purchase of an StoreKit Product is already pretty useful, but a StoreKit Configuration File is actually capable of much more than this!

You can also leverage that file to simulate and test some really tricky edge cases such as:

  • a refund being issued by App Store Connect

  • the user being notified of the price increase of a subscription

  • enabling or disabling Family Sharing

If you want to learn more about using StoreKit Configurations Files, you can read the official documentation from Apple or you can watch this video I had released last year:

Also, if you want to experiment with StoreKit Configuration Files, the code of the iOS app I used in this email is available on GitHub đź‘Ś


If you happen to be using the RevenueCat SDK for your in-app purchases, then I highly recommend that you test them using a StoreKit Configuration File.

As we’ve just seen, it will allow you to easily confirm you have everything configured correctly in App Store Connect.

But additionally, you will also see your test purchases show up in the RevenueCat dashboard as sandbox data!

And if you’re using RevenueCat Paywalls, a StoreKit Configuration File will also allow you to quickly confirm that your whole paywall is set up correctly 👌

(if you makes changes to your paywall from the RevenueCat back-end, it will also make the new version of the paywall easier to test!)


That’s all for this email, thanks for reading it!

If you’ve enjoyed it, feel free to forward it
to your friends and colleagues 🙌

I wish you an amazing week!

❤️

Previous
Previous

Be careful when using .onTapGesture()

Next
Next

How to mock any network call with URLProtocol