145

Does anyone have any ideas on how to reset and/or clear the iOS in-app purchase sandbox?

I have an app that I'm testing with the sandbox, and I'd like to test new purchases without having to create a new test user every time I purchase something.

If I don't do this, then I (of course) always get a message that the in-app purchase item has already been purchased when I click on my app's buy button.

0

10 Answers 10

87

IMO there are 3 things you can do to make testing non-consumables bearable:

  1. You can have many test accounts associated to one email. Gmail for example lets you add a "plus" string to the email to create aliases for an address: so [email protected] and [email protected] both really just go to [email protected]. Probably other email hosts do the same. When you create a test account you need to introduce: first name, last name, email address, password, secret question, secret answer, date of birth, and iTunes store country. You can put exactly the same data (including password) for [email protected] and [email protected] and you will have two test accounts. Finally, in your [email protected] inbox you will receive two verification emails from Apple to confirm both test accounts.

  2. Say that you have a non-consumable with product ID @"Extra_Levels". Instead of writing @"Extra_Levels" in all methods (requestProduct, purchaseProduct, ...), just write PRODUCT_ID1 and at some header file put #define PRODUCT_ID1 @"Extra_Levels" (with no semicolon!), then the preprocessor will search PRODUCT_ID1 and substitute it for @"Extra_Levels". Then creating a new non-consumable called @"Extra_Levels_01" and changing the #define will be as good as resetting the purchases for all your test users.

  3. As appsmatics pointed out, you can test the correct behavior of your code when you buy a non-consumable IAP by first using a consumable IAP (so that test user can make as many purchases as needed) to get rid of some bugs. Of course, you should also test the code with the real non-consumable IAP after that.

13
  • 25
    Wow, I never knew of this super-secret gmail feature. How useful!
    – bobobobo
    Nov 21, 2013 at 1:26
  • 4
    I just found out that you don't really have to verify your test user email. you can simply put [email protected] with specify password(that you are still going to use the password in sandbox mode) and it still work. I just tested last night.
    – sooon
    May 1, 2014 at 12:24
  • 4
    The PLUS SIGN trick for email aliases is not a GMail thing alone. It is a very old tradition amongst email servers, going back decades. But it was never incorporated into any email specifications. So, test it with your particular email server to be sure it is savvy with this feature. Jun 6, 2014 at 8:42
  • 3
    I would'n think that it is impossible to clear In-App purchases for test account;) Viva Apple:) Jan 13, 2016 at 13:57
  • 19
    + email addresses can no longer be used to sign up for Apple IDs.
    – pkamb
    Oct 31, 2019 at 23:43
34

You can clear the purchase history for a tester so that you can continue to use the same sandbox Apple ID for ongoing testing. Clearing purchase history will delete all past auto-renewable subscriptions and non-consumables purchased by the selected testers in the sandbox environment. In-app purchases made by customers on the App Store are not affected.

To clear tester purchase history:

From Users and Access, under Sandbox, click Testers.

Click Edit.

enter image description here

Select the checkbox for each tester you want to modify and click Clear Purchase History.

enter image description here

Click Clear Purchase History in the dialog that appears.

enter image description here

Sandbox Apple IDs with a high number of purchases may take longer to clear. This action cannot be reversed.

2
  • 1
    Make sure to delete your app from your device afterwards too, in case there's any caching happening. Sep 10, 2022 at 4:23
  • 1
    This answer is correct, but Sandbox Testers is now in a tab across the top, not in the sidebar. Nov 8, 2023 at 2:30
11

I have 2 in app purchase items. 1 for production. and the other for testing. when I need to "clear" I delete the in app item and create new one (15 seconds in itunes connect and 1 second to change the product id in code)

if i dont need to test "new user", i use the production in app item.

1
  • Yes, making a new copy of the product, and changing the product name in the code (presumably having #defined it) seems by far the easiest solution for realistic testing. Nov 13, 2014 at 11:07
11

Deleting your app and reinstalling works also for sandbox testing. Depends on the app obviously, but I'm testing a subscription based app that only purchases during sign up at the moment so it's been the easiest solution.

0
8

Well, technically you don't need that.

If you get SKPaymentTransactionStateRestored, it is 100% equivalent to the app store verifying the user and granting him the purchase. I have a switch like:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
  for( SKPaymentTransaction *purch in transactions )
  {
    switch( purch.transactionState )
    {
      case SKPaymentTransactionStateRestored:
        info( "PURCHASE RESTORE" ) ;
        // fall thru
      case SKPaymentTransactionStatePurchased:
        [[SKPaymentQueue defaultQueue] finishTransaction:purch];
        // Do regular changes to app state for this purchase,
        // register in keychain, etc.
        break ;

       //.. other cases
     }
  }
}

