Back to blog

How to Test In-App Purchases and Subscriptions in Flutter on Android & iOS Sandboxes

Written by Kajal · Reviewed and published by Prasandeep

Published 8 min readTest Automation
How to Test In-App Purchases and Subscriptions in Flutter on Android & iOS Sandboxes

In-app purchases (IAP) and subscriptions fail in ways normal UI tests never catch. The button can look fine while the store never returns a product, the receipt never gets acknowledged, or a renewal silently expires access. Sandboxes exist so you can exercise the real billing state machines without charging a card.

This guide walks through Flutter testing on Google Play license testing and Apple StoreKit / Sandbox—what each platform actually requires, which Flutter APIs matter, and how renewals behave under accelerated time. For where mobile monetization sits in a wider test strategy, see Modern Test Pyramid 2026. For native OS surfaces around auth and WebViews, see Flutter Patrol: Permissions, WebViews, Biometrics.

What you are really testing

A purchase is not “tap Buy → show success toast.” It is a pipeline:

  1. Catalog — store returns product IDs, prices, periods.
  2. Transaction — OS billing sheet completes, fails, or stays pending.
  3. Delivery — your app (ideally your server) decides the user is entitled.
  4. Acknowledgement / finish — you tell the store the purchase is consumed so it does not refund or stick.
  5. Lifecycle — restore, renew, grace period, cancel, upgrade/downgrade.

Miss step 4 on Android and Google refunds. Miss early stream listening on either platform and a purchase that finishes after a kill never unlocks.

Product typeUser expectationWhat you must prove in sandbox
ConsumableBuy many times (coins)Can repurchase after consume; inventory updates
Non-consumableBuy once (remove ads)Locked after buy; restore works on new install
Auto-renewable subscriptionAccess while period activeRenew, cancel end-of-period, upgrade/downgrade

Prerequisites

You need:

  • A Flutter app with in_app_purchase (flutter pub add in_app_purchase)
  • Apple Developer + App Store Connect app with Paid Apps agreement signed
  • Google Play Console app with products created
  • Matching product IDs across stores when possible (simpler client code)
  • Real devices for final Android billing (emulators do not run real Play Billing)

Optional but recommended: a small backend that verifies purchase.verificationData before granting entitlement.

Android — Google Play license testing

Play does not use a separate “sandbox login” the way Apple does. It uses license testers: Gmail accounts that can buy with test cards and are never charged real money—if the app is installed from a Play test track as a signed build.

Setup (in order)

  1. Create and Activate products under Monetize → Products (one-time and subscriptions).
  2. Settings → License testing → add tester Gmail addresses. Propagation often takes 15–60 minutes (sometimes longer).
  3. Build a signed AAB: flutter build appbundle.
  4. Upload to Internal or Closed testing and publish the track.
  5. Testers open the opt-in link, accept, and install from Play Store—not a sideloaded debug APK.
  6. On a real device, sign into Play Store as that license tester. Run the purchase. The sheet should show a test purchase with cards like “always approves” / “always declines.”

Hard rules that break most first attempts

RuleWhy it matters
Signed build on a test trackSideloaded debug builds often never see real products
Device Play account = license testerNon-testers get real (or blocked) billing
Call completePurchase() when pendingCompletePurchaseWithout acknowledgement, Google auto-refunds (~3 minutes for license testers, ~3 days for real users)

Accelerated subscription renewals (license testers)

Listed periodRough test renewal
Weekly / monthly~5 minutes
3 months~10 minutes
6 months~15 minutes
Yearly~30 minutes

Test subscriptions renew at most about 6 times, then cancel. That is intentional: you can walk purchase → renew → expire in one session.

iOS — StoreKit config vs Sandbox accounts

Apple gives two complementary environments.

1. Local StoreKit configuration (fast iteration)

Create a .storekit file in Xcode and list local products. Works in Simulator and on device without App Store Connect for basic flows. Use this while wiring UI and purchaseStream handlers.

Limit: local config is not a full production receipt story. Use it for fast UI wiring, not release sign-off.

2. Sandbox testers (pre-release truth)

  1. App Store Connect → Users and Access → Sandbox → create testers (emails that are not already Apple IDs).
  2. On device: Settings → App Store → Sandbox Account (wording varies by iOS version). Sign in with the sandbox tester.
  3. Install via Xcode or TestFlight. Purchases prompt for the sandbox password. No real charge.
  4. Never use a sandbox account to sign into the real App Store / Media & Purchases. That permanently ruins the sandbox tester—create a new one.

TestFlight builds use the sandbox purchase environment. That is what you want before App Store review.

Accelerated renewals (Sandbox)

Renewal speed can be adjusted per sandbox account in App Store Connect. Typical defaults:

