How to Test In-App Purchases and Subscriptions in Flutter on Android & iOS Sandboxes
Written by Kajal · Reviewed and published by Prasandeep

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:
- Catalog — store returns product IDs, prices, periods.
- Transaction — OS billing sheet completes, fails, or stays pending.
- Delivery — your app (ideally your server) decides the user is entitled.
- Acknowledgement / finish — you tell the store the purchase is consumed so it does not refund or stick.
- 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 type | User expectation | What you must prove in sandbox |
|---|---|---|
| Consumable | Buy many times (coins) | Can repurchase after consume; inventory updates |
| Non-consumable | Buy once (remove ads) | Locked after buy; restore works on new install |
| Auto-renewable subscription | Access while period active | Renew, 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)
- Create and Activate products under Monetize → Products (one-time and subscriptions).
- Settings → License testing → add tester Gmail addresses. Propagation often takes 15–60 minutes (sometimes longer).
- Build a signed AAB:
flutter build appbundle. - Upload to Internal or Closed testing and publish the track.
- Testers open the opt-in link, accept, and install from Play Store—not a sideloaded debug APK.
- 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
| Rule | Why it matters |
|---|---|
| Signed build on a test track | Sideloaded debug builds often never see real products |
| Device Play account = license tester | Non-testers get real (or blocked) billing |
Call completePurchase() when pendingCompletePurchase | Without acknowledgement, Google auto-refunds (~3 minutes for license testers, ~3 days for real users) |
Accelerated subscription renewals (license testers)
| Listed period | Rough 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)
- App Store Connect → Users and Access → Sandbox → create testers (emails that are not already Apple IDs).
- On device: Settings → App Store → Sandbox Account (wording varies by iOS version). Sign in with the sandbox tester.
- Install via Xcode or TestFlight. Purchases prompt for the sandbox password. No real charge.
- 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 period | Rough 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.
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.
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
| Platform | If you skip finish / acknowledge |
|---|---|
| Android | Auto-refund; user paid (or test-paid) but you look broken |
| iOS | Transaction 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).
Server verification (recommended)
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)
| Concern | Android license testing | iOS Sandbox / StoreKit |
|---|---|---|
| Account model | License tester Gmail on Play Store | Dedicated Sandbox Apple ID |
| Install path | Signed AAB from test track | Xcode / TestFlight |
| Emulator / Simulator | No real Play Billing | StoreKit config works in Simulator |
| Decline path | Test card “always declines” | Cancel sheet / fail scenarios |
| Renewal speed | Fixed accelerated table (~6 renewals) | Configurable; ~12 renewals |
| Biggest footgun | Missing completePurchase → refund | Sandbox account used on real App Store |
Common failures and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Empty product list | Inactive product, wrong ID, track/account mismatch | Activate products; wait for propagation; match IDs |
| No purchase sheet (Android) | Emulator or sideloaded unsigned build | Real device + Play test-track install |
| Paid but feature locked | Stream attached too late; unlock only on button callback | Listen at startup; unlock in stream |
| Instant Android refund | Never completed / acknowledged | completePurchase when pending |
| Sandbox login broken (iOS) | Sandbox ID used on production App Store | New sandbox tester |
| “Subscription never renews” | Expecting wall-clock monthly time | Use accelerated sandbox periods |
Release checklist
Run these on both platforms before you ship monetization:
- Fresh install → successful purchase → entitlement on
- Kill app mid-purchase → reopen → stream delivers → still complete
- Restore on new install / second device
- Declined / canceled payment → no unlock
- Subscription renew at least once under accelerated time
- Cancel → access ends at expected boundary
- Upgrade / downgrade if you sell multiple plans
- Consumable repurchase after consume
- 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.
Get the next guide in your inbox
Weekly AI testing insights, templates, and tool notes — unsubscribe anytime.