feat: implement Open IAP subscription status APIs#158
Merged
Conversation
Implement standardized subscription management APIs as specified in OpenIAP spec (https://www.openiap.dev/docs/apis#getactivesubscriptions, https://www.openiap.dev/docs/apis#hasactivesubscriptions), providing getActiveSubscriptions() to retrieve detailed subscription information with platform-specific fields and hasActiveSubscriptions() for simple boolean checks, both supporting optional filtering by product IDs or automatic detection of all active subscriptions.
This comment was marked as resolved.
This comment was marked as resolved.
877f394 to
9a33322
Compare
- Changed expirationDate to expirationDateIOS (iOS only) - Changed autoRenewing to autoRenewingAndroid (Android only) - Changed environment to environmentIOS (iOS only) - Changed daysUntilExpiration to daysUntilExpirationIOS (iOS only) - Updated example app to use new field names - Added testing guidelines to CLAUDE.md
9a33322 to
a9f9dd0
Compare
- Updated PurchaseBase type: id now contains transaction ID, added productId field - Modified finishTransaction to use purchase.id instead of purchase.transactionId - Updated iOS native module to map transaction.id to "id" field - Updated Android native module to map purchase.orderId to "id" field - Deprecated transactionId field while maintaining backward compatibility - Eliminates need for workarounds when calling finishTransaction 🤖 Generated with [Claude Code](https://claude.ai/code)
hyochan
added a commit
to hyochan/flutter_inapp_purchase
that referenced
this pull request
Aug 17, 2025
This PR implements standardized subscription management APIs as specified in the OpenIAP specification, providing a unified way to check subscription status across iOS and Android platforms with automatic detection of all active subscriptions and platform-specific details like iOS expiration dates and Android auto-renewal status. ## OpenIAP Specification References - [getActiveSubscriptions](https://www.openiap.dev/docs/apis#getactivesubscriptions) - [hasActiveSubscriptions](https://www.openiap.dev/docs/apis#hasactivesubscriptions) - [ActiveSubscription Type](https://www.openiap.dev/docs/types#activesubscription) ## Changes ### New APIs - Add `getActiveSubscriptions()` to retrieve detailed subscription information - Returns list of `ActiveSubscription` objects with platform-specific fields - Supports optional filtering by subscription IDs - Automatically detects all active subscriptions when no filter provided - Add `hasActiveSubscriptions()` for simple boolean subscription checks - Returns `true` if user has any active subscriptions - Supports optional filtering by specific subscription IDs - Handles errors gracefully by returning `false` ### Type System - Add `ActiveSubscription` model with platform-specific fields: - **iOS**: `expirationDateIOS`, `environmentIOS`, `daysUntilExpirationIOS` - **Android**: `autoRenewingAndroid` - **Cross-platform**: `productId`, `isActive`, `willExpireSoon` (within 7 days) ### Code Quality - Rename `IAPPlatform` to `IapPlatform` following Dart naming conventions - Fix type casting issues in `extractPurchased` and `extractItems` utilities - Add proper iOS transaction state mapping in `_convertToPurchase` - Replace `getCurrentPlatform()` calls with instance-based platform detection ### Testing - Add comprehensive unit tests for both iOS and Android platforms - Test subscription filtering functionality - Verify platform-specific field population ## Usage Example ```dart // Get all active subscriptions final subscriptions = await FlutterInappPurchase.instance.getActiveSubscriptions(); // Check specific subscriptions final hasMonthly = await FlutterInappPurchase.instance.hasActiveSubscriptions( subscriptionIds: ['monthly_subscription', 'yearly_subscription'], ); // Access platform-specific information for (final sub in subscriptions) { if (Platform.isIOS && sub.daysUntilExpirationIOS != null) { print('Expires in ${sub.daysUntilExpirationIOS} days'); } if (Platform.isAndroid && sub.autoRenewingAndroid == true) { print('Auto-renewing subscription'); } } ``` ## Breaking Changes None - these are new additions to the API surface. ## Migration Notes - Developers using custom subscription checking logic can migrate to these standardized APIs - The deprecated `checkSubscribed()` method (removed in v6.0.0) can now be replaced with `hasActiveSubscriptions()` ## Related - OpenIAP Discussion: https://github.com/hyochan/openiap.dev/discussions - Reference Implementation: hyochan/expo-iap#158
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes Made
New OpenIAP Subscription Status APIs
getActiveSubscriptions()- Get all active subscriptions across platformsgetSubscriptionStatus(productId)- Get detailed status for specific subscriptionrefreshSubscriptionStatus()- Force refresh subscription data from storesfinishTransaction Bug Fix (#151)
finishTransactionexpectedpurchase.transactionIdbut iOS returnedpurchase.idas product IDpurchase.idcontains transaction ID (for finishTransaction) andpurchase.productIdcontains product identifierPurchaseBasetype:idfield now contains transaction ID, addedproductIdfield for product identificationfinishTransactionto usepurchase.idinstead ofpurchase.transactionIdidfieldtransactionIdfield while maintaining backward compatibilityfinishTransaction(purchase)directlyType System Improvements
PurchaseBasewith clear field separation:id(transaction) vsproductId(product)Test Plan
Breaking Changes
None - all changes are backward compatible. The
transactionIdfield is deprecated but still available.