Listed periodRough sandbox renewal
1 week~3 minutes
1 month~5 minutes
1 year~1 hour

Sandbox subscriptions renew on the order of ~12 times, then stop—again so you can test the lifecycle quickly.

Flutter: the APIs that actually matter

Listen early—not only on the paywall

Purchases can complete while your paywall is disposed, or after process death. Attach purchaseStream at app start (root widget / bootstrap), not only inside a paywall State.

Dart
late final StreamSubscription<List<PurchaseDetails>> _subscription; void initState() { super.initState(); _subscription = InAppPurchase.instance.purchaseStream.listen( (purchases) { for (final purchase in purchases) { unawaited(_handlePurchase(purchase)); } }, onError: (Object error) { // Log store connection errors }, ); } void dispose() { _subscription.cancel(); super.dispose(); }

Start vs finish

buyConsumable / buyNonConsumable only start the OS sheet. Entitlement decisions belong in the stream handler.

Dart
Future<void> _handlePurchase(PurchaseDetails purchase) async { switch (purchase.status) { case PurchaseStatus.pending: // Show blocking loader; do not unlock yet return; case PurchaseStatus.error: // Surface purchase.error; do not unlock break; case PurchaseStatus.purchased: case PurchaseStatus.restored: // Prefer server verification before unlock // final ok = await verifyOnServer(purchase.verificationData); // if (!ok) break; await unlockEntitlement(purchase.productID); break; case PurchaseStatus.canceled: break; } if (purchase.pendingCompletePurchase) { await InAppPurchase.instance.completePurchase(purchase); } }

Why completePurchase is non-negotiable

PlatformIf you skip finish / acknowledge
AndroidAuto-refund; user paid (or test-paid) but you look broken
iOSTransaction can remain unfinished; next launches re-deliver or stick

Always finish when pendingCompletePurchase is true—even after you decide to deny unlock (still finish, then revoke on server if needed).

purchase.verificationData carries the store payload. Sending it to your backend before unlock closes a class of client-only cheat paths and makes restore / multi-device consistent. Client-only unlock is fine for demos; it is weak for real revenue.

Platform comparison (what QA should remember)

ConcernAndroid license testingiOS Sandbox / StoreKit
Account modelLicense tester Gmail on Play StoreDedicated Sandbox Apple ID
Install pathSigned AAB from test trackXcode / TestFlight
Emulator / SimulatorNo real Play BillingStoreKit config works in Simulator
Decline pathTest card “always declines”Cancel sheet / fail scenarios
Renewal speedFixed accelerated table (~6 renewals)Configurable; ~12 renewals
Biggest footgunMissing completePurchase → refundSandbox account used on real App Store

Common failures and fixes

SymptomLikely causeFix
Empty product listInactive product, wrong ID, track/account mismatchActivate products; wait for propagation; match IDs
No purchase sheet (Android)Emulator or sideloaded unsigned buildReal device + Play test-track install
Paid but feature lockedStream attached too late; unlock only on button callbackListen at startup; unlock in stream
Instant Android refundNever completed / acknowledgedcompletePurchase when pending
Sandbox login broken (iOS)Sandbox ID used on production App StoreNew sandbox tester
“Subscription never renews”Expecting wall-clock monthly timeUse accelerated sandbox periods

Release checklist

Run these on both platforms before you ship monetization:

  1. Fresh install → successful purchase → entitlement on
  2. Kill app mid-purchase → reopen → stream delivers → still complete
  3. Restore on new install / second device
  4. Declined / canceled payment → no unlock
  5. Subscription renew at least once under accelerated time
  6. Cancel → access ends at expected boundary
  7. Upgrade / downgrade if you sell multiple plans
  8. Consumable repurchase after consume
  9. Server reject path (invalid receipt) does not unlock

Faster path for early UI work

Services like RevenueCat (purchases_flutter) add entitlement abstractions and a Test Store so paywall UI can move before full Play/App Store wiring. That does not replace a final pass on real Play license testing and Apple Sandbox/TestFlight. Ship confidence still comes from the store environments your users hit.

Summary

Sandbox IAP testing is store-state testing, not button testing. On Android: license testers, signed test-track builds, and reliable acknowledgement. On iOS: StoreKit for speed, Sandbox/TestFlight for truth—without signing sandbox accounts into the production App Store.

In Flutter, attach purchaseStream early, unlock only after a trusted signal (preferably your server), and always completePurchase when asked. Run renewals, restores, declines, and process death under accelerated periods so you catch stuck unlocks, surprise refunds, and silent churn before users do.

ShareLinkedInPost on X

Get the next guide in your inbox

Weekly AI testing insights, templates, and tool notes — unsubscribe anytime.