diff --git a/lib/services/billing_service.dart b/lib/services/billing_service.dart index 4e22a2bf0..e6a3ea9ef 100644 --- a/lib/services/billing_service.dart +++ b/lib/services/billing_service.dart @@ -45,6 +45,9 @@ class BillingService { } } }); + if (_config.hasConfiguredAccount() && !hasActiveSubscription()) { + fetchSubscription(); + } } Future> getBillingPlans() { @@ -86,7 +89,24 @@ class BillingService { } } - // TODO: Fetch new subscription once the current one has expired? + Future 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) {