diff --git a/mobile/lib/models/subscription.dart b/mobile/lib/models/subscription.dart index 477942421..62ad27888 100644 --- a/mobile/lib/models/subscription.dart +++ b/mobile/lib/models/subscription.dart @@ -30,6 +30,14 @@ class Subscription { return expiryTime > DateTime.now().microsecondsSinceEpoch; } + bool isPastDue() { + return expiryTime < DateTime.now().microsecondsSinceEpoch && + expiryTime >= + DateTime.now() + .subtract(const Duration(days: 30)) + .microsecondsSinceEpoch; + } + bool isYearlyPlan() { return 'year' == period; } diff --git a/mobile/lib/ui/payment/stripe_subscription_page.dart b/mobile/lib/ui/payment/stripe_subscription_page.dart index a36ad1151..8306c3c18 100644 --- a/mobile/lib/ui/payment/stripe_subscription_page.dart +++ b/mobile/lib/ui/payment/stripe_subscription_page.dart @@ -81,6 +81,11 @@ class _StripeSubscriptionPageState extends State { userDetails.hasPaidAddon(); _hasActiveSubscription = _currentSubscription!.isValid(); _isStripeSubscriber = _currentSubscription!.paymentProvider == stripe; + + if (_isStripeSubscriber && _currentSubscription!.isPastDue()) { + _redirectToPaymentPortal(); + } + return _filterStripeForUI().then((value) { _hasLoadedData = true; setState(() {}); @@ -254,7 +259,7 @@ class _StripeSubscriptionPageState extends State { singleBorderRadius: 4, alignCaptionedTextToLeft: true, onTap: () async { - _onStripSupportedPaymentDetailsTap(); + _redirectToPaymentPortal(); }, ), ), @@ -295,9 +300,9 @@ class _StripeSubscriptionPageState extends State { ); } - // _onStripSupportedPaymentDetailsTap action allows the user to update + // _redirectToPaymentPortal action allows the user to update // their stripe payment details - void _onStripSupportedPaymentDetailsTap() async { + void _redirectToPaymentPortal() async { final String paymentProvider = _currentSubscription!.paymentProvider; switch (_currentSubscription!.paymentProvider) { case stripe: