Compare commits

...

1 commit

Author SHA1 Message Date
vishnukvmd c5d6291f2d Redirect to payment portal if subscription is past due 2024-03-27 15:41:26 +05:30
2 changed files with 16 additions and 3 deletions

View file

@ -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;
}

View file

@ -81,6 +81,11 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
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<StripeSubscriptionPage> {
singleBorderRadius: 4,
alignCaptionedTextToLeft: true,
onTap: () async {
_onStripSupportedPaymentDetailsTap();
_redirectToPaymentPortal();
},
),
),
@ -295,9 +300,9 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
);
}
// _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: