1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 05:43:41 +00:00

Changes to restart cancelled org (#12730)

This commit is contained in:
cyprain-okeke
2025-01-07 20:09:37 +01:00
committed by GitHub
parent 966e8d3fb8
commit 02556c1416
11 changed files with 261 additions and 57 deletions

View File

@@ -8,6 +8,7 @@ import { VerifyBankAccountRequest } from "@bitwarden/common/billing/models/reque
import { InvoicesResponse } from "@bitwarden/common/billing/models/response/invoices.response";
import { PaymentMethodResponse } from "@bitwarden/common/billing/models/response/payment-method.response";
import { OrganizationCreateRequest } from "../../admin-console/models/request/organization-create.request";
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
import { OrganizationBillingMetadataResponse } from "../../billing/models/response/organization-billing-metadata.response";
import { PlanResponse } from "../../billing/models/response/plan.response";
@@ -74,4 +75,9 @@ export abstract class BillingApiServiceAbstraction {
organizationId: string,
request: VerifyBankAccountRequest,
) => Promise<void>;
restartSubscription: (
organizationId: string,
request: OrganizationCreateRequest,
) => Promise<void>;
}

View File

@@ -57,4 +57,9 @@ export abstract class OrganizationBillingServiceAbstraction {
) => Promise<OrganizationResponse>;
startFree: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
restartSubscription: (
organizationId: string,
subscription: SubscriptionInformation,
) => Promise<void>;
}

View File

@@ -10,6 +10,7 @@ export class OrganizationBillingMetadataResponse extends BaseResponse {
invoiceDueDate: Date | null;
invoiceCreatedDate: Date | null;
subPeriodEndDate: Date | null;
isSubscriptionCanceled: boolean;
constructor(response: any) {
super(response);
@@ -23,6 +24,7 @@ export class OrganizationBillingMetadataResponse extends BaseResponse {
this.invoiceDueDate = this.parseDate(this.getResponseProperty("InvoiceDueDate"));
this.invoiceCreatedDate = this.parseDate(this.getResponseProperty("InvoiceCreatedDate"));
this.subPeriodEndDate = this.parseDate(this.getResponseProperty("SubPeriodEndDate"));
this.isSubscriptionCanceled = this.getResponseProperty("IsSubscriptionCanceled");
}
private parseDate(dateString: any): Date | null {

View File

@@ -10,6 +10,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { ToastService } from "@bitwarden/components";
import { ApiService } from "../../abstractions/api.service";
import { OrganizationCreateRequest } from "../../admin-console/models/request/organization-create.request";
import { BillingApiServiceAbstraction } from "../../billing/abstractions";
import { PaymentMethodType } from "../../billing/enums";
import { ExpandedTaxInfoUpdateRequest } from "../../billing/models/request/expanded-tax-info-update.request";
@@ -214,6 +215,19 @@ export class BillingApiService implements BillingApiServiceAbstraction {
);
}
async restartSubscription(
organizationId: string,
request: OrganizationCreateRequest,
): Promise<void> {
return await this.apiService.send(
"POST",
"/organizations/" + organizationId + "/billing/restart-subscription",
request,
true,
false,
);
}
private async execute(request: () => Promise<any>): Promise<any> {
try {
return await request();

View File

@@ -223,4 +223,17 @@ export class OrganizationBillingService implements OrganizationBillingServiceAbs
request.additionalStorageGb = information.storage;
}
}
async restartSubscription(
organizationId: string,
subscription: SubscriptionInformation,
): Promise<void> {
const request = new OrganizationCreateRequest();
const organizationKeys = await this.makeOrganizationKeys();
this.setOrganizationKeys(request, organizationKeys);
this.setOrganizationInformation(request, subscription.organization);
this.setPlanInformation(request, subscription.plan);
this.setPaymentInformation(request, subscription.payment);
await this.billingApiService.restartSubscription(organizationId, request);
}
}