StoreKit 2 and in-app purchases with AI agents: purchase code, StoreKit testing and server verification
Let the agent write StoreKit 2 code against a local StoreKit configuration file, so purchases, renewals and refunds run in Xcode without App Store servers. Lock the flows in with SKTestSession unit tests, listen to Transaction.updates at launch, and verify App Store Server Notifications V2 signatures on your server before granting access.
Last updated:
This page is about getting a coding agent (Claude Code, Cursor, Codex, or the agents inside Xcode) to write in-app purchase code with StoreKit 2, test it without real money, and verify purchases on your server. For connecting an agent to App Store Connect itself, see App Store Connect MCP servers. Every App Store tool in the catalog is listed under App Store. StoreKit is for digital in-app goods. Apple Pay through PassKit is for real-world goods, services and donations; see Apple Pay with AI agents. An Apple Music subscription through MusicKit is not a StoreKit product; see MusicKit with AI agents.
What the agent has to get right in StoreKit 2
Four APIs carry most purchase logic. From Apple's reference:
Transaction.currentEntitlements(iOS 15+) emits the latest transaction for each product the customer is entitled to: each non-consumable, each auto-renewable subscription in thesubscribedorinGracePeriodstate, and each non-renewing subscription. Refunded or revoked products don't appear, and neither do consumables; for unfinished consumables, useTransaction.unfinishedorTransaction.all.Transaction.updates(iOS 15+) emits transactions created outside the app or on other devices: Ask to Buy, offer code redemptions, App Store purchases. Apple's advice: create aTaskthat iterates it as soon as the app launches; unfinished transactions arrive there once, right after launch, and "without the Task to listen for these transactions, your app may miss them".VerificationResult: StoreKit verifiesTransaction,RenewalInfoandAppTransactionautomatically; your code checks whether each value is verified or unverified. Apple also warns that the decoded JWS payload givespricein milliunits of the currency while StoreKit gives it in units.Transaction.finish()tells the App Store that the app delivered the content or enabled the service.
For subscriptions, SubscriptionStoreView (iOS 17+) shows localized names, descriptions, prices and a purchase button for a subscription group, and adds buttons for the terms of service and privacy policy you submitted in App Store Connect.
Rules worth adding to AGENTS.md or CLAUDE.md:
In-app purchases: start one
Taskat launch that iteratesTransaction.updates. Unlock content only for.verifiedresults, callfinish()after delivery, and derive access fromTransaction.currentEntitlements, never from a stored flag. Never treat a missing expiration date as "subscribed".
Step 1: a StoreKit configuration file the agent can work against
Apple's "Setting up StoreKit Testing in Xcode": StoreKit Testing in Xcode is "a local test environment for testing in-app purchases without requiring a connection to App Store servers". Create the file with File > New > File from Template > StoreKit Configuration File. There are two kinds:
Local: you enter products by hand. Names, IDs, prices and localizations "don't upload to App Store Connect"; the price is "a placeholder value that's not connected to price tiers or real pricing information".
Synced (Xcode 14 and later): pulled from your in-app purchases in App Store Connect; you can't edit some product types in it unless you convert it with Editor > Convert to Local StoreKit Configuration.
Activate it under Edit Scheme > Run > Options > StoreKit Configuration. A project can hold several files but only one is active. On a device, Apple notes that Developer Mode is needed on iOS 16 and later. Locally signed receipts need the test certificate (Editor > Save Public Certificate); Apple's page shows an #if DEBUG switch between the test certificate and the Apple root certificate.
Apple lists what this is good for: building features before they're configured in App Store Connect, testing offline, debugging cases that are hard to set up in the sandbox (such as promotional offer eligibility), checking localized product data in the payment sheet, and testing failed transactions end to end.
Step 2: StoreKitTest so the agent can't break purchases quietly
The StoreKitTest framework "makes StoreKit testing in Xcode available for automation". Apple: each SKTestSession instance "gives you access to the same settings you manually change for StoreKit testing in Xcode":
swift
import StoreKitTest
import XCTest
final class EntitlementTests: XCTestCase {
func testExpiredSubscriptionRemovesAccess() async throws {
let session = try SKTestSession(configurationFileNamed: "Products")
session.disableDialogs = true
session.clearTransactions()
// purchase through the app's own purchase code here, then:
try session.expireSubscription(productIdentifier: "com.example.pro.monthly")
// assert that the app's entitlement check now returns false
}
}Other scenarios from Apple's topic list: refundTransaction(identifier:), forceRenewalOfSubscription(productIdentifier:), timeRate for faster renewals, askToBuyEnabled with approveAskToBuyTransaction(identifier:), interruptedPurchasesEnabled, billingGracePeriodIsEnabled, shouldEnterBillingRetryOnRenewal, and price-increase consent. Two cautions from the reference: all SKTestSession instances control the same single test environment, so run these tests serially; and buyProduct(productIdentifier:) and failTransactionsEnabled are marked deprecated. The page lists buyProduct(identifier:options:) and setSimulatedError(_:forAPI:) without a description, so check their declarations in Xcode before the agent relies on them.
Step 3: verify purchases on your server
On the device StoreKit verifies for you; Apple suggests verifying the JWS yourself on your server "for the most control and security", for example with the App Store Server Library's verifyAndDecodeTransaction, verifyAndDecodeAppTransaction and verifyAndDecodeRenewalInfo.
App Store Server Notifications V2 arrive as a signedPayload (JWS). Apple's steps: decode the payload to get the notification type and data, then decode signedTransactionInfo and, depending on the type, signedRenewalInfo; all three carry a signature to validate on your server. StoreKit Verify MCP (table below) gives an agent tools for exactly this check.
The App Store Server API is a REST API your server calls for transaction history, subscription status (Get All Subscription Statuses), refund history, order ID lookup and renewal date extensions. Get Notification History requests notifications your server may have missed in the past 180 days (30 in the sandbox), and Request a Test Notification checks that your endpoint receives them. Every endpoint except order lookup is available in the sandbox at https://api.storekit-sandbox.apple.com/. In the live catalog, Heimdall is the MCP server whose README covers this API.
Step 4: products, prices and a pre-flight before review
Products and subscriptions still have to exist in App Store Connect: Heimdall (profiles for subscriptions, in-app purchases and pricing) or the App Store Connect MCP by yuraist (creates, localizes and prices in-app purchases and offers) can do that from the agent; the comparison of ASC servers lives in App Store Connect MCP servers. For prices per country, two skills set purchasing-power prices (table below); both show the prices before they write them. Before submitting, kit-storekit-check and App Store Review Risk scan the project for StoreKit mistakes. Paywall design and pricing strategy: App Paywall Pilot.
StoreKit and in-app purchase tools for agents compared
| Tool / skill | What it does (from README) | Agents | Install (from README) | License | ★ (27 Oct) | Last push |
|---|---|---|---|---|---|---|
| App Paywall Pilot (Nikolai-Iakubovskii) | Skill and knowledge base for App Store-compliant subscription paywalls on iOS and Android: paywall audits, pricing and trial modules, StoreKit 2 and RevenueCat/Adapty implementation notes, unit-economics calculator | Claude Code, Codex, Cursor | git clone https://github.com/Nikolai-Iakubovskii/app-paywall-pilot ~/.claude/skills/app-paywall-pilot | MIT | 39 | 7 Oct 2026 |
| Heimdall (erayendes) | MCP server for the App Store Connect API and the App Store Server API (StoreKit 2), generated from Apple's OpenAPI specification; 929 tools in 13 profiles | any MCP client | npx -y @erayendes/asc-mcp setup | MIT | 53 | 26 Oct 2026 |
| StoreKit Verify MCP (tranzen21) | MCP server and CLI that verifies App Store Server Notifications V2: ES256 signatures of the payload and nested JWS, x5c chain to a pinned Apple Root CA - G3, Apple's policy OIDs; tools verify_notification, decode_notification, decode_transaction, explain_notification_type | Claude Code, any MCP client | claude mcp add storekit-verify -- npx -y github:tranzen21/storekit-verify-mcp | MIT | 0 | 21 Jul 2026 ⚠ |
| kit-storekit-check (sdvsignal) | /kit-storekit-check:run: six offline checks on project files (bundled .storekit file, ?? .distantFuture expiry, product IDs in .storekit vs Swift, local-only intro offers, encryption key, prices in metadata text) | Claude Code, Cursor | /plugin marketplace add sdvsignal/kit-plugins, /plugin install kit-storekit-check@kit-plugins | MIT | 0 | 22 Sep 2026 ⚠ |
| App Store Review Risk (Kofiloski) | Skill plus local static scanner (CLI, GitHub Action) for likely rejection risks with file evidence: privacy, entitlements, StoreKit flows, subscriptions, restore paths, external purchase language, account deletion | Codex | npx skills add https://github.com/Kofiloski/app-store-review-risk --skill app-store-review-risk | MIT | 0 | 15 Jul 2026 ⚠ |
| App Store Connect MCP (yuraist) | MCP server and CLI for the App Store Connect API: 60 named tools plus all 1303 operations through validated read/write calls with dry-run; in-app purchases, subscription groups, territory prices, introductory and promotional offers | Claude Code, Codex, any MCP client | git clone https://github.com/yuraist/appstoreconnect-mcp.git, cd appstoreconnect-mcp, npm install, npm run build, then claude mcp add appstoreconnect -- node /absolute/path/to/appstoreconnect-mcp/build/index.js | MIT | 1 | 25 Oct 2026 |
| App Store PPP Prices (duceum) | CLI with agent instructions for Claude Code, Cursor and Codex that bulk-updates in-app purchase and subscription prices per territory by purchasing power, using real Apple price points; --dry-run first | Claude Code, Codex, Cursor | uv tool install appstore-ppp-prices (skill files are copied by hand) | MIT | 52 | 22 Aug 2026 ⚠ |
| setup-iap (0xohzsh) | Regional prices in five tiers for App Store in-app purchases (subscriptions, consumables, non-consumables) and Google Play subscriptions; keeps the US price, shows a table before writing via the asc CLI | Claude Code | /plugin marketplace add 0xohzsh/setup-iap-skill, /plugin install setup-iap@setup-iap-skill | MIT | 0 | 3 Oct 2026 |
⚠ = no push for more than 4 weeks. Five of the six new tools have 0 or 1 star; treat them as young projects and read their output before acting on it. None of the tools writes your StoreKit 2 purchase code for you without review, and none predicts App Review's decision.
Which one to pick:
Your agent should design or audit a paywall: App Paywall Pilot.
Catch StoreKit mistakes in the project before submission: kit-storekit-check for the six specific checks, App Store Review Risk for a broader scan with file evidence.
Your server handles subscription webhooks: StoreKit Verify MCP to verify and explain notifications; Heimdall when the agent also needs the App Store Server API.
Create products, subscriptions and offers in App Store Connect: Heimdall, or the App Store Connect MCP by yuraist; more options in App Store Connect MCP servers.
Set prices by country: App Store PPP Prices for the App Store only, setup-iap if you also sell on Google Play.
A prompt that keeps the agent honest
Setting up the agent itself: Claude Code for iOS development, Codex for iOS development or Cursor rules for SwiftUI.
Add a monthly and a yearly subscription to
Features/Paywallwith StoreKit 2. Use the local StoreKit configuration fileProducts.storekit; don't touch App Store Connect. Start aTransaction.updateslistener at launch, unlock only verified transactions, and derive access fromTransaction.currentEntitlements. Then write StoreKitTest tests withSKTestSessionfor purchase, renewal, expiry, refund and Ask to Buy, and run them serially. List anything you couldn't test locally, such as server notifications, instead of calling it done.
FAQ
- Can an AI agent test in-app purchases before they exist in App Store Connect?
- Yes. Apple's StoreKit Testing in Xcode is a local test environment that needs no connection to App Store servers. A local StoreKit configuration file holds your products, subscription groups and offers; once it is selected in the scheme's Run options, the app gets StoreKit data from the test environment. Prices in a local file are placeholders and never upload to App Store Connect.
- How does an agent automate StoreKit tests?
- With the StoreKitTest framework. Create an SKTestSession from your StoreKit configuration file, set disableDialogs to true, and use methods such as expireSubscription(productIdentifier:), refundTransaction(identifier:) or forceRenewalOfSubscription(productIdentifier:) to put the test environment into the state you want. Apple notes that all SKTestSession instances control the same environment, so run these tests serially.
- Does my code have to verify StoreKit 2 transactions itself?
- On the device, StoreKit already verifies Transaction, RenewalInfo and AppTransaction values and wraps them in a VerificationResult; your code checks whether each value is verified or unverified before it unlocks anything. For the most control, Apple suggests verifying the JWS on your server, for example with the App Store Server Library's verifyAndDecodeTransaction.
- How do I verify App Store Server Notifications V2?
- Apple sends a signedPayload in JWS format. Decode it to get the notification type and data, then decode the nested signedTransactionInfo and, depending on the type, signedRenewalInfo; each of the three has a signature to validate on your server. StoreKit Verify MCP (new in the catalog) lets an agent run this check, including the certificate chain to Apple's root.
- Which tool catches StoreKit mistakes before App Review?
- kit-storekit-check runs six offline checks on project files, for example a .storekit file bundled in Copy Bundle Resources or a nil expiry date treated as subscribed forever. App Store Review Risk scans a repository or pull request more broadly, including StoreKit flows, restore paths and external purchase language. Both report candidates for review; neither predicts App Review's decision.