Skip to main content

Types

Comprehensive type definitions for flutter_inapp_purchase v6.0.0. All types are fully documented with TypeScript-style definitions for complete type safety.

Core Types

RequestPurchase

Platform-specific purchase request configuration.

class RequestPurchase {
final RequestPurchaseIOS? ios;
final RequestPurchaseAndroid? android;

RequestPurchase({
this.ios,
this.android,
});
}

RequestPurchaseIOS

iOS-specific purchase parameters.

class RequestPurchaseIOS {
final String sku; // Product SKU
final bool? andDangerouslyFinishTransactionAutomaticallyIOS; // Auto-finish transaction
final String? appAccountToken; // App account token
final int? quantity; // Purchase quantity
final PaymentDiscount? withOffer; // Promotional offer

RequestPurchaseIOS({
required this.sku,
this.andDangerouslyFinishTransactionAutomaticallyIOS,
this.appAccountToken,
this.quantity,
this.withOffer,
});
}

RequestPurchaseAndroid

Android-specific purchase parameters.

class RequestPurchaseAndroid {
final List<String> skus; // Product SKUs
final String? obfuscatedAccountIdAndroid; // Account ID
final String? obfuscatedProfileIdAndroid; // Profile ID
final bool? isOfferPersonalized; // Personalized offer
final String? purchaseToken; // Existing purchase token
final int? offerTokenIndex; // Offer token index
final int? prorationMode; // Proration mode

RequestPurchaseAndroid({
required this.skus,
this.obfuscatedAccountIdAndroid,
this.obfuscatedProfileIdAndroid,
this.isOfferPersonalized,
this.purchaseToken,
this.offerTokenIndex,
this.prorationMode,
});
}

RequestProductsParams

Parameters for loading product information.

class RequestProductsParams {
final List<String> skus; // Product SKUs to load
final PurchaseType type; // Product type (inapp/subs)

RequestProductsParams({
required this.skus,
required this.type,
});
}

Product Types

IAPItem

Represents a product available for purchase.

class IAPItem {
final String? productId; // Product identifier
final String? price; // Price as string
final String? currency; // Currency code
final String? localizedPrice; // Localized price string
final String? title; // Product title
final String? description; // Product description
final String? introductoryPrice; // Intro price

// iOS-specific fields
final String? subscriptionPeriodNumberIOS; // Subscription period number
final String? subscriptionPeriodUnitIOS; // Subscription period unit
final String? introductoryPriceNumberIOS; // Intro price number
final String? introductoryPricePaymentModeIOS; // Intro payment mode
final String? introductoryPriceNumberOfPeriodsIOS; // Intro periods count
final String? introductoryPriceSubscriptionPeriodIOS; // Intro period
final List<DiscountIOS>? discountsIOS; // Available discounts

// Android-specific fields
final String? signatureAndroid; // Purchase signature
final List<SubscriptionOfferAndroid>? subscriptionOffersAndroid; // Subscription offers
final String? subscriptionPeriodAndroid; // Subscription period

final String? iconUrl; // Product icon URL
final String? originalJson; // Original platform JSON
final String originalPrice; // Original price
}

DiscountIOS

iOS promotional discount information.

class DiscountIOS {
final String? identifier; // Discount identifier
final String? type; // Discount type
final String? numberOfPeriods; // Number of periods
final double? price; // Discount price
final String? localizedPrice; // Localized price
final String? paymentMode; // Payment mode
final String? subscriptionPeriod; // Subscription period

DiscountIOS({
this.identifier,
this.type,
this.numberOfPeriods,
this.price,
this.localizedPrice,
this.paymentMode,
this.subscriptionPeriod,
});
}

SubscriptionOfferAndroid

Android subscription offer details.

class SubscriptionOfferAndroid {
final String sku; // Product SKU
final String offerToken; // Offer token
final String? offerId; // Offer ID
final String? basePlanId; // Base plan ID
final List<PricingPhaseAndroid>? pricingPhases; // Pricing phases

SubscriptionOfferAndroid({
required this.sku,
required this.offerToken,
this.offerId,
this.basePlanId,
this.pricingPhases,
});
}

Purchase Types

PurchasedItem

Represents a completed purchase.

class PurchasedItem {
final String? productId; // Product identifier
final String? transactionId; // Transaction ID
final DateTime? transactionDate; // Transaction date
final String? transactionReceipt; // Transaction receipt
final String? purchaseToken; // Purchase token

// Android-specific fields
final String? dataAndroid; // Purchase data
final String? signatureAndroid; // Purchase signature
final bool? autoRenewingAndroid; // Auto-renewing status
final bool? isAcknowledgedAndroid; // Acknowledgment status
final PurchaseState? purchaseStateAndroid; // Purchase state

// iOS-specific fields
final DateTime? originalTransactionDateIOS; // Original transaction date
final String? originalTransactionIdentifierIOS; // Original transaction ID
final TransactionState? transactionStateIOS; // Transaction state
}

PurchaseError

Detailed error information for failed purchases.

