|
@@ -2,17 +2,25 @@ import 'package:logging/logging.dart';
|
|
|
import 'package:photos/core/configuration.dart';
|
|
|
import 'package:photos/core/network.dart';
|
|
|
import 'package:photos/models/billing_plan.dart';
|
|
|
+import 'package:photos/models/subscription.dart';
|
|
|
+import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
class BillingService {
|
|
|
BillingService._privateConstructor() {}
|
|
|
|
|
|
static final BillingService instance = BillingService._privateConstructor();
|
|
|
+ static const subscriptionKey = "subscription";
|
|
|
|
|
|
final _logger = Logger("BillingService");
|
|
|
final _dio = Network.instance.getDio();
|
|
|
|
|
|
+ SharedPreferences _prefs;
|
|
|
Future<List<BillingPlan>> _future;
|
|
|
|
|
|
+ Future<void> init() async {
|
|
|
+ _prefs = await SharedPreferences.getInstance();
|
|
|
+ }
|
|
|
+
|
|
|
Future<List<BillingPlan>> getBillingPlans() {
|
|
|
if (_future == null) {
|
|
|
_future = _dio
|
|
@@ -27,4 +35,18 @@ class BillingService {
|
|
|
}
|
|
|
return _future;
|
|
|
}
|
|
|
+
|
|
|
+ Subscription getSubscription() {
|
|
|
+ final jsonValue = _prefs.getString(subscriptionKey);
|
|
|
+ if (jsonValue == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return Subscription.fromJson(jsonValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> setSubscription(Subscription subscription) async {
|
|
|
+ await _prefs.setString(
|
|
|
+ subscriptionKey, subscription == null ? null : subscription.toJson());
|
|
|
+ }
|
|
|
}
|