StoreKit Test

RSS for tag

Create and automate tests in Xcode for your app's submission and in-app purchase transactions.

Posts under StoreKit Test tag

110 Posts

Post

Replies

Boosts

Views

Activity

Problems using sandbox to test in app purchases
Three main questions: How do I know I'm using my sandbox account in my app because when signing in, it only shows my normal apple account? How do I make sure I configured my subscriptions correctly in app store connect? How do I test without local storekit configs? Some context: I created a paywall (using a 3rd party service, superwall) for my app and everything seems to work when using local storekit configs. I submitted for review and the reviewer is having problems with purchasing because my paywall can't find the product I set up in app store connect. I have been trying to debug. I set up a sandbox tester account and can confirm that I am logged in my phone's developer settings. But when I log in my app, the sign in with apple pop up only gives the choice to sign in with my apple ID. Is this normal? Does apple just treat these accounts the same? Also, I can't seem to pull subscription info from app store connect when creating a synced storekit config. I created a new subscription in app store connect, so now I have two, a test and a weekly one. When I create a local storekit config and sync from the appstore, only my test one shows. For context, the weekly subscription shows up as "waiting for review" while test shows up as "ready to submit". Idk if that makes a difference. I highly suspect I misconfigured something with my in app subscriptions. I'm trying to replace superwall with my own built in paywall. But I can't seem to pull any product from the app store unless I use a storekit config, but even then, my weekly one doesn't show up. Plz help.
0
0
70
Apr ’25
Problems when testing Storekit purchases and subscriptions in Xcode and TestFlight
I have an app that unlocks content based on in-app purchases, both one-time payments and subscriptions. Recently, I added new subscription products, both for distribution in App Store Connect and in the configuration file in XCode to be able to test it, declaring it in the scheme. Since the beginning of development, I have had issues with subscriptions. Every time I close the app and reopen it, in order for the app to recover which subscription is active, I have to run the purchase function. This doesn’t happen with purchases or in the production environment, where it works fine. I’ve now implemented SubscriptionStoreView, so I don’t depend on my business logic, in case I’m doing something wrong in the code. This view never remembers which product I’ve already purchased. Currently, in a version deployed to my phone from XCode, it doesn't even process the payment. On macOS, the experience is even worse. On iPad, through TestFlight, I haven’t even been able to test payments at all.
0
0
64
Apr ’25
Reuse a product id from app A in app B for In-app purchase in my iOS app
I have an app which is already on App Store with In-app purchase. Now I want to integrate In-app purchase in my another app for the same products as in the existing app. Both the apps are using same Apple Account. Can I reuse those Product Ids from the first app in the second one. If yes, what is the ways to use them. Thank you in advance.
1
0
69
Apr ’25
Unknown Error Occurring During Sandbox Purchase Testing
We are experiencing an Unknown Error (error code 0) when testing purchases in the Apple Sandbox environment. The error does not occur every time, but it fails with an Unknown Error in approximately 8 out of 20 attempts. Due to this issue, our app is failing to pass Apple’s review. Issue Details This issue only occurs in the Apple Sandbox environment. After attempting a purchase, the Apple payment API returns SKPaymentTransaction Unknown Error. Returned error code: SKErrorUnknown (error.code 0). This problem is preventing us from conducting proper payment tests and getting approval from Apple. Would it be possible to receive support or any solutions for this issue?
0
2
181
Mar ’25
Auto-renewing Subscription Updates not Arriving
This is a copy of a reply to this post. https://developer.apple.com/forums/thread/722222?page=1 I'm posting as new in the hope someone might have more up-to-date information, as I'm pulling out what little hair I have left. I'm using Storekit 2, testing in Xcode with a local Storekit config file. I have created a very minimal system to investigate this issue. I have a SwiftUI-based window using SubscriptionStoreView, and my app set up with the usual listener. I have four types of auto renewing subscription, configured in the local Storekit config file. With my app running, I subscribe to the lowest-level subscription I offer, via the SubscriptionStoreView. Notification of the inital purchase arrives, but subsequent auto-renewals do not trigger any action in my listener for Transaction.updates. They arrive as expected in the Transaction Manager. Radio silence in my listener. If I upgrade one subscription (via my SubscriptionStoreView) I see this reflected in the UI immediately, and also in the Transaction Manager, but the update that arrives in Transaction.updates refers to the old subscription, and has the isUpgraded flag set to false. Also, can anyone remind me what the grey warning triangle next to entries in the Transaction Manager means. I'm assuming it means unfinished, as that's what the sidebar indicates. Can the testing system really be this broken, or am I wildly off the mark? Unless I'm doing something fundamentally wrong this all seems extremely flakey, but happy to be proved wrong. I find this all rather unsettling if I can't test reliably, and am concerned that I my app may end up in this situation if I use storekit 2: https://stackoverflow.com/questions/73530849/storekit-renewal-transactions-missing-in-transaction-all-or-transaction-updates
9
1
1.9k
Mar ’25
In-App Subscription
Hi, I have a problem with StoreKit regarding in-app subscription purchases. When I upload the app to TestFlight and during the review process, it doesn’t work on a real device. However, it works fine on the simulator. I get the error: "Subscription unavailable" (see image). Does anyone know what might be causing this and how to fix it? Please help!
1
0
202
Mar ’25
Issues with Testing Promotional Offers for Auto-Renewable Subscriptions (StoreKit 2)
We are in the process of implementing promotional offers for auto-renewable subscriptions in our app using StoreKit 2. For testing, we use a sandbox user alongside a new user on our platform. I can successfully purchase an Introductory Offer through the app. Once the user is eligible for a Promotional Offer (based on a previous purchase), we retrieve the Promotional Offer identifier and signature from our backend and display the offer. After initiating the purchase and having the user enter their Sandbox password, the transaction is added to the Payment Queue. However, it fails with the following error: Purchase failed error: invalidOfferSignature Additionally, the error returned is: "Purchase did not return a transaction: Error Domain=ASDServerErrorDomain Code=3903 "Unable to Purchase" UserInfo={NSLocalizedFailureReason=Unable to Purchase, client-environment-type=Sandbox, AMSServerErrorCode=3903, storefront-country-code=IND}" We are using StoreKit 2 APIs for this process. Has anyone encountered this issue when working with StoreKit 2, or found a solution to resolve it?
2
2
397
Mar ’25
Migrating a Paid App to In-App Subscriptions
Hello, I’m trying to change the business model of my app to in-app subscriptions. My goal is to ensure that previous users who paid for the app have access to all premium content seamlessly, without even noticing any changes. I’ve tried using RevenueCat for this, but I’m not entirely sure it’s working as expected. I would like to use RevenueCat to manage subscriptions, so I’m attempting a hybrid model. On the first launch of the updated app, the plan is to validate the app receipts, extract the originalAppVersion, and store it in a variable. If the original version is lower than the latest paid version, the isPremium variable is set to true, and this status propagates throughout the app. For users with versions equal to or higher than the latest paid version, RevenueCat will handle the subscription status—checking if a subscription is active and determining whether to display the paywall for premium features. In a sandbox environment, it seems to work fine, but I’ve often encountered situations where the receipt doesn’t exist. I haven’t found a way to test this behavior properly in production. For example, I uploaded the app to TestFlight, but it doesn’t validate the actual transaction for a previously purchased version of the app. Correct me if I’m wrong, but it seems TestFlight doesn’t confirm whether I installed or purchased a paid version of the app. I need to be 100% sure that users who previously paid for the app won’t face any issues with this migration. Is there any method to verify this behavior in a production-like scenario that I might not be aware of? I’m sharing the code here to see if you can confirm that it will work as intended or suggest any necessary adjustments. func fetchAppReceipt(completion: @escaping (Bool) -> Void) { // Check if the receipt URL exists guard let receiptURL = Bundle.main.appStoreReceiptURL else { print("Receipt URL not found.") requestReceiptRefresh(completion: completion) return } // Check if the receipt file exists at the given path if !FileManager.default.fileExists(atPath: receiptURL.path) { print("The receipt does not exist at the specified location. Attempting to fetch a new receipt...") requestReceiptRefresh(completion: completion) return } do { // Read the receipt data from the file let receiptData = try Data(contentsOf: receiptURL) let receiptString = receiptData.base64EncodedString() print("Receipt found and encoded in base64: \(receiptString.prefix(50))...") completion(true) } catch { // Handle errors while reading the receipt print("Error reading the receipt: \(error.localizedDescription). Attempting to fetch a new receipt...") requestReceiptRefresh(completion: completion) } } func validateAppReceipt(completion: @escaping (Bool) -> Void) { print("Starting receipt validation...") guard let receiptURL = Bundle.main.appStoreReceiptURL else { print("Receipt not found on the device.") requestReceiptRefresh(completion: completion) completion(false) return } print("Receipt found at URL: \(receiptURL.absoluteString)") do { let receiptData = try Data(contentsOf: receiptURL, options: .alwaysMapped) print(receiptData) let receiptString = receiptData.base64EncodedString(options: []) print("Receipt encoded in base64: \(receiptString.prefix(50))...") let request = [ "receipt-data": receiptString, "password": "c8bc9070bf174a8a8df108ef6b8d2ae3" // Shared Secret ] print("Request prepared for Apple's validation server.") guard let url = URL(string: "https://buy.itunes.apple.com/verifyReceipt") else { print("Error: Invalid URL for Apple's validation server.") completion(false) return } print("Validation URL: \(url.absoluteString)") var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "POST" urlRequest.httpBody = try? JSONSerialization.data(withJSONObject: request) URLSession.shared.dataTask(with: urlRequest) { data, response, error in if let error = error { print("Error sending the request: \(error.localizedDescription)") completion(false) return } guard let data = data else { print("No response received from Apple's server.") completion(false) return } print("Response received from Apple's server.") do { if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] { print("Response JSON: \(json)") // Verify original_application_version if let receipt = json["receipt"] as? [String: Any], let appVersion = receipt["original_application_version"] as? String { print("Original application version found: \(appVersion)") // Save the version in @AppStorage savedOriginalVersion = appVersion print("Original version saved in AppStorage: \(appVersion)") if let appVersionNumber = Double(appVersion), appVersionNumber < 1.62 { print("Original version is less than 1.62. User considered premium.") isFirstLaunch = true completion(true) } else { print("Original version is not less than 1.62. User is not premium.") completion(false) } } else { print("Could not find the original application version in the receipt.") completion(false) } } else { print("Error parsing the response JSON.") completion(false) } } catch { print("Error processing the JSON response: \(error.localizedDescription)") completion(false) } }.resume() } catch { print("Error reading the receipt: \(error.localizedDescription)") requestReceiptRefresh(completion: completion) completion(false) } } Some of these functions might seem redundant, but they are intended to double-check and ensure that the user is not a previous user. Is there any way to be certain that this will work when the app is downloaded from the App Store? Thanks in advance!
1
0
405
Mar ’25
Sign in with Sandbox account in Xcode Simulator
Hello! I'm working on implementing SwiftUI + StoreKit2 IAP in my app, and Xcode testing has been fantastic, now I'd like to test my app with Sandbox, where I created a Sandbox account, and it works on my physical device, I can log in, make transactions, etc. (btw, feedback: please improve the UX for Sandbox testing, it's really clumsy compared to Xcode testing with Transaction Manager) My problem is that when I'd like to log in with my Sandbox account on the simulator (Settings -&gt; Developer -&gt; Sandbox Apple Account (at the bottom) -&gt; Sign in), it doesn't work, it fails silently. I know it authenticates well, because if I type in the wrong password, I get an error popup, but with the right password, it just fails silently, hides the login sheet and the "Sign in" text remains "Sign in" (on my phone when I log in, the "Sign in" is replaced with the email address of the Sandbox account). I know many people get errors, and they recommend to go icloud.com and acccept TOS (done that), also to download the latest iOS for the simulator (also done), these are not a problem for me, as I don't get any errors. My authentication works, but for some reason the simulator still won't log in, it fails silently, and I see no errors/reason why. Tried with different simulators (latest iOS version), same result, tried to reboot the simulator, same result. Any idea why is this happening? Thank you, sendai
1
1
435
Mar ’25
Sandbox user can't see StoreKit subscriptions
Hi everyone, I’m struggling to get StoreKit 2 to fetch products in my SwiftUI app while using a sandbox user. I think I’ve followed all necessary setup steps in Xcode, App Store Connect, and my physical test device, but Product.products(for:) always returns an empty array. I’d appreciate any insights! What I’ve Done Local App Setup (Xcode 16.2) Created a blank SwiftUI Xcode project. Enabled In-App Purchase capability under Signing & Capabilities. Implemented minimal StoreKit 2 code to fetch available products (see below). Using the correct bundle identifier, which matches App Store Connect. App Store Connect Configuration Registered the app with the same bundle identifier. Created an Auto-Renewable Subscription with: Product ID: v1 (matches my code). All fields filled (pricing, localization, etc.). Status: Ready for Review. Linked the subscription to the latest app version in App Store Connect. Sandbox User & Testing Setup Created a sandbox tester account. Logged in with the sandbox user under Settings → Developer → Sandbox Apple ID. This was on my physical device (iOS 18.2). Installed and ran the app directly from Xcode (⌘+R). Issue: StoreKit Returns No Products Product.products(for:) does not return any products. There are no errors thrown, just an empty array. I confirmed that StoreKit Configuration is set to None in Xcode. No StoreKit-related logs appear in the Console. Code Snippets //StoreKitManager.swift import StoreKit import SwiftUI @MainActor class StoreKitManager: ObservableObject { @Published var products: [Product] = [] @Published var errorMessage: String? func fetchProducts() async { do { let productIDs: Set<String> = ["v1"] // Matches App Store Connect let fetchedProducts = try await Product.products(for: productIDs) print(fetchedProducts) // Debug output DispatchQueue.main.async { self.products = fetchedProducts } } catch { DispatchQueue.main.async { self.errorMessage = "Failed to fetch products: \(error.localizedDescription)" } } } } //ContentView.swift import SwiftUI struct ContentView: View { @StateObject private var storeKitManager = StoreKitManager() var body: some View { VStack { if let errorMessage = storeKitManager.errorMessage { Text(errorMessage).foregroundColor(.red) } else if storeKitManager.products.isEmpty { Text("No products available") } else { List(storeKitManager.products, id: \.id) { product in VStack(alignment: .leading) { Text(product.displayName).font(.headline) Text(product.description).font(.subheadline) Text("\(product.price.formatted(.currency(code: product.priceFormatStyle.currencyCode ?? "USD")))") .bold() } } } Button("Fetch Products") { Task { await storeKitManager.fetchProducts() } } } .padding() .onAppear { Task { await storeKitManager.fetchProducts() } } } } #Preview { ContentView() } Additional Information iOS Version: 18.2 Xcode Version: 16.2 macOS Version: 15.3.1 Device: Physical iPhone (not simulator) TestFlight Build: Not used (app is run directly from Xcode) StoreKit Configuration: Set to None
2
0
381
Mar ’25
IAP StoreKit2 Can Not Fectch Products
I am currently using StoreKit2 to set up the in-app purchase subscription flow, and I have already configured the subscription products in App Connect. I created a StoreKit Configuration file in Xcode and used it in the scheme. However, after completing the purchase, the transaction.jsonRepresentation data returns a transactionId of 0. After checking the documentation, I found that I need to disable the StoreKit Configuration and enable Sandbox Testing. But after disabling the StoreKit Configuration, I can't retrieve the real product data using Product.products(for: productIds). I can confirm that the ProductId I provided is real and matches the data configured in App Connect. Could you please help me identify the issue? Thank you
1
0
273
Mar ’25
Validating receipt for iOS in-app purchase always returns error 21002
I'm receiving the following error when attempting to validate an in‑app purchase receipt: Certificate verification failed at depth 0 : forge.pki.UnknownCertificateAuthority Certificate chain validation failed: Certificate is not trusted. This error occurs during the certificate chain validation process of the receipt's PKCS#7 container. My implementation uses node‑forge to decode the receipt, extract the embedded certificate chain, and verify that the chain properly links from the leaf certificate (which directly signed the receipt) through the intermediate certificate to the trusted Apple Inc. Root certificate. What the Error Indicates: "UnknownCertificateAuthority" at depth 0: This suggests that the leaf certificate in the receipt is not being recognized as part of a valid chain because it cannot be linked back to a trusted root in my CA store. "Certificate chain validation failed: Certificate is not trusted": This means that the entire certificate chain does not chain up to a trusted certificate authority (in this case, the Apple Inc. Root certificate) as expected. Steps Taken: I verified that the receipt is a valid PKCS#7 container. I extracted the certificate chain from the receipt. However, the receipt only provided the leaf certificate. I manually added the intermediate certificate (AppleWWDRCAG5.pem) to complete the chain. I loaded the official Apple Inc. Root certificate (AppleIncRootCertificate.pem) into my CA store. Despite these steps, the validation still fails at depth 0, indicating that the leaf certificate is not recognized as being issued by a trusted authority. Request for Assistance: Could you please help clarify the following points: Is the certificate chain for receipts (leaf → intermediate → Apple Inc. Root) as expected, or has there been any change in the chain that I should account for? Is there a recommended or updated intermediate certificate I should be using for receipt validation? Are there known issues or recent changes on Apple's side that might cause the leaf certificate to not be recognized as part of a valid chain? Any guidance to resolve this certificate chain validation error would be greatly appreciated.
1
0
290
Mar ’25
testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase)
I am trying to test this simulated Error. The issue is, I can't get this to trigger through the simulatedError function. Error will always end up as an unknown error Example code snippet: @available(iOS 17.0, *) func testPurchase_InvalidQuantity() async throws { // Arrange testSession.clearTransactions() testSession.resetToDefaultState() let productID = "consumable_1" try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) guard let product = await fetchProduct(identifier: productID) else { XCTFail("Failed to fetch test product") return } let option = Product.PurchaseOption.quantity(4) let result = await manager.purchase(product: product, options: option) switch result { case .success: XCTFail("Expected failure due to invalid quantity") case .failure(let error): print("Received error: \(error.localizedDescription)") switch error { case .purchaseError(let purchaseError): XCTAssertEqual(purchaseError.code, StoreKitPurchaseError.invalidQuantity.code) default: XCTFail("Unexpected error: \(error)") } } } In the above code snippet, I have an Unexpected Error. But if i remove try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) I will receive a XCTFail in the success of my result. So when I set the quantity to a -1, only then can I correctly receive an invalidQuantity. Does anyone know why the try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) would fail to work as directed? I have tests for all the generic errors for loadProducts API and the simulatedError works great for them
1
0
335
Mar ’25
Local Storekit testing error
In developing a new MacOS app in Xcode I set up a Storekit configuration file so I could test 2 non-consumable purchases locally. I've been successfully testing them for the past couple of weeks, but suddenly yesterday I found I was unable to make purchases. I can successfully fetch products, but when I try to purchase either of them, I get the following error: Error handling payment sheet request: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service created from an endpoint was invalidated from this process." UserInfo= {NSDebugDescription=The connection to service created from an endpoint was invalidated from this process.} Purchase did not return a transaction: Error Domain=ASDErrorDomain Code=5115 "Received failure in response from Xcode" UserInfo= {NSDebugDescription=Received failure in response from Xcode, NSUnderlyingError=0x600002d44ae0 {Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service created from an endpoint was invalidated from this process." UserInfo= {AMSDescription=An unknown error occurred. Please try again., AMSURL=http://localhost:51482/WebObjects/MZBuy.woa/wa/inAppBuy, NSDebugDescription=The connection to service created from an endpoint was invalidated from this process., AMSStatusCode=200, AMSServerPayload={ "app-list" = ( ); dialog = { cancelButtonString = Cancel; defaultButton = Buy; explanation = "Do you want to buy one App Registration for $2.99?\n\n[Environment: Xcode]"; initialCheckboxValue = 1; "m-allowed" = 0; message = "Confirm Your In-App Purchase"; okButtonAction = { buyParams = "bid=com.airlinemates.backup&bvrs=1.4&offerName=EIBREG&quantity=1&deviceVerification=5084f98e-ab99-5846-827e-048d00d9fac3"; itemName = EIBREG; kind = Buy; }; okButtonString = Buy; paymentSheetInfo = { caseControl = true; confirmationTitle = Pay; countryCode = US; currency = USD; designVersion = 2; displayPrice = "$2.99"; flexList = ( { value = ( { style = priceMain; value = "$2.99"; }, { style = priceSub; value = "One-time charge"; } ); }, { header = "$null"; value = "For testing purposes only. You will not be charged for confirming this purchase."; } ); price = "2.99"; requestor = AppStore; salableIcon = "http://localhost:53078/StoreKit/AppIcon?bid=com.airlinemates.backup"; salableIconType = app; salableInfo = ( "App Registration %%image_0%%", backup, "In-App Purchase" ); styles = ( { bold = true; name = priceMain; size = large; }, { color = gray; name = priceSub; }, { bold = true; name = priceMainSpaceBefore; size = large; spacingBefore = medium; } ); title = { type = text; value = Xcode; }; }; }; "download-queue-item-count" = 0; dsid = 17322632127; failureType = 5115; jingleAction = inAppBuy; jingleDocType = inAppSuccess; pings = ( ); }}}} I've Googled & can't find any reference to this specific error, or even anything that points me in a direction to find the root cause. It's very strange because I haven't made any changes to the code & I hadn't changed the configuration file prior to this error appearing. I've since deleted the configuration file & created a new one - but it's still not working. If I create a transaction in Storekit transaction manager, the app picks it up as having been purchased - so the issue is only isolated to purchases initiated from the app. If I stop using the configuration file when I run the app, it works fine through sandbox testing the real items in App Store Connect.
4
2
546
Feb ’25
Verify Receipt is not found - After successful payment for Annual subscription.
The application is developed with Xamarin Framework and it is live now. The customer installed the app and purchased the annual subscription. And for some reason, they uninstall and reinstall the application on the same device. Now user wants to restore the subscription. In the application, there is an option to Restore the subscription. But restore API not return purchase details. But when clicking the subscription button instead of restoring the subscription, it says you subscribed to this plan". is there any possibility of not getting VerifyRecipt even after a successful purchase?
0
0
262
Feb ’25
Certificate is not temporally valid
I'm attempting to test an in app purchase for my app on my phone (not in a simulator, not sandbox testing). I'm getting an error that certificate check has failed. Could this have anything to do with the SHA-1 warnings that Apple has recently mentioned? I've tried regenerating my StoreKit file, cleaning the build, restarting XCode, resetting all of my devices purchases from the Debug > StoreKit menu, all with no luck. Any help would be greatly appreciated. 2025-01-10 19:52:19.974564-0500 MyApp[74478:30675548] [Default] Failed to verify certificate chain due to client recoverable failure: Error Domain=NSOSStatusErrorDomain Code=-67818 "“StoreKit Testing in Xcode” certificate is expired" UserInfo={NSLocalizedDescription=“StoreKit Testing in Xcode” certificate is expired, NSUnderlyingError=0x3027b9d40 {Error Domain=NSOSStatusErrorDomain Code=-67818 "Certificate 0 “StoreKit Testing in Xcode” has errors: Certificate is not temporally valid;" UserInfo={NSLocalizedDescription=Certificate 0 “StoreKit Testing in Xcode” has errors: Certificate is not temporally valid;}}} 2025-01-10 19:52:19.978233-0500 MyApp[74478:30675483] [Default] Failed to verify signature for Transaction, will assume invalid: failedToVerifyCertificateChain Purchase succeeded but verification failed: Certificate Chain Invalid Failed to purchase Premium: invalidCertificateChain saveUnencrypted: Started saving form_info.json saveUnencrypted: Saved form_info.json to Documents Directory in 9 ms (JSONEncoder chunk-based copy-on-write, 1 chunks) at ...
3
1
399
Feb ’25