From 67e55379d75159f8835f236d768f6e7dd41f0739 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Tue, 24 Jun 2025 16:56:44 +0100 Subject: [PATCH] [PM-22565]Prevent credit addition when trialing org has no payment (#15167) * changes for no billing location when adding credit * Use the existing taxInfor from getOrganizationPaymentMethod * refactor the biling location check --- .../organization-payment-method.component.ts | 25 ++++++++++++++++++- apps/web/src/locales/en/messages.json | 4 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/billing/organizations/payment-method/organization-payment-method.component.ts b/apps/web/src/app/billing/organizations/payment-method/organization-payment-method.component.ts index bcc497113eb..36ac7debae2 100644 --- a/apps/web/src/app/billing/organizations/payment-method/organization-payment-method.component.ts +++ b/apps/web/src/app/billing/organizations/payment-method/organization-payment-method.component.ts @@ -15,6 +15,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions"; import { PaymentMethodType } from "@bitwarden/common/billing/enums"; +import { TaxInformation } from "@bitwarden/common/billing/models/domain"; import { VerifyBankAccountRequest } from "@bitwarden/common/billing/models/request/verify-bank-account.request"; import { OrganizationSubscriptionResponse } from "@bitwarden/common/billing/models/response/organization-subscription.response"; import { PaymentSourceResponse } from "@bitwarden/common/billing/models/response/payment-source.response"; @@ -54,6 +55,8 @@ export class OrganizationPaymentMethodComponent implements OnDestroy { protected readonly Math = Math; launchPaymentModalAutomatically = false; + protected taxInformation: TaxInformation; + constructor( private activatedRoute: ActivatedRoute, private billingApiService: BillingApiServiceAbstraction, @@ -108,6 +111,12 @@ export class OrganizationPaymentMethodComponent implements OnDestroy { } protected addAccountCredit = async (): Promise => { + if (this.subscriptionStatus === "trialing") { + const hasValidBillingAddress = await this.checkBillingAddressForTrialingOrg(); + if (!hasValidBillingAddress) { + return; + } + } const dialogRef = openAddCreditDialog(this.dialogService, { data: { organizationId: this.organizationId, @@ -124,11 +133,12 @@ export class OrganizationPaymentMethodComponent implements OnDestroy { protected load = async (): Promise => { this.loading = true; try { - const { accountCredit, paymentSource, subscriptionStatus } = + const { accountCredit, paymentSource, subscriptionStatus, taxInformation } = await this.billingApiService.getOrganizationPaymentMethod(this.organizationId); this.accountCredit = accountCredit; this.paymentSource = paymentSource; this.subscriptionStatus = subscriptionStatus; + this.taxInformation = taxInformation; if (this.organizationId) { const organizationSubscriptionPromise = this.organizationApiService.getSubscription( @@ -247,4 +257,17 @@ export class OrganizationPaymentMethodComponent implements OnDestroy { const key = this.paymentSource == null ? "addPaymentMethod" : "changePaymentMethod"; return this.i18nService.t(key); } + + private async checkBillingAddressForTrialingOrg(): Promise { + const hasBillingAddress = this.taxInformation != null; + if (!hasBillingAddress) { + this.toastService.showToast({ + variant: "error", + title: null, + message: this.i18nService.t("billingAddressRequiredToAddCredit"), + }); + return false; + } + return true; + } } diff --git a/apps/web/src/locales/en/messages.json b/apps/web/src/locales/en/messages.json index b3f9a5fa64c..60e8d333225 100644 --- a/apps/web/src/locales/en/messages.json +++ b/apps/web/src/locales/en/messages.json @@ -10659,5 +10659,9 @@ "example": "12/31/2024" } } + }, + "billingAddressRequiredToAddCredit": { + "message": "Billing address required to add credit.", + "description": "Error message shown when trying to add credit to a trialing organization without a billing address." } }