Skip to content

Commit

Permalink
Merge 146cb14 into 4268721
Browse files Browse the repository at this point in the history
  • Loading branch information
vintage committed Nov 16, 2020
2 parents 4268721 + 146cb14 commit 7f8ce7a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/modules.dart
Expand Up @@ -213,7 +213,7 @@ class PurchasedItem {
final String signatureAndroid;
final bool autoRenewingAndroid;
final bool isAcknowledgedAndroid;
final int purchaseStateAndroid;
final PurchaseState purchaseStateAndroid;
final String originalJsonAndroid;

// iOS only
Expand All @@ -234,7 +234,8 @@ class PurchasedItem {
signatureAndroid = json['signatureAndroid'] as String,
isAcknowledgedAndroid = json['isAcknowledgedAndroid'] as bool,
autoRenewingAndroid = json['autoRenewingAndroid'] as bool,
purchaseStateAndroid = json['purchaseStateAndroid'] as int,
purchaseStateAndroid =
_decodePurchaseStateAndroid(json['purchaseStateAndroid'] as int),
originalJsonAndroid = json['originalJsonAndroid'] as String,

originalTransactionDateIOS =
Expand Down Expand Up @@ -367,3 +368,25 @@ TransactionState _decodeTransactionStateIOS(int rawValue) {
return null;
}
}

/// See also https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState
enum PurchaseState {
pending,

purchased,

unspecified,
}

PurchaseState _decodePurchaseStateAndroid(int rawValue) {
switch (rawValue) {
case 0:
return PurchaseState.unspecified;
case 1:
return PurchaseState.purchased;
case 2:
return PurchaseState.pending;
default:
return null;
}
}

0 comments on commit 7f8ce7a

Please sign in to comment.