Flutter In-App Purchase With StoreKit 2

· 5 min read

If you sell anything inside an iOS app, you use Apple’s In-App Purchase system, and in 2026 that means StoreKit 2. The good news for Flutter developers: the official in_app_purchase plugin already uses it. The package says: “On iOS and macOS, the generic API uses StoreKit 2 by default.”

This guide covers what StoreKit 2 changes, how the Dart purchase flow works, and the mistakes that cause stuck or refunded purchases. It is part of our guide to building a Flutter app with Claude Code.

What StoreKit 2 changes

Apple’s StoreKit page lists the main differences from the original StoreKit:

  • Signed transactions. “In StoreKit 2, transactions are cryptographically signed by the App Store in JSON Web Signature format for increased security and easier parsing of transaction information.”
  • Transactions follow the user. StoreKit 2 “automatically makes up-to-date transactions available to your app, whether someone launches it for the first time or downloads it on another device.”
  • Same data on device and server. “StoreKit 2 APIs return the same information as the App Store Server API.”

For a Flutter app, you do not call these Swift APIs directly. The plugin’s StoreKit implementation (in_app_purchase_storekit) wraps them, and you work with the cross-platform InAppPurchase API. If you hit an issue that only StoreKit 1 avoids, you can opt out:

InAppPurchaseStoreKitPlatform.enableStoreKit1();

Call it before the platform is registered, and treat it as a temporary workaround.

Before writing code

Apple’s sandbox docs list what must be in place before purchases work at all:

  • an active Apple Developer Program account,
  • the Paid Applications Agreement signed by the Account Holder,
  • products set up in App Store Connect with at least “a product reference name, product ID, a localized name, and a price.”

You also need the In-App Purchase capability enabled for the app in Xcode. Decide your product types first: consumables (coins), non-consumables (lifetime access) or auto-renewable subscriptions. Apple’s rules on what must use in-app purchase are in our post on guideline 3.1.1.

Step 1: listen to the purchase stream early

Purchases arrive on a stream, not as a return value. That includes purchases from a previous session that never finished. The package is clear: “You should always start listening to purchase update as early as possible.”

late final StreamSubscription<List<PurchaseDetails>> _sub;

void initPurchases() {
  _sub = InAppPurchase.instance.purchaseStream.listen(
    _onPurchases,
    onError: (Object e) => log('purchase stream error: $e'),
  );
}

Start this in your app’s startup code, not on the paywall screen. If the listener only exists while the paywall is open, a purchase that completes after the user leaves is lost until the next launch.

Step 2: load products

const ids = <String>{'pro_monthly', 'pro_yearly', 'lifetime'};
final response = await InAppPurchase.instance.queryProductDetails(ids);
if (response.notFoundIDs.isNotEmpty) {
  // IDs not configured in App Store Connect, or not ready yet.
}
final products = response.productDetails;

Always show prices from ProductDetails, never hardcoded strings. The store returns the localized price for the user’s storefront.

Step 3: buy

final param = PurchaseParam(productDetails: product);
if (isConsumable(product)) {
  await InAppPurchase.instance.buyConsumable(purchaseParam: param);
} else {
  await InAppPurchase.instance.buyNonConsumable(purchaseParam: param);
}

The package’s subscription example uses buyNonConsumable as well. The call starts the flow. The result arrives later on the purchase stream.

Step 4: handle every status, then complete

PurchaseStatus has five values: pending, purchased, restored, error and canceled. Handle them all:

Future<void> _onPurchases(List<PurchaseDetails> list) async {
  for (final p in list) {
    switch (p.status) {
      case PurchaseStatus.pending:
        showPending();
      case PurchaseStatus.purchased:
      case PurchaseStatus.restored:
        final valid = await verify(p.verificationData);
        if (valid) await grantAccess(p.productID);
      case PurchaseStatus.error:
        showError(p.error);
      case PurchaseStatus.canceled:
        resetButtons();
    }
    if (p.pendingCompletePurchase) {
      await InAppPurchase.instance.completePurchase(p);
    }
  }
}

The pendingCompletePurchase flag matters. The package docs say you must call completePurchase when it is true, after the product has been delivered. If you skip it:

  • On iOS and macOS, unfinished transactions are redelivered on every launch and block new purchases of the same product ID.
  • On Android, purchases not completed within three days are refunded.

Step 5: restore purchases

People who reinstall or switch devices need a way to get non-consumables and subscriptions back, so give them a Restore button. In the plugin:

await InAppPurchase.instance.restorePurchases();

Restored purchases arrive on the same stream with status restored. One limit the package notes: the App Store has no API for querying consumables, so restoring coin balances across devices needs your own server.

Verification: on device or on a server

The plugin asks you to “validate restored purchases following the best practices for each underlying store.” With StoreKit 2, the signed transaction is self-contained, and the App Store Server API returns the same information to your backend. Your options, from simplest to strongest:

  1. Trust the device for a low-price, offline app. Fast to ship, easy to bypass.
  2. Verify on your server by sending verificationData to a backend that checks it with Apple. Required if access is tied to an account across devices.
  3. Use a subscription service such as RevenueCat, which handles verification and gives you entitlements. See Flutter RevenueCat paywall.

For subscription apps, option 2 or 3 is the norm, because renewals, refunds and expirations happen while the app is closed. The App Store Server API also helps with support cases such as “extending the renewal date of a subscription.”

Common pitfalls

  • Products return empty. Usually the Paid Applications Agreement is not active, the product IDs do not match, or metadata is still propagating. Apple notes product changes “can take up to one hour to appear in the sandbox environment.”
  • Listener started late. Purchases arrive with nobody listening.
  • No completePurchase. Stuck transactions on iOS, refunds on Android.
  • Hardcoded prices. Wrong currency outside your own country.

Testing is a topic of its own, with Xcode StoreKit configuration files, sandbox accounts and Play license testers. See how to test in-app purchases in Flutter. For what to sell and how to price it, see how to make a subscription app and mobile app paywall design.

MobileKit’s build skills include a purchase checklist that covers the stream, completion and restore steps above, since those are the parts that most often break in review.

Sources read on the day this post was written: in_app_purchase on pub.dev, in_app_purchase_storekit on pub.dev, PurchaseStatus API reference, PurchaseDetails API reference, Apple StoreKit, RevenueCat: Flutter installation and Apple: testing in-app purchases with sandbox.

Questions

Does the Flutter in_app_purchase plugin use StoreKit 2?

Yes. The package says that on iOS and macOS the generic API uses StoreKit 2 by default. You can fall back to StoreKit 1 by calling InAppPurchaseStoreKitPlatform.enableStoreKit1() before registering the platform.

What happens if I never call completePurchase?

On iOS and macOS, unfinished transactions are redelivered on every launch and block new purchases of the same product ID. On Android, purchases that are not completed within three days are refunded.

Do I need a server to verify purchases?

The plugin tells you to validate purchases following each store's best practices. StoreKit 2 transactions are signed by the App Store in JSON Web Signature format, and the App Store Server API returns the same transaction information for server-side checks.

Try it on your next idea

One payment, every update to this major version, and a refund window if it is not for you. Refund policy.