How to test IAP with Sandbox User in the Sandbox environment? - ios

I can test in the Xcode environment.
I can test with TestFlight which uses a REAL Apple Id to make purchases in the Sandbox Environment.
But how do I test with a Sandbox User in the Sandbox Environment? Because I need to be able to clear out my Sandbox user purchase history so that I can test first purchases again.
I've been reading through the documents and I feel like each particular doc jumps over the piece of info that I need. It explains how to create a Sandbox Test User and I've done that. I did plenty of IAP work many years ago, but things have changed enough that it's not working as I expect. When I read the docs, I feel like I can't find the missing piece.
When I test in a simulator with Xcode, it does my IAP transactions in the Xcode environment. That makes sense.
https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases_with_sandbox
This page says:
To run your app using your Sandbox Apple ID, build and run your app
from Xcode.
But when I test on a physical device installing directly from Xcode, it also does my IAP transactions in the Xcode environment. I thought this would put me in the Sandbox environment, but it didn't. The Xcode transactions manager shows the transactions. The initial purchase view controller didn't reference the Sandbox at all and the "You're All Set" alert shows Environment: Xcode instead of Environment: Sandbox.
When I put a test build into TestFlight and test using that version, my IAP transactions are happening in production using my real Apple Id (but I'm not actually charged for any transactions).
I assumed that testing in TestFlight would give me the Sandbox environment, but it happens in the Production environment. (The purchase view controller doesn't show Sandbox and the "You're All Set" alert doesn't show Sandbox.)
So, how do I test in the Sandbox? Every way I try to test either puts me in the Xcode environment or the Production Environment.
What am I missing?
I've logged out of my real Apple id on my phone and then logged in with the Sandbox User credentials I created in AppStore Connect. But when I tried to test the app, by installing from Xcode it still says I'm in the Xcode test environment. When I create transactions, those transactions show up in the Xcode Transaction Manager.
How do I test in the Sandbox environment?

The difference between IAP being in "Xcode" mode versus being in "Sandbox" mode is whether you setup a StoreKit Configuration or not on your target's scheme.
In Xcode select the Product menu and go to Scheme, then "Edit Scheme...". Select Run on the left side and then go to the Options tab.
For the "StoreKit Configuration" setting you will get Xcode mode if you select a specific configuration. You will get Sandbox mode if you set this option to None even when running the app from Xcode.
None of this applies when running from TestFlight. In TestFlight you are in full production mode.
To verify this I logged into a sandbox account in the Settings app under App Store -> SANDBOX ACCOUNT. I then ran my app via Xcode and went through some IAP in my app. When the StoreKit Configuration was set to None the IAP screens showed "Sandbox". When the StoreKit Configuration was set to a specific storekit file the IAP screens showed "Xcode".

Related

In the Sandbox test of StoreKit2 billing process, can I cancel a purchase of a Non-Consumable item?

I have recently started developing an IOS app in xcode.
I am implementing the billing process with Storekit2, but after purchasing a "non-consumable" item with a sandbox account, I am unable to cancel the purchase.
The official site says that this is the case, but in order to test it, we would like to test the purchase process repeatedly in a sandbox environment that is similar to the production environment.
We have the following two tests for Storekit2, and we are aware that Storekit Configuration can be tested over and over again.
Storekit Configuration
Sandbox
1, Is there any way to cancel to buy in order to test billing over and over again?
2, In actual practice, do we try various cases with Storekit Configuration and if it is OK, we release it already?
3, Also, before the advent of Storekit Configuration, how did you test a "non-consumable" product multiple times?
If anyone has more information, please let me know!
TL,DR: learn more about Testing all stages with IAP here
Yes, you could do "Clear the purchase history" as it's listed
Screenshot
Xcode enviroment
When you're running app from your Xcode on simulator or device, just click button Manage Storekit Transactions. Then you could test with any stage, refund or clear purchase history
Manage Storekit Transactions
Sandbox
Just login AppStoreConnect, Users and Access -> Select tab Sandbox Testers -> there is Edit button, just follow it to clear transaction history
Sandbox Testers

Devices with iOS 15 ignore my sandbox account during test in-app purchases

We have recently updated several test devices from iOS 14.7.1 to 15.2. After that, when trying to make a test purchase inside our app, TestFlight ignores the sandbox accounts (which we add to Settings -> Apps-Store -> Sandbox account) and uses the main account that is used for purchases in the App Store.
The SandBox account works fine if you log out as the main user in the App Store - but then you can't use TestFlight to download test builds.
maybe someone has faced a similar problem and knows the solution or will tell me in which direction to look?
TestFlight ignores the sandbox accounts (which we add to Settings -> Apps-Store -> Sandbox account) and uses the main account
That is correct behavior. The sandbox account is for when you are running an Xcode build. TestFlight, on the other hand, always uses your real account, but it doesn't charge you (and the same for your beta testers).
#matt is right. The only what I can add here is that after you
logged in as sandbox user > attached device to xcode > run the build > made the purchase with sandbox user
you will be able to use that sandbox user even in next TestFlight builds.
For other testers this new approach is very uncomfortable, expecially if tester has a very complex password for their primary accounts... Apple made these things worst, for sure.
Btw, important to note that making purchases using primary account in sandbox environment (liek your testers do in TestFlight builds) will also reset the subscriptions in some time range. Not sure what exactly, probably from 5min to 1h. I didn't know it and had tons of questions, why my app doesn't recognise any previous subscription made recently. Purchase restore response also says that there is nothing to restore... Weird way of tasting, Apple...

How to test touch dialog and perform real in-app purchase?

I have submitted my iOS app. The status is now pending developers release . In-app auto renewable subscriptions are approved. When I test, the app still prompt sandbox dialog for me to enter sandbox account password to verify my purchase. I cannot test real purchase and cancel under this situation . Would you please tell me what is the next step?
To test in-app in Production environment, not Sandbox, you need to have the appropriate build.
If you are running from Xcode, you are automatically acting in Sandbox.
To have a Production environment, you need to make an AdHoc build (distributed via services like diawi.com) or AppStore build (distributed via Testflight).

how to switch from Sandbox to live in In App purchase

I am using In App purchase and it is working fine when i am testing it from the sandbox account. But when i tried to purchase the online subscription by making amount zero by live account. it is giving an error of
[you are not authorised to make purchase in this inApp in SandBox at this time Environment Sandbox]
i guess it was setup in sand box mode. So As i tested in sandbox and it is working fine ho can i make it live to that any one can purchase it.
I got my answer for the apple document that app installed from Xcode is always in Sandbox environment and app download from live itunes is Live. thanks a lot to all and specially for one who commented heae on post and guided me.
=>
StoreKit connects to the sandbox environment when you launch your application from Xcode, from your test device (iOS), or from the Finder (OS X). It connects to a production environment for applications that were downloaded from the App Store. You must not use your test user account to sign into the production environment. This will result in your test user account becoming invalid. Invalid test accounts cannot be used to test In-App Purchase again.
<=
Apple Document
You can not test live app with sandbox test ID as sandbox email ID has no real credit. If In App Purchase is working for sandbox ID, it will work for real IDs too.

iOS In App Purchase: test a real purchase without submitting to Apple

I implemented in app purchase in my iOS app and I want to do a real test (not a sandbox) before submitting this new version to Apple
Of course, the current version of the app (in the App Store) was validated with a product
So, I archived the app using an Ad Hoc distribution profile and I generated an IPA file for Ad Hoc deployment. But when I installed the app via Testflight on my device, I discovered that the app was in sandbox environment!
Is there a way to do a "real" purchase before submitting the app to the App Store ?
You can actually test the in-app purchasing in the sandbox environment, basically you'll need to set up an test user account in your iTunesConnect.
Check the apple documentation here:
http://developer.apple.com/library/ios/#technotes/tn2259/_index.html
You'll be able to find all the information related to In-App Purchasing, including sandbox testing.
Short answer: you can't test a real purchase (aka, spend real money). It isn't possible.
Slightly longer answer: You'll automatically hit the sandbox environment unless it's an apple-signed release build. Even ad-hoc signed builds hit the sandbox.
To test a new IAP: create your IAP (it will be in "needs approval mode" until submitted with the final build and test against the sandbox - that's fine). If your purchase works against the sandbox, it should work against prod with real money as well. It would be great to do a trial run with real money, but that's just not possible until the IAP is approved and you get the production signed version of the app from the app store.
Just create a test account on iTunes Connect. Then log out from the device and run your app from Xcode.
To get access to the purchase you need apple signature, because you are connecting with the apple servers.
I assume that your app, is doesnt have that signature, so your request goes to the sandbox.

Resources