class PurchaseError implements Exception {
final String name; // Error name
final String message; // Error message
final int? responseCode; // Platform response code
final String? debugMessage; // Debug information
final ErrorCode? code; // Standardized error code
final String? productId; // Related product ID
final IAPPlatform? platform; // Platform where error occurred

PurchaseError({
String? name,
required this.message,
this.responseCode,
this.debugMessage,
this.code,
this.productId,
this.platform,
});
}

PurchaseResult

Legacy purchase result structure (deprecated in favor of PurchaseError).

class PurchaseResult {
final int? responseCode; // Response code
final String? debugMessage; // Debug message
final String? code; // Error code
final String? message; // Error message
final String? purchaseTokenAndroid; // Android purchase token

PurchaseResult({
this.responseCode,
this.debugMessage,
this.code,
this.message,
this.purchaseTokenAndroid,
});
}

Enums

PurchaseType

Product purchase types.

enum PurchaseType { 
inapp, // One-time purchases
subs // Subscriptions
}

ErrorCode

Standardized error codes across platforms.

enum ErrorCode {
eUnknown, // Unknown error
eUserCancelled, // User cancelled
eUserError, // User error
eItemUnavailable, // Item unavailable
eRemoteError, // Remote server error
eNetworkError, // Network error
eServiceError, // Service error
eReceiptFailed, // Receipt validation failed
eReceiptFinishedFailed, // Receipt finish failed
eNotPrepared, // Not prepared
eNotEnded, // Not ended
eAlreadyOwned, // Already owned
eDeveloperError, // Developer error
eBillingResponseJsonParseError, // JSON parse error
eDeferredPayment, // Deferred payment
eInterrupted, // Interrupted
eIapNotAvailable, // IAP not available
ePurchaseError, // Purchase error
eSyncError, // Sync error
eTransactionValidationFailed, // Transaction validation failed
eActivityUnavailable, // Activity unavailable
eAlreadyPrepared, // Already prepared
ePending, // Pending
eConnectionClosed, // Connection closed
// Additional error codes...
}

IAPPlatform

Platform enumeration.

enum IAPPlatform { 
ios, // iOS platform
android // Android platform
}

TransactionState

iOS transaction states.

enum TransactionState {
purchasing, // Transaction in progress
purchased, // Transaction completed
failed, // Transaction failed
restored, // Transaction restored
deferred // Transaction deferred
}

PurchaseState

Android purchase states.

enum PurchaseState {
pending, // Purchase pending
purchased, // Purchase completed
unspecified // Unspecified state
}

Platform-Specific Types

PaymentDiscount (iOS)

iOS promotional offer configuration.

class PaymentDiscount {
final String identifier; // Offer identifier
final String keyIdentifier; // Key identifier
final String nonce; // Nonce value
final String signature; // Signature
final int timestamp; // Timestamp

PaymentDiscount({
required this.identifier,
required this.keyIdentifier,
required this.nonce,
required this.signature,
required this.timestamp,
});
}

PricingPhaseAndroid

Android subscription pricing phase.

class PricingPhaseAndroid {
String? price; // Price
String? formattedPrice; // Formatted price
String? billingPeriod; // Billing period
String? currencyCode; // Currency code
int? recurrenceMode; // Recurrence mode
int? billingCycleCount; // Billing cycle count
}

Utility Types

ConnectionResult

Connection establishment result.

class ConnectionResult {
final bool connected; // Connection status
final String? message; // Connection message

ConnectionResult({
required this.connected,
this.message,
});
}

IAPConfig

IAP configuration options.

class IAPConfig {
final bool autoFinishTransactions; // Auto-finish transactions
final bool enablePendingPurchases; // Enable pending purchases
final Duration? connectionTimeout; // Connection timeout
final bool validateReceipts; // Validate receipts

const IAPConfig({
this.autoFinishTransactions = true,
this.enablePendingPurchases = true,
this.connectionTimeout,
this.validateReceipts = false,
});
}

Type Guards

Utility functions for type checking.

// Check if props use platform-specific format
bool isPlatformRequestProps(dynamic props);

// Check if props use unified format
bool isUnifiedRequestProps(dynamic props);

// Get current platform
IAPPlatform getCurrentPlatform();

Platform Differences

Key Type Differences

FeatureiOSAndroid
Product IDsSingle sku stringArray of skus
Purchase TokentransactionReceiptpurchaseToken
Transaction StateTransactionState enumPurchaseState enum
Error HandlingInteger codesString codes
DiscountsDiscountIOS objectsSubscriptionOfferAndroid

Platform-Specific Fields

iOS Only:

  • originalTransactionIdentifierIOS
  • transactionStateIOS
  • discountsIOS
  • subscriptionPeriodUnitIOS

Android Only:

  • purchaseToken
  • dataAndroid
  • signatureAndroid
  • isAcknowledgedAndroid
  • purchaseStateAndroid

Migration Notes

⚠️ Breaking Changes from v5.x:

  1. Request Objects: Now use RequestPurchase instead of string parameters
  2. Error Types: PurchaseError replaces legacy error handling
  3. Type Safety: All optional fields are properly nullable
  4. Platform Separation: Clear distinction between iOS and Android types

See Also