1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

Update client side error handling and remove add account credit from sub (#10214)

This commit is contained in:
Alex Morask
2024-07-31 09:27:16 -04:00
committed by GitHub
parent 27fa7625cf
commit 4a0b6fc191
12 changed files with 114 additions and 105 deletions

View File

@@ -1,4 +1,8 @@
import { ProviderOrganizationOrganizationDetailsResponse } from "@bitwarden/common/admin-console/models/response/provider/provider-organization.response";
import { InvoicesResponse } from "@bitwarden/common/billing/models/response/invoices.response";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { ToastService } from "@bitwarden/components";
import { ApiService } from "../../abstractions/api.service";
import { BillingApiServiceAbstraction } from "../../billing/abstractions";
@@ -9,7 +13,6 @@ import { TokenizedPaymentMethodRequest } from "../../billing/models/request/toke
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 { OrganizationSubscriptionResponse } from "../../billing/models/response/organization-subscription.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";
@@ -18,7 +21,11 @@ import { UpdateClientOrganizationRequest } from "../models/request/update-client
import { ProviderSubscriptionResponse } from "../models/response/provider-subscription-response";
export class BillingApiService implements BillingApiServiceAbstraction {
constructor(private apiService: ApiService) {}
constructor(
private apiService: ApiService,
private logService: LogService,
private toastService: ToastService,
) {}
cancelOrganizationSubscription(
organizationId: string,
@@ -37,7 +44,7 @@ export class BillingApiService implements BillingApiServiceAbstraction {
return this.apiService.send("POST", "/accounts/cancel", request, true, false);
}
createClientOrganization(
createProviderClientOrganization(
providerId: string,
request: CreateClientOrganizationRequest,
): Promise<void> {
@@ -65,7 +72,7 @@ export class BillingApiService implements BillingApiServiceAbstraction {
return response as string;
}
async getBillingStatus(id: string): Promise<OrganizationBillingStatusResponse> {
async getOrganizationBillingStatus(id: string): Promise<OrganizationBillingStatusResponse> {
const r = await this.apiService.send(
"GET",
"/organizations/" + id + "/billing-status",
@@ -90,19 +97,6 @@ export class BillingApiService implements BillingApiServiceAbstraction {
return new OrganizationBillingMetadataResponse(r);
}
async getOrganizationSubscription(
organizationId: string,
): Promise<OrganizationSubscriptionResponse> {
const r = await this.apiService.send(
"GET",
"/organizations/" + organizationId + "/subscription",
null,
true,
true,
);
return new OrganizationSubscriptionResponse(r);
}
async getPlans(): Promise<ListResponse<PlanResponse>> {
const r = await this.apiService.send("GET", "/plans", null, false, true);
return new ListResponse(r, PlanResponse);
@@ -119,40 +113,55 @@ export class BillingApiService implements BillingApiServiceAbstraction {
return response as string;
}
async getProviderClientOrganizations(
providerId: string,
): Promise<ListResponse<ProviderOrganizationOrganizationDetailsResponse>> {
const response = await this.execute(() =>
this.apiService.send("GET", "/providers/" + providerId + "/organizations", null, true, true),
);
return new ListResponse(response, ProviderOrganizationOrganizationDetailsResponse);
}
async getProviderInvoices(providerId: string): Promise<InvoicesResponse> {
const response = await this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/invoices",
null,
true,
true,
const response = await this.execute(() =>
this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/invoices",
null,
true,
true,
),
);
return new InvoicesResponse(response);
}
async getProviderPaymentInformation(providerId: string): Promise<PaymentInformationResponse> {
const response = await this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/payment-information",
null,
true,
true,
const response = await this.execute(() =>
this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/payment-information",
null,
true,
true,
),
);
return new PaymentInformationResponse(response);
}
async getProviderSubscription(providerId: string): Promise<ProviderSubscriptionResponse> {
const r = await this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/subscription",
null,
true,
true,
const response = await this.execute(() =>
this.apiService.send(
"GET",
"/providers/" + providerId + "/billing/subscription",
null,
true,
true,
),
);
return new ProviderSubscriptionResponse(r);
return new ProviderSubscriptionResponse(response);
}
async updateClientOrganization(
async updateProviderClientOrganization(
providerId: string,
organizationId: string,
request: UpdateClientOrganizationRequest,
@@ -198,4 +207,20 @@ export class BillingApiService implements BillingApiServiceAbstraction {
false,
);
}
private async execute(request: () => Promise<any>): Promise<any> {
try {
return await request();
} catch (error) {
this.logService.error(error);
if (error instanceof ErrorResponse) {
this.toastService.showToast({
variant: "error",
title: null,
message: error.getSingleMessage(),
});
}
throw error;
}
}
}