Testing In-App Purchases in iOS 14

At WWDC20, Apple unveiled a new tool that will "make building and testing In-App Purchases better than ever". We’ll talk about StoreKit testing.

According to the documentation, "StoreKit testing in Xcode is a local test environment where you test in-app purchases without needing to connect to App Store servers."

Previously, it was only possible to test purchases and subscriptions in the Sandbox Environment, and that comes with a few limitations:

  • It is impossible to make a purchase on a simulator (it is only possible to request a list of available purchases).
  • To test purchases, you first need to set up products on App Store Connect and then use the user's sandbox environment and a real device. In this case, purchases for the developer are free. (They also are free in builds distributed through TestFlight.)
  • Sandbox purchases are not visible in the Subscriptions section of the device settings, unlike purchases made in applications in production.

With the release of the new version of iOS, you can now test purchases locally. All the necessary tools are built into Xcode:

StoreKit Configuration Files let you configure products right in Xcode.

To start testing purchases, you first need to add one to your project: Adding a SroreKit project in Xcode All the metadata for test purchases will be stored here.

It’s possible to add three types of purchases.

  • Consumable In-App Purchase (can be purchased multiple times, for example, extra lives in a game.)
  • Non-Consumable In-App Purchase (can be purchased only once, for example, when unlocking the full version of the app.)
  • Auto-Renewable Subscription (The user gets charged a recurring fee for services or content.)

Then specify using this file instead of App Store. In the Target Run settings, select the previously created Configuration file: Selecting Configuration file in Xcode in Target Run settings

StoreKit Transaction Manager stores all the test transactions and allows you to modify them. You can access it in the Debug Area. Signing and Capabilities tab Xcode

Clicking on the button opens the manager, which shows all the completed transactions, each of which can be deleted or refunded. StoreKit transactions in Xcode

StoreKit Test Framework allows you to write tests for purchases.

It has an option to disable pop-up dialogs, thereby speeding up the testing process. For the SKTestSession object, you can set the disableDialogs property to be true. Then, purchase tests can be run just like regular tests. UI Tests in Xcode

The Sandbox Account section in the App Store Settings on iPhone now shows test subscriptions, just like with real purchases. App Store Settings in iPhone Additionally, you can now ignore Introductory Offers. To remind you, auto-renewable subscriptions have an option of an introductory trial period, during which the user can use premium features for free or get a discount on the subscription fee. More info on Introductory Offers is available here. Sandbox options in iPhone; edit subscriptions

In addition, you can use the same sandbox account for testing free trials and Introductory Offers. Read more about setting up Introductory Offers here.

In the sandbox, you can also test App Store server notifications.

Here’s an example lifecycle of a subscription:

App Store server notifications in sandbox

Two events — DIDRENEW and DIDCHANGERENEWALSTATUS — are coming soon. These events will be sent from the App Store to your server, notifying it of changes in the status of your in-app purchases. Read more about App Store Server Notifications here.

Another feature that will be available in the near future is testing Interrupted Purchases. To do that, you will need to go to App Store Connect to enable the Interrupt Purchases For This Tester property for the sandbox test account.

App Store Connect users & access App Store Connect users & access; manage a user

To sum it up, you can now: View and manage subscriptions on your device. Test upgrades, downgrades, cancellations, ignore introductory offers. Create sandbox tester accounts on App Store Connect if you have the Developer role. It will soon be possible to test the behavior of the application after an interrupted purchase.

You can learn more about setting up StoreKit testing in the documentation of Xcode.

Read similar articles

Blog = Implementing  Grid Layout in SwiftUI

Implementing Grid Layout in SwiftUI

In this article, we will look at what Grid Layout is, what features it has, and how our grid implementation differs from Apple’s.

Learn more 6 min read
Blog = Things we wish we knew about iOS Voice Over

Things we wish we knew about iOS Voice Over

We decided to compile this somewhat disjoint list of things we wished we knew before starting the task on integrating Voice Over (VO) features.

Learn more 7 min read
Blog = How to start working with swift-format

How to start working with swift-format

While many developers are content with older popular solutions for code formatting, we decided to cover a newer, still evolving tool called swift-format.

Learn more 4 min read

Comments powered by Talkyard.