Testing an interrupted purchase
Verify that your app handles an interrupted purchase by inspecting and invoking payment transactions.
Overview
An interrupted purchase is a transaction that requires the user to perform some action outside of your app before completing their transaction. For example, the user may need to update their payment method or accept new terms and conditions before continuing with their transaction.
In sandbox testing, you can simulate an interrupted purchase by turning on the interrupted purchase feature in App Store Connect for a tester Sandbox Apple Account. This interrupts all purchase attempts by that Sandbox Apple Account until you agree to the updated terms and conditions on the iOS device, or until you turn off the feature in App Store Connect. To learn how to set up interrupted purchase testing, see Enable interrupted purchases for a Sandbox Apple Account.
Set up testing
To enable interrupted purchases for the Sandbox Apple Account, log in to App Store Connect, and do the following:
From Users and Access, open the Users and Access Panel in the sidebar, under the Sandbox header, select Testers. On the right, you can view your Sandbox Apple Accounts.
Select a Sandbox Apple Account to use for testing interrupted purchases. If it’s already enabled, you’ll see a checkmark under the Interrupted Purchases column.
In the dialog that appears, select Interrupt Purchases for This Tester.
Begin testing
After setting up interrupted purchase testing in App Store Connect, use the following steps to test your app:
On the test device, sign in with the Sandbox Apple Account that has interrupted purchases enabled.
In your app, select Buy or Subscribe to make an in-app purchase.
Observe that the system displays a payment sheet.
In Xcode, verify that the payment queue receives a new transaction in the state SKPaymentTransactionState.purchasing.
On the device, authenticate the payment sheet.
In Xcode, observe that the payment fails. The payment queue receives an updated transaction in the state SKPaymentTransactionState.failed.
Check that your code calls finishTransaction(_:) to remove it from the queue.
On the device, observe that the system displays Terms & Conditions, interrupting the purchase (because you configured the sandbox environment to do so).
On the device, tap to agree to the Terms & Conditions.
In Xcode, verify that the payment queue receives a new transaction in the SKPaymentTransactionState.purchased state for the same productIdentifier and in the same quantity as the failed transaction.
In Xcode, validate the receipt. Check that your app provides the service or the product, and calls finishTransaction(_:).
On the device, the user should observe a successful purchase.
Conclude testing
The Sandbox Apple Account continues to experience interrupted purchases until you disable it in App Store Connect, or until the user agrees to the terms and conditions on the device. To disable interrupted purchases in App Store Connect, deselect Interrupt Purchases for This Tester. For more information, see Enable interrupted purchases for a Sandbox Apple Account.