How to code and test refund requests in Swift and Xcode

Oscar de la Hera Gomez
Three flowers that represent StoreKit, Swift and XCode side by side. Beneath them sits the text “Code & Test StoreKit Refund Requests.”

A step by step guide on implementing and testing StoreKit refund requests 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.

The following walkthrough assumes that you have already setup StoreKit with an offering, have developed a UI that allows an app to display, buy and refund products and have already made at least one successful purchase.

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

Step One: Add the Request Refund Utility

A screenshot of Xcode showing the code provided in the snippet below.

Add a new file called performStoreKitRefundRequest.swift and paste in the code below.

We recommend placing it in the StoreKit folder under utilities, to make sure your code remains structured.

Please note that we have created this as a UIView extension so that you can call it from a UIView.

Step Two: Implement the code

A screenshot of the snippet of code provided below.

Where ever you have setup your refund UI, call the refund request using the async/await code below.

Please note that if you're calling it from a UIView controller, you should use self.view.performStoreKitRefundRequest(product:product) instead of self.performStoreKitRefundRequest(product:product).

Step Three: Verify

A screenshot of the Refund UI in an iOS app when you begin a refund request.

Run the app, perform a refund request and check that it shows up in the StoreKit Transaction Manager.

A screenshot of the Xcode StoreKit transaction manager showing a refund.

Looking to simulate a StoreKit refund that occurred outside of an app ?

Consult the guide below to learn how to simulate StoreKit refunds outside of an iOS app in Xcode.

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.

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.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details