Apple introduced Promoted In-App Purchases in iOS 11. Though I have implemented the new required SKPaymentTransactionObserver method, paymentQueue:shouldAddStorePayment:for:, I have not been able to successfully test "buying" an item. Should one be able to test and purchase in the Sandbox test environment?
Apple does discuss initiating testing through an URL of the form:
itms-services://?action=purchaseIntent&bundleId=com.example.app&productIdentifier=com.example.app.myIAP
I've put the URL in an email to myself. When I click on the URL, I get the following sequence:
1) Switches to MyApp, and shouldAddStorePayment is called with a product with my product identifier, com.example.app.myIAP (encouraging start)
2) Have paymentQueue:shouldAddStorePayment:for: return true.
3) paymentQueue:updatedTransactions: is called, with a transaction in the “purchasing” (but not purchased) state. It has a nil transactionIdentifier.
4) An alert pops up saying to Sign In. I sign in with a sandbox Apple ID - hitting the “Buy” button on the sign in alert.
5) Another pop up saying to Sign In. I sign in with a sandbox Apple ID - hitting the “Buy” button on the sign in alert.
6) paymentQueue:updatedTransactions: is called, with a transaction in the “failed” state. It has a non-nil transactionIdentifier.
Should the shouldAddStorePayment routine be doing something extra?
Promoting in-app purchases requires two steps: Set up in-app purchases in App Store Connect by uploading promotional images for the in-app purchases you'd like to promote. You can then use the App Store Promotions tool in App Store Connect to manage their order and visibility on the App Store.
I submitted the app with the limited testing as described above. And I was able to do real purchases of promoted in-app-purchases.
But there is a chicken and egg scenario here. Now that the items are in the store, I can run against a local/debug build and test from the App Store. But I think I also burned through several Sandbox User IDs trying things out.
Following is a sequence that I can now do.
1) Go to App Store and log out.
2) Build/run your app and use Restore Purchases - logging in with your Sandbox User ID/password.
3) Verify that your Sandbox User is now logged into the App Store (do not log in directly to the App Store with Sandbox User or that user will no longer work.)
4) Find your app and then find the In-App Purchases section with the promoted features. Select a promoted in-app purchase feature.
5) Your app is loaded. After a bit, one gets an alert with: Confirm Your In-App Purchase ---- Do you want to buy XXXX for $0.99? --- [Environment: Sandbox] ---- Cancel / Buy
6) After purchase one gets the alert: You're all set. ---- Your purchase was successful. ---- [Environment: Sandbox] ---- OK
7) if you do this on an item your Sandbox User has already purchased, you get an alert with: You've already purchased this. Would you like to get it again for free? ---- [Environment: Sandbox] ---- Cancel / OK
The point of the above is that you get alert messages like what you saw before rather than the receipt type item popping up from the bottom that you get when you do a real purchase.
Hope this helps, but still not a good answer for first time through.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With