In-App Purchases in Flutter with the Official in_app_purchase Plugin
in_app_purchase 3.3.1 without middleware: StoreKit 2 and Play Billing backends, purchaseStream lifecycle, completePurchase deadlines, subscription upgrades, and sandbox testing.
Published on • November 12, 2026
AI Assistant

Our RevenueCat and StoreKit 2 post covers the middleware route: one SDK, entitlements, paywalls, webhooks. This post is the other path, the official in_app_purchase plugin, where you talk to StoreKit and Play Billing directly, keep your own verification server, and accept more plumbing in exchange for no third-party dependency on your revenue stream.
The package and what sits behind it
dependencies:
in_app_purchase: ^3.3.1
in_app_purchase 3.3.1 (BSD-3-Clause, published September 2026) is a federated plugin with endorsed implementations: in_app_purchase_android 0.5.5 wraps Google’s BillingClient APIs, in_app_purchase_storekit 0.4.0 wraps StoreKit, and in_app_purchase_platform_interface 1.4.0 defines the contract. Support floors are Android SDK 24, iOS 13.0 and macOS 10.15. Two setup notes from the readme: do not add com.android.billingclient:billing to your own Gradle file (conflicts are likely, the plugin brings its own), and on iOS and macOS the generic API uses StoreKit 2 by default, with InAppPurchaseStoreKitPlatform.enableStoreKit1() as an opt-out you must call before the platform registers.
Subscribe first, buy second
Purchase updates arrive on a single stream that carries both storefronts, and you must be listening before you trigger any flow:
late final StreamSubscription<List<PurchaseDetails>> _sub;
@override
void initState() {
super.initState();
_sub = InAppPurchase.instance.purchaseStream.listen(
_handlePurchases,
onError: (Object e) => debugPrint('purchase stream error: $e'),
);
}
@override
void dispose() {
_sub.cancel();
super.dispose();
}
The reason is in the docs: purchases made in a previous session can be redelivered on the next launch, so a listener attached late simply never sees them.
Query, buy, and the three-day clock
final response = await InAppPurchase.instance.queryProductDetails(
{'coins_100', 'pro_monthly'},
);
final purchaseParam = PurchaseParam(productDetails: productDetails);
if (isConsumable) {
await InAppPurchase.instance.buyConsumable(purchaseParam: purchaseParam);
} else {
await InAppPurchase.instance.buyNonConsumable(purchaseParam: purchaseParam);
}
After verifying the receipt and delivering the goods, you must call completePurchase(). The deadline is not cosmetic: on Android, an uncompleted purchase is refunded after three days; on iOS, unfinished transactions stay in Apple’s queue, get redelivered on every launch, and make the next attempt at the same product ID fail with a duplicate-transaction error. Handle the stream statuses in order: pending shows the store spinner, error surfaces purchase.error, purchased and restored go through verification before unlocking, and pendingCompletePurchase triggers the completion call.
Restoring, and what cannot be restored
restorePurchases() re-emits non-consumables and subscriptions through the same stream, and both stores require a visible restore mechanism (Apple’s guideline 3.1.1 is explicit about it). The gap to plan for: the App Store has no API for querying consumables, and Google Play drops consumed products from ownership, so coin balances and other consumable state must live on your own server and be re-fetched at login.
Subscription upgrades, price consent, and offers
Google Play needs to be told which subscription is being replaced:
final param = GooglePlayPurchaseParam(
productDetails: productDetails,
changeSubscriptionParam: ChangeSubscriptionParam(
oldPurchaseDetails: oldPurchase,
replacementMode: ReplacementMode.withTimeProration,
),
);
await InAppPurchase.instance.buyNonConsumable(param);
The App Store has no equivalent call because subscriptions belong to subscription groups configured in App Store Connect. StoreKit 2 adds Sk2PurchaseParam for win-back offer identifiers, and price changes get their own consent dialog: an SKPaymentQueueDelegateWrapper with shouldShowPriceConsent() == false suppresses the default popup so you can present it after an explanation, then showPriceConsentIfNeeded() triggers it yourself. Offer codes on iOS 14+ use presentCodeRedemptionSheet() from the same platform addition.
Reaching into platform specifics
The generic ProductDetails and PurchaseDetails classes cover most apps, but subtypes expose the raw store objects when you need them: GooglePlayProductDetails carries subscriptionIndex and subscriptionOfferDetails (the pricing phases behind intro offers), AppStoreProductDetails exposes skProduct.subscriptionGroupIdentifier, and the StoreKit 2 variants (AppStoreProduct2Details, SK2Transaction) expose subscriptionGroupID and jsonRepresentation. On the purchase side, GooglePlayPurchaseDetails.billingClientPurchase.originalJson and the iOS transaction wrappers are what you forward to your backend.
Verification belongs on your server
Google’s billing overview is unambiguous: integrate with your own backend using the Play Developer API, because client-side checks are spoofable. That means verifying the Play purchase token server-side and subscribing to real-time developer notifications (Cloud Pub/Sub) for renewals, cancellations and refunds. On Apple, validate receipts against the App Store, move to the App Store Server API and App Store Server Notifications for status changes outside the app, and keep currentEntitlements in mind for users who reinstall. Your unlock logic should trust these server responses, never the client stream alone.
Testing without spending money
Apple supports the full loop before release: StoreKit Testing in Xcode with local product configuration, the sandbox environment once products exist in App Store Connect, and TestFlight (which runs purchases against sandbox, free to testers, with up to 10,000 external testers). Google Play uses license testers and the internal testing track for the same purpose. One Android extra worth knowing: in_app_purchase_android exposes Alternative and UserChoice billing, gated behind Play Console configuration, isAlternativeBillingOnlyAvailable(), showAlternativeBillingOnlyInformationDialog() and setBillingChoice(), for regions where Play requires offering an alternative payment processor.
Takeaway: Use in_app_purchase 3.3.1 when you want the official StoreKit 2 and Play Billing paths with no middleware: attach the purchaseStream listener before any purchase, always call completePurchase() within three days, persist consumable state on your server, verify tokens and receipts backend-side with the Play Developer API and App Store Server API, and test through sandbox, license testers and TestFlight before launch.