mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
[AC-2858] Remove code supporting payment method warning banners (#10615)
* Remove errant payment method warning banner implementation * Removing unused endpoint
This commit is contained in:
@@ -123,14 +123,12 @@ import {
|
||||
BillingApiServiceAbstraction,
|
||||
BraintreeServiceAbstraction,
|
||||
OrganizationBillingServiceAbstraction,
|
||||
PaymentMethodWarningsServiceAbstraction,
|
||||
StripeServiceAbstraction,
|
||||
} from "@bitwarden/common/billing/abstractions";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||
import { DefaultBillingAccountProfileStateService } from "@bitwarden/common/billing/services/account/billing-account-profile-state.service";
|
||||
import { BillingApiService } from "@bitwarden/common/billing/services/billing-api.service";
|
||||
import { OrganizationBillingService } from "@bitwarden/common/billing/services/organization-billing.service";
|
||||
import { PaymentMethodWarningsService } from "@bitwarden/common/billing/services/payment-method-warnings.service";
|
||||
import { BraintreeService } from "@bitwarden/common/billing/services/payment-processors/braintree.service";
|
||||
import { StripeService } from "@bitwarden/common/billing/services/payment-processors/stripe.service";
|
||||
import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||
@@ -1201,11 +1199,6 @@ const safeProviders: SafeProvider[] = [
|
||||
useClass: BillingApiService,
|
||||
deps: [ApiServiceAbstraction, LogService, ToastService],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: PaymentMethodWarningsServiceAbstraction,
|
||||
useClass: PaymentMethodWarningsService,
|
||||
deps: [BillingApiServiceAbstraction, StateProvider],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: BillingAccountProfileStateService,
|
||||
useClass: DefaultBillingAccountProfileStateService,
|
||||
|
||||
@@ -8,7 +8,6 @@ import { PaymentInformationResponse } from "@bitwarden/common/billing/models/res
|
||||
|
||||
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
||||
import { OrganizationBillingMetadataResponse } from "../../billing/models/response/organization-billing-metadata.response";
|
||||
import { OrganizationBillingStatusResponse } from "../../billing/models/response/organization-billing-status.response";
|
||||
import { PlanResponse } from "../../billing/models/response/plan.response";
|
||||
import { ListResponse } from "../../models/response/list.response";
|
||||
import { CreateClientOrganizationRequest } from "../models/request/create-client-organization.request";
|
||||
@@ -34,8 +33,6 @@ export abstract class BillingApiServiceAbstraction {
|
||||
organizationId: string,
|
||||
) => Promise<OrganizationBillingMetadataResponse>;
|
||||
|
||||
getOrganizationBillingStatus: (id: string) => Promise<OrganizationBillingStatusResponse>;
|
||||
|
||||
getPlans: () => Promise<ListResponse<PlanResponse>>;
|
||||
|
||||
getProviderClientInvoiceReport: (providerId: string, invoiceId: string) => Promise<string>;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
export * from "./account/billing-account-profile-state.service";
|
||||
export * from "./billilng-api.service.abstraction";
|
||||
export * from "./organization-billing.service";
|
||||
export * from "./payment-method-warnings-service.abstraction";
|
||||
export * from "./payment-processors/braintree.service.abstraction";
|
||||
export * from "./payment-processors/stripe.service.abstraction";
|
||||
export * from "./provider-billing.service.abstraction";
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { PaymentMethodWarning } from "../models/domain/payment-method-warning";
|
||||
|
||||
export abstract class PaymentMethodWarningsServiceAbstraction {
|
||||
/**
|
||||
* An {@link Observable} record in the {@link ActiveUserState} of the user's organization IDs each mapped to their respective {@link PaymentMethodWarning}.
|
||||
*/
|
||||
paymentMethodWarnings$: Observable<Record<string, PaymentMethodWarning>>;
|
||||
/**
|
||||
* Updates the {@link ActiveUserState} by setting `acknowledged` to `true` for the {@link PaymentMethodWarning} represented by the provided organization ID.
|
||||
* @param organizationId - The ID of the organization whose warning you'd like to acknowledge.
|
||||
*/
|
||||
acknowledge: (organizationId: string) => Promise<void>;
|
||||
/**
|
||||
* Updates the {@link ActiveUserState} by setting `risksSubscriptionFailure` to `false` for the {@link PaymentMethodWarning} represented by the provided organization ID.
|
||||
* @param organizationId - The ID of the organization whose subscription risk you'd like to remove.
|
||||
*/
|
||||
removeSubscriptionRisk: (organizationId: string) => Promise<void>;
|
||||
/**
|
||||
* Clears the {@link PaymentMethodWarning} record from the {@link ActiveUserState}.
|
||||
*/
|
||||
clear: () => Promise<void>;
|
||||
/**
|
||||
* Tries to retrieve the {@link PaymentMethodWarning} for the provided organization ID from the {@link ActiveUserState}.
|
||||
* If the warning does not exist, or if the warning has been in state for longer than a week, fetches the current {@link OrganizationBillingStatusResponse} for the organization
|
||||
* from the API and uses it to update the warning in state.
|
||||
* @param organizationId - The ID of the organization whose {@link PaymentMethodWarning} you'd like to update.
|
||||
*/
|
||||
update: (organizationId: string) => Promise<void>;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { BILLING_DISK, UserKeyDefinition } from "../../platform/state";
|
||||
import { PaymentMethodWarning } from "../models/domain/payment-method-warning";
|
||||
|
||||
export const PAYMENT_METHOD_WARNINGS_KEY = UserKeyDefinition.record<PaymentMethodWarning>(
|
||||
BILLING_DISK,
|
||||
"paymentMethodWarnings",
|
||||
{
|
||||
deserializer: (warnings) => ({
|
||||
...warnings,
|
||||
savedAt: new Date(warnings.savedAt),
|
||||
}),
|
||||
clearOn: ["logout"],
|
||||
},
|
||||
);
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from "./bank-account";
|
||||
export * from "./masked-payment-method";
|
||||
export * from "./payment-method-warning";
|
||||
export * from "./tax-information";
|
||||
export * from "./tokenized-payment-method";
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export type PaymentMethodWarning = {
|
||||
organizationName: string;
|
||||
risksSubscriptionFailure: boolean;
|
||||
acknowledged: boolean;
|
||||
savedAt: Date;
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
|
||||
export class OrganizationBillingStatusResponse extends BaseResponse {
|
||||
organizationId: string;
|
||||
organizationName: string;
|
||||
risksSubscriptionFailure: boolean;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
|
||||
this.organizationId = this.getResponseProperty("OrganizationId");
|
||||
this.organizationName = this.getResponseProperty("OrganizationName");
|
||||
this.risksSubscriptionFailure = this.getResponseProperty("RisksSubscriptionFailure");
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import { SubscriptionCancellationRequest } from "../../billing/models/request/su
|
||||
import { TokenizedPaymentMethodRequest } from "../../billing/models/request/tokenized-payment-method.request";
|
||||
import { VerifyBankAccountRequest } from "../../billing/models/request/verify-bank-account.request";
|
||||
import { OrganizationBillingMetadataResponse } from "../../billing/models/response/organization-billing-metadata.response";
|
||||
import { OrganizationBillingStatusResponse } from "../../billing/models/response/organization-billing-status.response";
|
||||
import { PaymentInformationResponse } from "../../billing/models/response/payment-information.response";
|
||||
import { PlanResponse } from "../../billing/models/response/plan.response";
|
||||
import { ListResponse } from "../../models/response/list.response";
|
||||
@@ -72,17 +71,6 @@ export class BillingApiService implements BillingApiServiceAbstraction {
|
||||
return response as string;
|
||||
}
|
||||
|
||||
async getOrganizationBillingStatus(id: string): Promise<OrganizationBillingStatusResponse> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + id + "/billing-status",
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new OrganizationBillingStatusResponse(r);
|
||||
}
|
||||
|
||||
async getOrganizationBillingMetadata(
|
||||
organizationId: string,
|
||||
): Promise<OrganizationBillingMetadataResponse> {
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
import { any, mock, MockProxy } from "jest-mock-extended";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { FakeAccountService, FakeStateProvider, mockAccountServiceWith } from "../../../spec";
|
||||
import { FakeActiveUserState } from "../../../spec/fake-state";
|
||||
import { Utils } from "../../platform/misc/utils";
|
||||
import { UserId } from "../../types/guid";
|
||||
import { BillingApiServiceAbstraction as BillingApiService } from "../abstractions/billilng-api.service.abstraction";
|
||||
import { PAYMENT_METHOD_WARNINGS_KEY } from "../models/billing-keys.state";
|
||||
import { PaymentMethodWarning } from "../models/domain/payment-method-warning";
|
||||
import { OrganizationBillingStatusResponse } from "../models/response/organization-billing-status.response";
|
||||
|
||||
import { PaymentMethodWarningsService } from "./payment-method-warnings.service";
|
||||
|
||||
describe("Payment Method Warnings Service", () => {
|
||||
let paymentMethodWarningsService: PaymentMethodWarningsService;
|
||||
let billingApiService: MockProxy<BillingApiService>;
|
||||
|
||||
const mockUserId = Utils.newGuid() as UserId;
|
||||
let accountService: FakeAccountService;
|
||||
let stateProvider: FakeStateProvider;
|
||||
let activeUserState: FakeActiveUserState<Record<string, PaymentMethodWarning>>;
|
||||
|
||||
function getPastDate(daysAgo: number) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - daysAgo);
|
||||
return date;
|
||||
}
|
||||
|
||||
const getBillingStatusResponse = (organizationId: string) =>
|
||||
new OrganizationBillingStatusResponse({
|
||||
OrganizationId: organizationId,
|
||||
OrganizationName: "Teams Organization",
|
||||
RisksSubscriptionFailure: true,
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
accountService = mockAccountServiceWith(mockUserId);
|
||||
stateProvider = new FakeStateProvider(accountService);
|
||||
activeUserState = stateProvider.activeUser.getFake(PAYMENT_METHOD_WARNINGS_KEY);
|
||||
|
||||
billingApiService = mock<BillingApiService>();
|
||||
paymentMethodWarningsService = new PaymentMethodWarningsService(
|
||||
billingApiService,
|
||||
stateProvider,
|
||||
);
|
||||
});
|
||||
|
||||
it("acknowledge", async () => {
|
||||
const organizationId = "1";
|
||||
const state: Record<string, PaymentMethodWarning> = {
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: getPastDate(3),
|
||||
},
|
||||
};
|
||||
activeUserState.nextState(state);
|
||||
await paymentMethodWarningsService.acknowledge(organizationId);
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({
|
||||
[organizationId]: {
|
||||
...state[organizationId],
|
||||
acknowledged: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("clear", async () => {
|
||||
const state: Record<string, PaymentMethodWarning> = {
|
||||
"1": {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: getPastDate(3),
|
||||
},
|
||||
};
|
||||
activeUserState.nextState(state);
|
||||
await paymentMethodWarningsService.clear();
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({});
|
||||
});
|
||||
|
||||
it("removeSubscriptionRisk", async () => {
|
||||
const organizationId = "1";
|
||||
const state: Record<string, PaymentMethodWarning> = {
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: getPastDate(3),
|
||||
},
|
||||
};
|
||||
activeUserState.nextState(state);
|
||||
await paymentMethodWarningsService.removeSubscriptionRisk(organizationId);
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({
|
||||
[organizationId]: {
|
||||
...state[organizationId],
|
||||
risksSubscriptionFailure: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe("update", () => {
|
||||
it("Does nothing if the stored payment method warning is less than a week old", async () => {
|
||||
const organizationId = "1";
|
||||
const state: Record<string, PaymentMethodWarning> = {
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: getPastDate(3),
|
||||
},
|
||||
};
|
||||
activeUserState.nextState(state);
|
||||
await paymentMethodWarningsService.update(organizationId);
|
||||
expect(billingApiService.getOrganizationBillingStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Retrieves the billing status from the API and uses it to update the state if the state is null", async () => {
|
||||
const organizationId = "1";
|
||||
activeUserState.nextState(null);
|
||||
billingApiService.getOrganizationBillingStatus.mockResolvedValue(
|
||||
getBillingStatusResponse(organizationId),
|
||||
);
|
||||
await paymentMethodWarningsService.update(organizationId);
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: any(),
|
||||
},
|
||||
});
|
||||
expect(billingApiService.getOrganizationBillingStatus).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("Retrieves the billing status from the API and uses it to update the state if the stored warning is null", async () => {
|
||||
const organizationId = "1";
|
||||
activeUserState.nextState({
|
||||
[organizationId]: null,
|
||||
});
|
||||
billingApiService.getOrganizationBillingStatus.mockResolvedValue(
|
||||
getBillingStatusResponse(organizationId),
|
||||
);
|
||||
await paymentMethodWarningsService.update(organizationId);
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: any(),
|
||||
},
|
||||
});
|
||||
expect(billingApiService.getOrganizationBillingStatus).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("Retrieves the billing status from the API and uses it to update the state if the stored warning is older than a week", async () => {
|
||||
const organizationId = "1";
|
||||
activeUserState.nextState({
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: false,
|
||||
acknowledged: false,
|
||||
savedAt: getPastDate(10),
|
||||
},
|
||||
});
|
||||
billingApiService.getOrganizationBillingStatus.mockResolvedValue(
|
||||
new OrganizationBillingStatusResponse({
|
||||
OrganizationId: organizationId,
|
||||
OrganizationName: "Teams Organization",
|
||||
RisksSubscriptionFailure: true,
|
||||
}),
|
||||
);
|
||||
await paymentMethodWarningsService.update(organizationId);
|
||||
expect(await firstValueFrom(paymentMethodWarningsService.paymentMethodWarnings$)).toEqual({
|
||||
[organizationId]: {
|
||||
organizationName: "Teams Organization",
|
||||
risksSubscriptionFailure: true,
|
||||
acknowledged: false,
|
||||
savedAt: any(),
|
||||
},
|
||||
});
|
||||
expect(billingApiService.getOrganizationBillingStatus).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,74 +0,0 @@
|
||||
import { firstValueFrom, map, Observable } from "rxjs";
|
||||
|
||||
import { ActiveUserState, StateProvider } from "../../platform/state";
|
||||
import { BillingApiServiceAbstraction as BillingApiService } from "../abstractions/billilng-api.service.abstraction";
|
||||
import { PaymentMethodWarningsServiceAbstraction } from "../abstractions/payment-method-warnings-service.abstraction";
|
||||
import { PAYMENT_METHOD_WARNINGS_KEY } from "../models/billing-keys.state";
|
||||
import { PaymentMethodWarning } from "../models/domain/payment-method-warning";
|
||||
|
||||
export class PaymentMethodWarningsService implements PaymentMethodWarningsServiceAbstraction {
|
||||
private paymentMethodWarningsState: ActiveUserState<Record<string, PaymentMethodWarning>>;
|
||||
paymentMethodWarnings$: Observable<Record<string, PaymentMethodWarning>>;
|
||||
|
||||
constructor(
|
||||
private billingApiService: BillingApiService,
|
||||
private stateProvider: StateProvider,
|
||||
) {
|
||||
this.paymentMethodWarningsState = this.stateProvider.getActive(PAYMENT_METHOD_WARNINGS_KEY);
|
||||
this.paymentMethodWarnings$ = this.paymentMethodWarningsState.state$;
|
||||
}
|
||||
|
||||
async acknowledge(organizationId: string): Promise<void> {
|
||||
await this.paymentMethodWarningsState.update((state) => {
|
||||
const current = state[organizationId];
|
||||
state[organizationId] = {
|
||||
...current,
|
||||
acknowledged: true,
|
||||
};
|
||||
return state;
|
||||
});
|
||||
}
|
||||
|
||||
async removeSubscriptionRisk(organizationId: string): Promise<void> {
|
||||
await this.paymentMethodWarningsState.update((state) => {
|
||||
const current = state[organizationId];
|
||||
state[organizationId] = {
|
||||
...current,
|
||||
risksSubscriptionFailure: false,
|
||||
};
|
||||
return state;
|
||||
});
|
||||
}
|
||||
|
||||
async clear(): Promise<void> {
|
||||
await this.paymentMethodWarningsState.update(() => ({}));
|
||||
}
|
||||
|
||||
async update(organizationId: string): Promise<void> {
|
||||
const warning = await firstValueFrom(
|
||||
this.paymentMethodWarningsState.state$.pipe(
|
||||
map((state) => (!state ? null : state[organizationId])),
|
||||
),
|
||||
);
|
||||
if (!warning || warning.savedAt < this.getOneWeekAgo()) {
|
||||
const { organizationName, risksSubscriptionFailure } =
|
||||
await this.billingApiService.getOrganizationBillingStatus(organizationId);
|
||||
await this.paymentMethodWarningsState.update((state) => {
|
||||
state ??= {};
|
||||
state[organizationId] = {
|
||||
organizationName,
|
||||
risksSubscriptionFailure,
|
||||
acknowledged: false,
|
||||
savedAt: new Date(),
|
||||
};
|
||||
return state;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private getOneWeekAgo = (): Date => {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - 7);
|
||||
return date;
|
||||
};
|
||||
}
|
||||
@@ -7,7 +7,6 @@ export enum FeatureFlag {
|
||||
BrowserFilelessImport = "browser-fileless-import",
|
||||
ItemShare = "item-share",
|
||||
GeneratorToolsModernization = "generator-tools-modernization",
|
||||
ShowPaymentMethodWarningBanners = "show-payment-method-warning-banners",
|
||||
EnableConsolidatedBilling = "enable-consolidated-billing",
|
||||
AC1795_UpdatedSubscriptionStatusSection = "AC-1795_updated-subscription-status-section",
|
||||
EnableDeleteProvider = "AC-1218-delete-provider",
|
||||
@@ -50,7 +49,6 @@ export const DefaultFeatureFlagValue = {
|
||||
[FeatureFlag.BrowserFilelessImport]: FALSE,
|
||||
[FeatureFlag.ItemShare]: FALSE,
|
||||
[FeatureFlag.GeneratorToolsModernization]: FALSE,
|
||||
[FeatureFlag.ShowPaymentMethodWarningBanners]: FALSE,
|
||||
[FeatureFlag.EnableConsolidatedBilling]: FALSE,
|
||||
[FeatureFlag.AC1795_UpdatedSubscriptionStatusSection]: FALSE,
|
||||
[FeatureFlag.EnableDeleteProvider]: FALSE,
|
||||
|
||||
Reference in New Issue
Block a user