diff --git a/lib/models/subscription.dart b/lib/models/subscription.dart index 64a498ab9..1878b3f48 100644 --- a/lib/models/subscription.dart +++ b/lib/models/subscription.dart @@ -3,7 +3,7 @@ import 'dart:convert'; class Subscription { final int id; final String productID; - final int storageInMBs; + final int storage; final String originalTransactionID; final String paymentProvider; final int expiryTime; @@ -11,7 +11,7 @@ class Subscription { Subscription({ this.id, this.productID, - this.storageInMBs, + this.storage, this.originalTransactionID, this.paymentProvider, this.expiryTime, @@ -24,7 +24,7 @@ class Subscription { Subscription copyWith({ int id, int productID, - int storageInMBs, + int storage, int originalTransactionID, int paymentProvider, int expiryTime, @@ -32,7 +32,7 @@ class Subscription { return Subscription( id: id ?? this.id, productID: productID ?? this.productID, - storageInMBs: storageInMBs ?? this.storageInMBs, + storage: storage ?? this.storage, originalTransactionID: originalTransactionID ?? this.originalTransactionID, paymentProvider: paymentProvider ?? this.paymentProvider, @@ -44,7 +44,7 @@ class Subscription { return { 'id': id, 'productID': productID, - 'storageInMBs': storageInMBs, + 'storage': storage, 'originalTransactionID': originalTransactionID, 'paymentProvider': paymentProvider, 'expiryTime': expiryTime, @@ -57,7 +57,7 @@ class Subscription { return Subscription( id: map['id'], productID: map['productID'], - storageInMBs: map['storageInMBs'], + storage: map['storage'], originalTransactionID: map['originalTransactionID'], paymentProvider: map['paymentProvider'], expiryTime: map['expiryTime'], @@ -71,7 +71,7 @@ class Subscription { @override String toString() { - return 'Subscription(id: $id, productID: $productID, storageInMBs: $storageInMBs, originalTransactionID: $originalTransactionID, paymentProvider: $paymentProvider, expiryTime: $expiryTime)'; + return 'Subscription(id: $id, productID: $productID, storage: $storage, originalTransactionID: $originalTransactionID, paymentProvider: $paymentProvider, expiryTime: $expiryTime)'; } @override @@ -81,7 +81,7 @@ class Subscription { return o is Subscription && o.id == id && o.productID == productID && - o.storageInMBs == storageInMBs && + o.storage == storage && o.originalTransactionID == originalTransactionID && o.paymentProvider == paymentProvider && o.expiryTime == expiryTime; @@ -91,7 +91,7 @@ class Subscription { int get hashCode { return id.hashCode ^ productID.hashCode ^ - storageInMBs.hashCode ^ + storage.hashCode ^ originalTransactionID.hashCode ^ paymentProvider.hashCode ^ expiryTime.hashCode; diff --git a/lib/services/billing_service.dart b/lib/services/billing_service.dart index 070a30698..32229b296 100644 --- a/lib/services/billing_service.dart +++ b/lib/services/billing_service.dart @@ -108,7 +108,10 @@ class BillingService { final subscription = Subscription.fromMap(response.data["subscription"]); await setSubscription(subscription); return subscription; - } catch (e) { + } on DioError catch (e) { + if (e.response.statusCode == 404) { + _prefs.remove(subscriptionKey); + } throw e; } } diff --git a/lib/ui/sign_in_header_widget.dart b/lib/ui/sign_in_header_widget.dart index 877790ce9..97b2b7476 100644 --- a/lib/ui/sign_in_header_widget.dart +++ b/lib/ui/sign_in_header_widget.dart @@ -49,7 +49,7 @@ class _SignInHeaderState extends State { return FutureBuilder( future: BillingService.instance.fetchSubscription(), builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData) { + if (snapshot.hasData || snapshot.hasError) { if (BillingService.instance.hasActiveSubscription()) { return Container(); } diff --git a/lib/ui/subscription_page.dart b/lib/ui/subscription_page.dart index 4671bfd44..442c4cd8c 100644 --- a/lib/ui/subscription_page.dart +++ b/lib/ui/subscription_page.dart @@ -52,12 +52,10 @@ class _SubscriptionPageState extends State { Bus.instance.fire(UserAuthenticatedEvent()); final isUpgrade = _currentSubscription != null && _currentSubscription.isValid() && - newSubscription.storageInMBs > - _currentSubscription.storageInMBs; + newSubscription.storage > _currentSubscription.storage; final isDowngrade = _currentSubscription != null && _currentSubscription.isValid() && - newSubscription.storageInMBs < - _currentSubscription.storageInMBs; + newSubscription.storage < _currentSubscription.storage; String text = "your photos and videos will now be backed up"; if (isUpgrade) { text = "your plan was successfully upgraded";