forked from RevenueCat/purchases-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_wrapper.dart
87 lines (71 loc) · 2.49 KB
/
package_wrapper.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:purchases_flutter/object_wrappers.dart';
/// Contains information about the product available for the user to purchase.
/// For more info see https://docs.revenuecat.com/docs/entitlements
class Package {
/// Unique identifier for this package. Can be one a predefined package type
/// or a custom one.
final String identifier;
/// Package type for the product. Will be one of [PackageType].
final PackageType packageType;
/// Product assigned to this package.
final Product product;
/// Offering this package belongs to.
final String offeringIdentifier;
/// Constructs a Package from a JSON object.
Package.fromJson(Map<dynamic, dynamic> json)
: identifier = json['identifier'],
packageType = _PackageTypeHelper.getFromString(json['packageType']),
product = Product.fromJson(json['product']),
offeringIdentifier = json['offeringIdentifier'];
@override
String toString() {
return 'Package{identifier: $identifier, packageType: $packageType, product: $product, offeringIdentifier: $offeringIdentifier}';
}
}
/// Enumeration of all possible Package types.
enum PackageType {
/// A package that was defined with a custom identifier.
unknown,
/// A package that was defined with a custom identifier.
custom,
/// A package configured with the predefined lifetime identifier.
lifetime,
/// A package configured with the predefined annual identifier.
annual,
/// A package configured with the predefined six month identifier.
sixMonth,
/// A package configured with the predefined three month identifier.
threeMonth,
/// A package configured with the predefined two month identifier.
twoMonth,
/// A package configured with the predefined monthly identifier.
monthly,
/// A package configured with the predefined weekly identifier.
weekly
}
class _PackageTypeHelper {
static PackageType getFromString(String name) {
switch (name) {
case "UNKNOWN":
return PackageType.unknown;
case "CUSTOM":
return PackageType.custom;
case "LIFETIME":
return PackageType.lifetime;
case "ANNUAL":
return PackageType.annual;
case "SIX_MONTH":
return PackageType.sixMonth;
case "THREE_MONTH":
return PackageType.threeMonth;
case "TWO_MONTH":
return PackageType.twoMonth;
case "MONTHLY":
return PackageType.monthly;
case "WEEKLY":
return PackageType.weekly;
default:
return PackageType.unknown;
}
}
}