MockEasyIap class

Mock EasyIap for testing.

Simulates in-app purchase behavior without connecting to real stores.

final mockIap = MockEasyIap(
  products: [
    IapProduct.subscription('pro_monthly'),
  ],
);

// Simulate successful purchase
mockIap.mockPurchaseSuccess('pro_monthly');

// Or simulate failure
mockIap.mockPurchaseFailure('pro_monthly', 'payment_declined');

Constructors

MockEasyIap({required List<IapProduct> products, Map<String, MockProductDetails> mockProductDetails = const {}, Duration delay = const Duration(milliseconds: 500), bool isStoreAvailable = true})

Properties

activeSubscriptions List<IapReceipt>
List of active subscription receipts.
no setter
delay Duration
Delay for simulating network latency.
final
hasActiveSubscription bool
Whether user has any active subscription.
no setter
hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Whether MockEasyIap is initialized.
no setter
isStoreAvailable bool
Whether the mock store is available.
getter/setter pair
mockProductDetails Map<String, MockProductDetails>
Simulated product details (prices, etc.).
final
ownedProductIds Set<String>
Set of owned product IDs.
no setter
ownershipStream Stream<Set<String>>
Stream of ownership changes.
no setter
products List<IapProduct>
List of configured products.
final
purchaseStream Stream<IapReceipt>
Stream of purchase events.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addSubscription(String productId, {DateTime? expiresAt}) → void
Add an active subscription (for test setup).
dispose() → void
Dispose resources.
hasSubscription(String productId) bool
Check if user has a specific subscription.
initialize({bool autoRestore = true}) Future<void>
Initialize mock.
isOwned(String productId) bool
Check if a product is owned.
mockPurchaseCancelled(String productId) → void
Mock a cancelled purchase for a product.
mockPurchaseFailure(String productId, String errorCode) → void
Mock a failed purchase for a product.
mockPurchaseSuccess(String productId) → void
Mock a successful purchase for a product.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
purchase(String productId) Future<IapResult>
Simulate a purchase.
reset() → void
Clear all mock data.
restore() Future<List<IapReceipt>>
Simulate restore.
setOwned(Set<String> productIds) → void
Set owned products (for test setup).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited