Skip to content

feat: add subscription status APIs#522

Merged
hyochan merged 2 commits intomainfrom
feat/active-subscriptions
Aug 17, 2025
Merged

feat: add subscription status APIs#522
hyochan merged 2 commits intomainfrom
feat/active-subscriptions

Conversation

@hyochan
Copy link
Copy Markdown
Owner

@hyochan hyochan commented 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

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

// 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

@hyochan hyochan added the 🎯 feature New feature label Aug 17, 2025
@hyochan hyochan force-pushed the feat/active-subscriptions branch 2 times, most recently from fe14d4c to 86e37ff Compare August 17, 2025 15:03
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 17, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

- Implement OpenIAP compliant subscription status APIs
- Add ActiveSubscription model with platform-specific fields
- Rename IAPPlatform to IapPlatform for naming convention
- Fix type casting issues in extract utility functions
- Add iOS transactionState mapping in _convertToPurchase
- Handle both JSON string and decoded List in extractors
- Add comprehensive tests with proper mock handlers
- All tests passing locally
@hyochan hyochan force-pushed the feat/active-subscriptions branch from 86e37ff to b6bce71 Compare August 17, 2025 15:09
@hyochan hyochan merged commit e92746e into main Aug 17, 2025
3 checks passed
@hyochan hyochan deleted the feat/active-subscriptions branch August 17, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎯 feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant