subscription.dart 1.5 KB

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