Skip to content

Commit 86e37ff

Browse files
committed
feat: add getActiveSubscriptions and hasActiveSubscriptions methods
- 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
1 parent a2d947e commit 86e37ff

File tree

5 files changed

+521
-69
lines changed

5 files changed

+521
-69
lines changed

lib/enums.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
enum Store { none, playStore, amazon, appStore }
55

66
/// Platform detection enum
7-
enum IAPPlatform { ios, android }
7+
enum IapPlatform { ios, android }
88

99
/// Purchase type enum
1010
enum PurchaseType { inapp, subs }

lib/errors.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'dart:io';
44
import 'enums.dart';
55

66
/// Get current platform
7-
IAPPlatform getCurrentPlatform() {
7+
IapPlatform getCurrentPlatform() {
88
if (Platform.isIOS) {
9-
return IAPPlatform.ios;
9+
return IapPlatform.ios;
1010
} else if (Platform.isAndroid) {
11-
return IAPPlatform.android;
11+
return IapPlatform.android;
1212
}
1313
throw UnsupportedError('Platform not supported');
1414
}
@@ -89,7 +89,7 @@ class PurchaseError implements Exception {
8989
final String? debugMessage;
9090
final ErrorCode? code;
9191
final String? productId;
92-
final IAPPlatform? platform;
92+
final IapPlatform? platform;
9393

9494
PurchaseError({
9595
String? name,
@@ -104,7 +104,7 @@ class PurchaseError implements Exception {
104104
/// Creates a PurchaseError from platform-specific error data
105105
factory PurchaseError.fromPlatformError(
106106
Map<String, dynamic> errorData,
107-
IAPPlatform platform,
107+
IapPlatform platform,
108108
) {
109109
final errorCode = errorData['code'] != null
110110
? ErrorCodeUtils.fromPlatformCode(errorData['code'], platform)
@@ -175,9 +175,9 @@ class ErrorCodeUtils {
175175
/// Maps a platform-specific error code back to the standardized ErrorCode enum
176176
static ErrorCode fromPlatformCode(
177177
dynamic platformCode,
178-
IAPPlatform platform,
178+
IapPlatform platform,
179179
) {
180-
if (platform == IAPPlatform.ios) {
180+
if (platform == IapPlatform.ios) {
181181
final mapping = ErrorCodeMapping.ios;
182182
for (final entry in mapping.entries) {
183183
if (entry.value == platformCode) {
@@ -196,17 +196,17 @@ class ErrorCodeUtils {
196196
}
197197

198198
/// Maps an ErrorCode enum to platform-specific code
199-
static dynamic toPlatformCode(ErrorCode errorCode, IAPPlatform platform) {
200-
if (platform == IAPPlatform.ios) {
199+
static dynamic toPlatformCode(ErrorCode errorCode, IapPlatform platform) {
200+
if (platform == IapPlatform.ios) {
201201
return ErrorCodeMapping.ios[errorCode] ?? 0;
202202
} else {
203203
return ErrorCodeMapping.android[errorCode] ?? 'E_UNKNOWN';
204204
}
205205
}
206206

207207
/// Checks if an error code is valid for the specified platform
208-
static bool isValidForPlatform(ErrorCode errorCode, IAPPlatform platform) {
209-
if (platform == IAPPlatform.ios) {
208+
static bool isValidForPlatform(ErrorCode errorCode, IapPlatform platform) {
209+
if (platform == IapPlatform.ios) {
210210
return ErrorCodeMapping.ios.containsKey(errorCode);
211211
} else {
212212
return ErrorCodeMapping.android.containsKey(errorCode);

0 commit comments

Comments
 (0)