Check for updates to subscription if it is locally expired
This commit is contained in:
parent
74bb2ce0c4
commit
2223c4103e
1 changed files with 21 additions and 1 deletions
|
@ -45,6 +45,9 @@ class BillingService {
|
|||
}
|
||||
}
|
||||
});
|
||||
if (_config.hasConfiguredAccount() && !hasActiveSubscription()) {
|
||||
fetchSubscription();
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<BillingPlan>> getBillingPlans() {
|
||||
|
@ -86,7 +89,24 @@ class BillingService {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Fetch new subscription once the current one has expired?
|
||||
Future<Subscription> fetchSubscription() async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_config.getHttpEndpoint() + "/billing/subscription",
|
||||
options: Options(
|
||||
headers: {
|
||||
"X-Auth-Token": _config.getToken(),
|
||||
},
|
||||
),
|
||||
);
|
||||
final subscription = Subscription.fromMap(response.data["subscription"]);
|
||||
await setSubscription(subscription);
|
||||
return subscription;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Subscription getSubscription() {
|
||||
final jsonValue = _prefs.getString(subscriptionKey);
|
||||
if (jsonValue == null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue