How to Test iOS In-App Purchases with Sandbox

Test in-app purchases

Testing in-app purchases in the sandbox environment is a crucial step in ensuring that your app is functioning properly before submitting it to the App Store. The sandbox environment simulates the App Store environment, allowing you to test the entire process of purchasing an item in your app without actually charging your users.

Prerequisites to test iOS in-app purchases

The sandbox environment provided by Apple enables the testing of in-app purchases without any actual charges using test accounts. This environment leverages the App Store infrastructure but does not process actual payments. Rather, it returns transactions as if the payments were successfully processed.

There are a few things you should consider when you start testing your in-app purchases. 

  • To test in the developer sandbox, the app needs to be built as a developer build in Xcode.
  • In-app purchases can be tested without prior approval from App Review.
  • Device provisioning is limited to 100 per device type and a total of 500 devices to prevent widespread distribution outside the App Store.
  • Subscriptions renew at an accelerated rate in the sandbox environment.
  • No receipt is available in the sandbox environment until a purchase is made.

Add a testing account to App Store Connect 

To start, add a testing account to App Store Connect

  1. Go to Users and Access and click on Sandbox Testers.
  2. Click the add button (+).
  3. Enter the necessary tester information and click on Create.
  4. You can use the “+” symbol for the email to prevent you from creating a new email for every user.
  5. Please note that once the Sandbox Apple ID is created, the tester’s name, email, and password cannot be edited.
test in-app purchases
Test in-app purchases

Sandbox durations for testing subscriptions

After adding testers in Sandbox, you can choose a subscription renewal speed for each tester, allowing you to determine how quickly subscriptions renew. By default, the accounts are set to a speed equalization of 1 month = 5 minutes. However, you can adjust the renewal period speed based on the options below. 

Subscriptions will automatically renew up to 12 times per account, but the actual number of renewals is random — in our practice, it’s up to 6. 

App Store DurationSandbox Duration
3 days 2 minutes
1 week 3 minutes
1 month 5 minutes
2 months10 minutes
3 months15 inutes
6 months30 minutes
1 yesr1 hour

In App Store Connect, you can select a subscription renewal rate for each Sandbox Apple ID account. 

Test iOS subscriptions with Sandbox

To test whether you iOS subscriptions work properly, use testing device:

  1. Go to Settings > App Store > Log into Sandbox tester account. 
  2. Initiate a purchase in your app.
  3. You might be asked to fill in your account details again. You might not expect this, but that’s normal. 
  4. Wait for the alert from Apple about the successful purchase. 

Test upgrades, downgrades, and crossgrades iOS subscriptions in Sandbox 

To test upgrades, downgrades, and crossgrades of iOS subscriptions in the sandbox environment, you can follow the steps below:

  1. Subscribe to the monthly subscription within your app.
  2. Open the Settings app on your device and go to “App Store” under your Sandbox account.
  3. Tap “Manage” and then select “Subscriptions.”
  4. Choose your existing subscription and select a different product from the list of options to change your subscription. If you want to downgrade your subscription, you’ll need to wait 5-10 minutes before proceeding to the next step.
  5. Launch your app again.
  6. Verify that the user is subscribed to the new product and that the changes to the subscription have taken effect.

Test subscription cancellation on iOS

Disable Auto-renew:

  1. On your iOS device, go to Settings > App Store.
  2. Under the Sandbox Account section, tap on your highlighted Sandbox Apple ID and select “Manage.”
  3. Choose the subscription product that you want to cancel from the Subscriptions page.
  4. Tap on the “Cancel Subscription” button.
  5. No active subscriptions could be found. 

Reenable subscription renewal:

On the same “Manage Subscriptions” page, tap on the canceled subscription and confirm the payment to reenable the subscription renewal.

Test Restore Purchase on iOS

To test the functionality of restoring a purchase during an active subscription in the iOS sandbox environment, it is important to note that unlike the production sandbox and production environments, there is no receipt file generated on the device until a purchase is made. Therefore, to fully test restoring a purchase in the Sandbox, a button, gesture, or another method needs to be added to the app to revert it to the unsubscribed state.

Testing the restoration of a purchase during an active subscription in the sandbox environment involves the following steps:

  1. Sign up for a monthly subscription.
  2. Reinstall the app and make sure that you don’t have any subscriptions there.
  3. Use a button or gesture that was added to revert the app to the unsubscribed state.
  4. Tap the “Restore Purchases” button.
  5. If this is done before the subscription cycle ends (within 35 minutes), the app should detect an active subscription and change to the subscribed state.

To test the restoration of purchases across devices in the sandbox environment, follow these steps:

  1. Subscribe to a monthly plan on device A.
  2. Install the app on device B before the subscription expires.
  3. Log into the same Sandbox account used on device A.
  4. Launch the app on device B.
  5. Tap the “Restore Purchases” button.

Test billing issues on iOS

After WWDC22, Apple added a capability to simulate billing failures. To learn more about how to test billing issues in detail, read this article or official documentation.

Conclusion 

Once you have tested the entire process, you can implement your in-app purchases in your production app. It is important to note that you will need to use different settings and test user accounts in your production app than you used in the sandbox environment.

In summary, testing in-app purchases in the sandbox environment is a crucial step in ensuring that your app is functioning properly before submitting it to the App Store.

Qonversion is an all-in-one solution that provides developers with a cross-platform infrastructure for managing subscriptions and users’ access between iOS and web platforms. With Qonversion, you can ensure that your subscription model works seamlessly across all devices, minimizing the possibility of billing issues. It also provides a comprehensive analytics dashboard with valuable insights into user behavior and subscription performance.