What you need
In order to correctly test receipt validation, you need to:
- Declare your application on the iTunes Connect portal. Go to Manage Your Applications and create a new application (or a new version if it is an update). Note that the bundle identifier and the bundle version are important, as they will be used to generate the testing receipt.
- Declare a test account on the iTunes Connect portal. Go to Manage Users and create an account. It will be used during the generation of the test receipt.
- Sign the application with a valid certificate. The receipt retrieval process is only triggered if the application bundle has been properly signed. Developer certificate can be created and downloaded from the Mac Dev Center for OS X or iOS Dev Center for iOS.
In order to correctly test InApp purchase validation, you also need to:
- Declare one or more InApp products. You just need to declare them, without providing a screenshot.
Sandbox Test Accounts Tip
Each In-App Purchase sandboxtest user account is tied to one and only one email address. As such, you cannot reuse an existing email address with another test user account. You can create as many test user accounts as you want in iTunes Connect. Furthermore, if your email service provider supports email addresses with "+" sign, you can use that as an alias for your normal email address. For instance, if your email is foo@example.com, then you can use the foo+us@example.com, foo+uk@example.com, and foo+fr@example.com emails when creating test user accounts in iTunes Connect. All communications sent to foo+us@example.com, foo+uk@example.com, and foo+fr@example.com will be routed to foo@example.com.
Testing on OS X
Now that all the pre-requisites are ready, you can test your receipt validation code:
- Launch the application from the Finder. DO NOT LAUNCH it from Xcode !!! It is important to launch it from the finder so the launchd daemon can trigger the receipt retrieval.
- The lack of receipt should make the application exit with a code 173. This application’s exit trigger the request for a valid receipt. An App Store login window should appear; use the test account credentials to sign-in and retrieve the test receipt.
- If the credentials are valid and the bundle information match the one you entered, then a receipt is generated and installed in the application bundle. After the receipt is retrieved, the application is re-launched automatically.
For InApp purchases:
- Within your application, make some purchases. Use your test account when you are required to sign-in. Purchases are stored within the receipt; by using another validation code, you can verify that the purchases are present.
Testing on iOS
Now that all the pre-requisites are ready, you can test your receipt validation code:
- Launch the application on a real device. DO NOT LAUNCH it in the simulator, it won’t work !!!
- The lack of receipt should make the application trigger a receipt refresh request. An AppStore login window should appear; use the test account credentials to sign-in and retrieve the test receipt.
- If the credentials are valid and the bundle information match the one you entered, then a receipt is generated and installed in the application sandbox. After the receipt is retrieved, you can perform another validation to ensure that everything is ok.
For InApp purchases:
- Within your application, make some purchases. Use your test account when you are required to sign-in. Purchases are stored within the receipt; by using another validation code, you can verify that the purchases are present.