subscription.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @dart=2.9
  2. const freeProductID = "free";
  3. const stripe = "stripe";
  4. const appStore = "appstore";
  5. const playStore = "playstore";
  6. class Subscription {
  7. final String productID;
  8. final int storage;
  9. final String originalTransactionID;
  10. final String paymentProvider;
  11. final int expiryTime;
  12. final String price;
  13. final String period;
  14. final Attributes attributes;
  15. Subscription({
  16. this.productID,
  17. this.storage,
  18. this.originalTransactionID,
  19. this.paymentProvider,
  20. this.expiryTime,
  21. this.price,
  22. this.period,
  23. this.attributes,
  24. });
  25. bool isValid() {
  26. return expiryTime > DateTime.now().microsecondsSinceEpoch;
  27. }
  28. bool isYearlyPlan() {
  29. return 'year' == period;
  30. }
  31. factory Subscription.fromMap(Map<String, dynamic> map) {
  32. if (map == null) {
  33. throw ArgumentError("argument is null");
  34. }
  35. return Subscription(
  36. productID: map['productID'],
  37. storage: map['storage'],
  38. originalTransactionID: map['originalTransactionID'],
  39. paymentProvider: map['paymentProvider'],
  40. expiryTime: map['expiryTime'],
  41. price: map['price'],
  42. period: map['period'],
  43. attributes: map["attributes"] != null
  44. ? Attributes.fromJson(map["attributes"])
  45. : null,
  46. );
  47. }
  48. }
  49. class Attributes {
  50. bool isCancelled;
  51. String customerID;
  52. Attributes({
  53. this.isCancelled,
  54. this.customerID,
  55. });
  56. Attributes.fromJson(dynamic json) {
  57. isCancelled = json["isCancelled"];
  58. customerID = json["customerID"];
  59. }
  60. }