The question of having your app logic / take back the purchase is simple: if you're caching purchases in keychain, delete your keychain. If you're doing it some other how, just change your local app state to pretend like the user never purchased it before. The request to purchase dialog is still exactly the same, the only difference is when you punch YES, it gives you SKPaymentTransactionStateRestored instead of SKPaymentTransactionStatePurchased.

4

You can clear the purchase history for a sandbox Apple ID in App Store Connect.

To clear tester purchase history:

  1. From Users and Access, under Sandbox, click Testers.
  2. Click Edit.
  3. Select the checkbox for each tester you want to modify and click Clear Purchase History.
  4. Click Clear Purchase History in the dialog that appears.

see Documentation https://help.apple.com/app-store-connect/#/dev7e89e149d

2
  • Best answer. Thanks!
    – Silvering
    Nov 9, 2021 at 15:12
  • 4
    Best ONLY ONCE. If you are expecting to reset the transactions for a tester account lots of times, beware the Apple Warning: "Sandbox Apple IDs with a high number of purchases may take longer to clear." What this means is that if you reset more than once, you get put on the bottom of a queue, and it make take longer than you want for the reset to occur. Like more than a day. This is why the TOP answer rules. If you're resetting a lot, you need multiple tester accounts to be able to work without waiting. Dec 4, 2021 at 21:58
3

Check out SimStoreKit. It's a "simulated version of the iPhone's StoreKit, for testing store UIs on the iPhone Simulator, or even on device without having to set up IAP in Connect."

SimStoreKit stores purchases in the user defaults under the key ILSimSKTransactions. So to clear all purchases you can do:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ILSimSKTransactions"]

On the simulator, you can simply remove your app and install it again.

I've successfully used SimStoreKit to debug my app's store front before testing with the sandbox. The beauty of this library is that it can be set-up to use the same class names as the real StoreKit framework (by doing #define ILSimReplaceRealStoreKit 1 before doing #include <ILSimStoreKit.h>).

In source files where I need to access StoreKit, I include this header file:

#import <TargetConditionals.h>

#if TARGET_IPHONE_SIMULATOR
    #define kILSimAllowSimulatedStoreKit 1
    #define ILSimReplaceRealStoreKit 1
    #import <ILSimStoreKit.h>
#else
    #import <StoreKit/StoreKit.h>
#endif

This has the effect of using SimStoreKit when I run on the simulator and the real StoreKit when I run on the device.

2
  • couldn't get this to work. I'm getting a build error. I copied all the files in the zip into my project and replaced all the #import <StoreKit/StoreKit.h> with #define ILSimReplaceRealStoreKit 1 #import "ILSimStoreKit.h"
    – Jay Q.
    Jan 21, 2012 at 6:00
  • You just need the files that start with ILSimSK. The other stuff is for the demo app. Perhaps you should post a question with the exact error you're getting. "I'm getting a build error" doesn't say much. Jan 21, 2012 at 7:53
0

This is now possible for subscriptions purchases through Reset Eligibility

  1. On the test iOS device, open Settings > Apple ID > Media & Purchases (or iTunes &/or App Store for iOS 13 and earlier). Under the Sandbox Account section, tap your highlighted Sandbox Apple ID then tap Manage to open the sandbox Subscription Management page.
  2. If the subscription has expired, tap one of the options to resubscribe.
  3. Once you resubscribe or when you have a subscription going on, you can use the Reset Eligibility button to reset and redeem another introductory offer (trial or discounted price).
1
  • This doesn't work for normal, single purchase (non-subscription) In app purchases. Although it's a good tip, the original question didn't mention subscription purchases.
    – jxd
    Oct 12, 2021 at 12:34
-1

Just keep using the same test account, restoring purchases as opposed to completing new ones. After all, whether you start a new purchase or restore an old one, YOUR APP will do the same thing (at least initially, maybe the user interface will update differently upon completion). Apple are the folks handling things differently in those different situations - don't worry about it.

Place your delivery logic in the SKPaymentTransactionStateRestored case within this method's implementation for testing:

- (void)paymentQueue:(SKPaymentQueue *)queue
 updatedTransactions:(NSArray *)transactions;

Then be sure to put that delivery logic into the SKPaymentTransactionStatePurchased case.

At the end, because most of us are obsessive-compulsive to varying degrees, do a final test with a fresh account (not a big deal to make a second one for absolute certainty).

The final thing to note: consider apple's position. If there was a problem with developers having to waste time creating tens or hundreds of accounts to test IAP thoroughly, they would have solved the problem. There is no problem.

-3

alternatively to create multiple test user solution you can create multiple test in app purchases in iTunes connect then you don't need to change a user account.

1
  • 1
    Reason for downvotes are: 1. It is not a good solution as you may be trying to test specific In App purchase solution that may require a lot of scenarios with application user login and cross device/platform content availability. 2. It is as (infact more) tedious creating multiple test purchases as creating multiple test accounts. 3. Also, answer is not very well formatted.
    – mickeymoon
    Apr 26, 2019 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.