How to code and test StoreKit pending purchases in Swift and XCode

A step by step guide on implementing and testing StoreKit product pending purchases for In-App Purchases and Subscriptions.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 03/25/2023 at 15:20
Last Updated on 03/27/2023 at 15:25
Three flowers that represent StoreKit, Swift and XCode side by side. Beneath them sits the text “Code & Test StoreKit Product Pending Purchases.”

A step by step guide on implementing and testing StoreKit product pending purchases for In-App Purchases and Subscriptions.

The guide was made using our Free iOS StoreKit 2 Open Source project which is recommended for developers or business folk wishing to learn about how In-App Purchases or Subscriptions work and the code behind them.

SubscribeFree Open-Source Apple StoreKit 2 Swift Project

The following walkthrough assumes that you have already setup StoreKit with an offering and developed a UI that allows an app to display products.

Please consult the guides below to learn how to setup StoreKit, create a StoreKit offering or design a UI that considers all StoreKit scenarios.

How to setup StoreKit in XcodeHow to create a StoreKit offering in XCode or App Store ConnectFree iOS e-commerce Figma design file

Step One: Setup StoreKit Purchases

A screenshot of an iOS app showing a completed purchase.

Follow our guide below to setup StoreKit purchases.

How to code and test StoreKit purchases in Swift and XCode

Step Two: Enable Ask to Buy

A screenshot of Xcode highlighting the location of the Editor tab in the Xcode menu and Enable Ask to Buy. If Ask to Buy is already enabled, this will say Disable Ask to Buy.

Follow our guide below to enable Ask to Buy in XCode.

How to enable or disable StoreKit Ask to Buy in XCode

Step Three: Make the purchase

A screenshot of an iOS app asking for permission after requesting a purchase of a non-consumable in-app purchase.

Run the app and attempt to make a purchase.

The app will prompt you to ask for permission.

You should also consider marking the transaction as pending using UI similar to the one below.

A screenshot of an iOS app showing a non-consumable in-app purchase in a pending state.

Step Four: Approve or Deny

A screenshot of the XCode StoreKit Transaction Manager. Highlighted is a pending transaction. We have used arrows to point out the tick and cross that appear after selected a pending transaction. The tick approves the transaction whilst the x denies it.

Follow our guide below to learn how to approve or deny a pending transaction.

How to approve or deny a pending StoreKit Transaction in XCode

If you deny a pending purchase, your app will not be notified via the StoreKit listener. This means that in order to update from the pending UI, your app must request the product purchase state again for it to know the transaction is not pending. We recommend requesting product statuses every time an app enters the foreground.

If you approved the purchase, your app will be notified via the StoreKit listener and you should use this to update the UI to show that it has been successfully purchased.

A screenshot of an iOS app showing a non-consumable in-app purchase in a purchased state.

Looking to learn more about developing apps with StoreKit 2?

Read our comprehensive development guide linked below to learn about all the secrets behind developing In-App Purchases and Subscriptions with StoreKit 2.

Read Apple StoreKit 2 Development Guide

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe