From 2b78ac5151d39c5243a706c9974c40ba16077452 Mon Sep 17 00:00:00 2001 From: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:45:01 -0400 Subject: [PATCH] Show subscription status as active for premium if incomplete and within 15 seconds of creation (#11334) --- .../user-subscription.component.html | 2 +- .../individual/user-subscription.component.ts | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/web/src/app/billing/individual/user-subscription.component.html b/apps/web/src/app/billing/individual/user-subscription.component.html index 3430bddc13..eeb64ffe77 100644 --- a/apps/web/src/app/billing/individual/user-subscription.component.html +++ b/apps/web/src/app/billing/individual/user-subscription.component.html @@ -42,7 +42,7 @@
{{ "status" | i18n }}
- {{ (subscription && subscription.status) || "-" }} + {{ (subscription && subscriptionStatus) || "-" }} {{ "pendingCancellation" | i18n }} diff --git a/apps/web/src/app/billing/individual/user-subscription.component.ts b/apps/web/src/app/billing/individual/user-subscription.component.ts index cca17f6b9c..e04b7c8b01 100644 --- a/apps/web/src/app/billing/individual/user-subscription.component.ts +++ b/apps/web/src/app/billing/individual/user-subscription.component.ts @@ -35,8 +35,6 @@ import { UpdateLicenseDialogResult } from "../shared/update-license-types"; export class UserSubscriptionComponent implements OnInit { loading = false; firstLoaded = false; - adjustStorageAdd = true; - showUpdateLicense = false; sub: SubscriptionResponse; selfHosted = false; cloudWebVaultUrl: string; @@ -65,7 +63,7 @@ export class UserSubscriptionComponent implements OnInit { private toastService: ToastService, private configService: ConfigService, ) { - this.selfHosted = platformUtilsService.isSelfHost(); + this.selfHosted = this.platformUtilsService.isSelfHost(); } async ngOnInit() { @@ -216,11 +214,28 @@ export class UserSubscriptionComponent implements OnInit { : 0; } - get storageProgressWidth() { - return this.storagePercentage < 5 ? 5 : 0; - } - get title(): string { return this.i18nService.t(this.selfHosted ? "subscription" : "premiumMembership"); } + + get subscriptionStatus(): string | null { + if (!this.subscription) { + return null; + } else { + /* + Premium users who sign up with PayPal will have their subscription activated by a webhook. + This is an arbitrary 15-second grace period where we show their subscription as active rather than + incomplete while we wait for our webhook to process the `invoice.created` event. + */ + if (this.subscription.status === "incomplete") { + const periodStartMS = new Date(this.subscription.periodStartDate).getTime(); + const nowMS = new Date().getTime(); + return nowMS - periodStartMS <= 15000 + ? this.i18nService.t("active") + : this.subscription.status; + } + + return this.subscription.status; + } + } }