ente/lib/models/subscription.dart

100 lines
2.3 KiB
Dart
Raw Normal View History

2022-12-27 11:35:15 +00:00
import 'dart:convert';
const freeProductID = "free";
const stripe = "stripe";
const appStore = "appstore";
const playStore = "playstore";
2021-02-25 14:59:54 +00:00
class Subscription {
2021-01-29 11:07:58 +00:00
final String productID;
2021-02-01 10:38:07 +00:00
final int storage;
2021-01-29 11:07:58 +00:00
final String originalTransactionID;
final String paymentProvider;
2021-01-18 17:02:44 +00:00
final int expiryTime;
final String price;
final String period;
final Attributes? attributes;
Subscription({
required this.productID,
required this.storage,
required this.originalTransactionID,
required this.paymentProvider,
required this.expiryTime,
required this.price,
required this.period,
this.attributes,
});
bool isValid() {
return expiryTime > DateTime.now().microsecondsSinceEpoch;
}
bool isYearlyPlan() {
return 'year' == period;
}
static fromMap(Map<String, dynamic>? map) {
if (map == null) return null;
return Subscription(
2021-01-29 11:07:58 +00:00
productID: map['productID'],
2021-02-01 10:38:07 +00:00
storage: map['storage'],
2021-01-29 11:07:58 +00:00
originalTransactionID: map['originalTransactionID'],
paymentProvider: map['paymentProvider'],
2021-01-18 17:02:44 +00:00
expiryTime: map['expiryTime'],
price: map['price'],
period: map['period'],
attributes: map["attributes"] != null
2022-12-27 11:43:00 +00:00
? Attributes.fromMap(map["attributes"])
: null,
);
}
2022-12-27 11:35:15 +00:00
Map<String, dynamic> toMap() {
return {
'productID': productID,
'storage': storage,
'originalTransactionID': originalTransactionID,
'paymentProvider': paymentProvider,
'expiryTime': expiryTime,
'price': price,
'period': period,
'attributes': attributes?.toMap(),
};
}
String toJson() => json.encode(toMap());
2022-12-27 11:43:00 +00:00
factory Subscription.fromJson(String source) =>
Subscription.fromMap(json.decode(source));
}
class Attributes {
bool? isCancelled;
String? customerID;
Attributes({
this.isCancelled,
2022-06-11 08:23:52 +00:00
this.customerID,
});
2022-12-27 11:35:15 +00:00
Map<String, dynamic> toMap() {
return {
'isCancelled': isCancelled,
'customerID': customerID,
};
}
2022-12-27 11:35:15 +00:00
factory Attributes.fromMap(Map<String, dynamic> map) {
return Attributes(
isCancelled: map['isCancelled'],
customerID: map['customerID'],
);
}
String toJson() => json.encode(toMap());
2022-12-27 11:43:00 +00:00
factory Attributes.fromJson(String source) =>
Attributes.fromMap(json.decode(source));
2022-06-11 08:23:52 +00:00
}