Redirect to payment portal if subscription is past due
This commit is contained in:
parent
25a054287a
commit
c5d6291f2d
|
@ -30,6 +30,14 @@ class Subscription {
|
||||||
return expiryTime > DateTime.now().microsecondsSinceEpoch;
|
return expiryTime > DateTime.now().microsecondsSinceEpoch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPastDue() {
|
||||||
|
return expiryTime < DateTime.now().microsecondsSinceEpoch &&
|
||||||
|
expiryTime >=
|
||||||
|
DateTime.now()
|
||||||
|
.subtract(const Duration(days: 30))
|
||||||
|
.microsecondsSinceEpoch;
|
||||||
|
}
|
||||||
|
|
||||||
bool isYearlyPlan() {
|
bool isYearlyPlan() {
|
||||||
return 'year' == period;
|
return 'year' == period;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,11 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
|
||||||
userDetails.hasPaidAddon();
|
userDetails.hasPaidAddon();
|
||||||
_hasActiveSubscription = _currentSubscription!.isValid();
|
_hasActiveSubscription = _currentSubscription!.isValid();
|
||||||
_isStripeSubscriber = _currentSubscription!.paymentProvider == stripe;
|
_isStripeSubscriber = _currentSubscription!.paymentProvider == stripe;
|
||||||
|
|
||||||
|
if (_isStripeSubscriber && _currentSubscription!.isPastDue()) {
|
||||||
|
_redirectToPaymentPortal();
|
||||||
|
}
|
||||||
|
|
||||||
return _filterStripeForUI().then((value) {
|
return _filterStripeForUI().then((value) {
|
||||||
_hasLoadedData = true;
|
_hasLoadedData = true;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
@ -254,7 +259,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {
|
||||||
singleBorderRadius: 4,
|
singleBorderRadius: 4,
|
||||||
alignCaptionedTextToLeft: true,
|
alignCaptionedTextToLeft: true,
|
||||||
onTap: () async {
|
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
|
// their stripe payment details
|
||||||
void _onStripSupportedPaymentDetailsTap() async {
|
void _redirectToPaymentPortal() async {
|
||||||
final String paymentProvider = _currentSubscription!.paymentProvider;
|
final String paymentProvider = _currentSubscription!.paymentProvider;
|
||||||
switch (_currentSubscription!.paymentProvider) {
|
switch (_currentSubscription!.paymentProvider) {
|
||||||
case stripe:
|
case stripe:
|
||||||
|
|
Loading…
Reference in a new issue