In-App Purchase Testing Tips

This guide describes how to test in-app purchases in your iOS app

About iOS 14 Local Testing (will be available soon)

During WWDC 2020 Apple announced a new way to test in-app purchases using StoreKit configuration file.

At the moment, in-app purchases validation made using StoreKit configuration file is not yet supported. We will announce when this feature becomes available in Apphud.

How to Change Sandbox Apple ID

If you want to change sandbox Apple ID in order to test in-app purchases from scratch, like testing Trials or paid Introductory Offers, please follow these steps:

  • Create new sandbox account

  • Delete the app from iOS device

  • Delete your test user in Apphud (To find yourself go to Users > View Sandbox Users)

  • Change Apple ID in device

  • Run the app again and make purchases

Testing Eligibilities

Apphud checks whether the given user is eligible for purchasing introductory or promotional offer by searching for transactions in ANY of current user's subscriptions. This means that if your Apphud user has several app store receipts from previous sandbox Apple IDs, you may get unexpected result.

Apphud User may have several subscriptions with the same product from different Apple ID account, if you were changing sandbox Apple ID without deleting Apphud User. In this case Apphud will merge multiple subscriptions under the same user. That is why it is recommended to delete your Apphud User from Apphud Dashboard when testing the app from another Apple ID.

Testing Eligibility for Introductory Offer

To correctly use checkEligibilityForIntroductoryOffer method please do the following:

  1. Please make sure that your Apphud User doesn't contain multiple App Store receipts from previous test Apple IDs. If so, delete your user.

  2. Note that "Reset Eligibility" option (Settings > App Store > Sandbox Account > Manage > Your App) is not supported. Apple doesn't delete old trial transactions from the receipt, so there is no technical way to correctly determine introductory eligibility after you pressed "Reset Eligibility" button.

  3. Test on clean Apple ID account. Create a fresh sandbox Apple ID account.

  4. When running the app at the first time after deleting (i.e. fresh install), keep in mind that you would need to submit App Store Receipt to Apphud either by calling Apphud.migratePurchasesIfNeeded{} or by tapping restore purchases button in your App's UI. This is required only in Sandbox, because apps running from Xcode/TestFlight initially don't have App Store Receipts and Apphud doesn't automatically refresh missing App Store receipts to avoid Apple ID password prompt. At production, however, everything will work okay, because App Store receipts always exist in apps downloaded from the App Store.

  5. Now you can test your eligibility method: method will return true because you didn't yet use introductory offer. After you have used introductory offer, method will return false.

Testing Eligibility for Promotional Offer

To correctly use checkEligibilityForPromotionalOffer method please do the following:

  1. Please make sure that your Apphud User doesn't contain multiple App Store receipts from previous test Apple IDs. If so, delete your user.

  2. When running the app at the first time after deleting (i.e. fresh install), keep in mind that you would need to submit App Store Receipt to Apphud either by calling Apphud.migratePurchasesIfNeeded{} or by tapping restore purchases button in your App's UI. This is required only in Sandbox, because apps running from Xcode/TestFlight initially don't have App Store Receipts and Apphud doesn't automatically refresh missing App Store receipts to avoid Apple ID password prompt. At production, however, everything will work okay, because App Store receipts always exist in apps downloaded from the App Store.

  3. Now you can test your promo eligibility method: method will return true if Apphud User has any subscription and false if user doesn't have any subscriptions.

Testing Integrations

Please read here.

Do not forget to call Apphud.setFinishTransactions()

This section is suitable only if you purchase subscriptions using Apphud SDK, i.e. you call Apphud.purchase(product) method in your App. If you purchase subscriptions with your own code, skip this section.

Call Apphud.setFinishTransactions() before SDK initialization to tell Apphud to finish all transactions, even those that are stuck in the queue for some reason.

This is useful when you test purchases a lot / change sandbox Apple IDs / break execution during purchases, etc.

This method is also helpful in production, sometimes it reduces errors in purchasing a subscription.

Force a Fresh Install in Apphud

If you want to change User ID / Device ID in order to test a new sandbox account, there is no need to write this paragraph; please read How to Change Sandbox Apple ID instead.

Currently, User ID and Device ID values are being saved in keychain on your device. Even if you change User ID, you will still have the same user with changed User ID. You can initialize Apphud SDK with different Device ID to force a fresh install.

func startManually(apiKey: String, userID: String? = nil, deviceID: String? = nil)

This method should not be used in production unless you know what you are doing.

How to Create a New Sandbox Apple ID

You can read more about testing and setting up auto-renewable subscriptions in our blog.

To test in app purchases you need to create sandbox user. Go to App Store Connect and open "Users and Access", then – "Sandbox Testers":

You can read more about creating sandbox testers here.

You can sign in to Sandbox account separately from your App Store account since iOS 12. Sign in to sandbox here:

Purchasing

Purchasing process is the same as real in-app purchases. The only difference is accelerated time and impossibility to cancel subscription manually. Subscriptions in sandbox renew 6 times per day maximum.

Real duration

Duration in sandbox

1 week

3 minutes

1 month

5 minutes

2 months

10 minutes

3 months

15 minutes

6 months

30 minutes

1 year

1 hour

If after purchase in Apphud you can see a user with active subscription, it means that payment process work correctly.

Which Events Can Be Tested in Sandbox?

You can test following events in sandbox:

  • Trial Started

  • Trial Converted

  • Intro Started

  • Intro Converted

  • Intro Renewed

  • Intro Expired (if payment mode is "Pay as you go" and number of introductory periods is at least six)

  • Promo Started

  • Promo Converted

  • Promo Renewed

  • Promo Expired

  • Subscription Started

  • Subscription Renewed

  • Subscription Expired

  • Autorenew Disabled

  • Autorenew Enabled

You can read more about events here.