From 1020366c3a881e77f89078e1f4045944e4cf2bc1 Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Wed, 27 Mar 2024 16:11:03 +0530 Subject: [PATCH] [mobile][web] Ignore cancelled subscriptions while computing past-due status --- mobile/lib/models/subscription.dart | 7 ++++++- web/apps/photos/src/utils/billing/index.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/lib/models/subscription.dart b/mobile/lib/models/subscription.dart index 62ad27888..51fca19e3 100644 --- a/mobile/lib/models/subscription.dart +++ b/mobile/lib/models/subscription.dart @@ -30,8 +30,13 @@ class Subscription { return expiryTime > DateTime.now().microsecondsSinceEpoch; } + bool isCancelled() { + return attributes?.isCancelled ?? false; + } + bool isPastDue() { - return expiryTime < DateTime.now().microsecondsSinceEpoch && + return !isCancelled() && + expiryTime < DateTime.now().microsecondsSinceEpoch && expiryTime >= DateTime.now() .subtract(const Duration(days: 30)) diff --git a/web/apps/photos/src/utils/billing/index.ts b/web/apps/photos/src/utils/billing/index.ts index 8d18a823f..5acf1ebc6 100644 --- a/web/apps/photos/src/utils/billing/index.ts +++ b/web/apps/photos/src/utils/billing/index.ts @@ -155,6 +155,7 @@ export function hasExceededStorageQuota(userDetails: UserDetails) { export function isSubscriptionPastDue(subscription: Subscription) { const currentTime = Date.now() * 1000; return ( + !isSubscriptionCancelled(subscription) && subscription.expiryTime < currentTime && subscription.expiryTime > currentTime - THIRTY_DAYS_IN_MICROSECONDS );