subscription.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 int id;
  8. final String productID;
  9. final int storage;
  10. final String originalTransactionID;
  11. final String paymentProvider;
  12. final int expiryTime;
  13. final String price;
  14. final String period;
  15. final Attributes attributes;
  16. Subscription({
  17. this.id,
  18. this.productID,
  19. this.storage,
  20. this.originalTransactionID,
  21. this.paymentProvider,
  22. this.expiryTime,
  23. this.price,
  24. this.period,
  25. this.attributes,
  26. });
  27. bool isValid() {
  28. return expiryTime > DateTime.now().microsecondsSinceEpoch;
  29. }
  30. bool isYearlyPlan() {
  31. return 'year' == period;
  32. }
  33. factory Subscription.fromMap(Map<String, dynamic> map) {
  34. if (map == null) {
  35. throw ArgumentError("argument is null");
  36. }
  37. return Subscription(
  38. id: map['id'],
  39. productID: map['productID'],
  40. storage: map['storage'],
  41. originalTransactionID: map['originalTransactionID'],
  42. paymentProvider: map['paymentProvider'],
  43. expiryTime: map['expiryTime'],
  44. price: map['price'],
  45. period: map['period'],
  46. attributes: map["attributes"] != null
  47. ? Attributes.fromJson(map["attributes"])
  48. : null,
  49. );
  50. }
  51. }
  52. class Attributes {
  53. bool isCancelled;
  54. String customerID;
  55. Attributes({
  56. this.isCancelled,
  57. this.customerID,
  58. });
  59. Attributes.fromJson(dynamic json) {
  60. isCancelled = json["isCancelled"];
  61. customerID = json["customerID"];
  62. }
  63. }