mirror of
https://github.com/bitwarden/browser
synced 2026-02-27 18:13:29 +00:00
[PM-14892] Refactoring tax estimation
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
|
||||
import { TaxIdTypesResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
|
||||
|
||||
export abstract class TaxServiceAbstraction {
|
||||
getTaxIdTypes: () => Promise<TaxIdTypesResponse>;
|
||||
|
||||
getCountries: () => CountryListItem[];
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
|
||||
|
||||
export class TaxIdTypesResponse extends BaseResponse {
|
||||
taxIdTypes: TaxIdTypeResponse[] = [];
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
const taxIdTypes = this.getResponseProperty("TaxIdTypes");
|
||||
if (taxIdTypes && taxIdTypes.length) {
|
||||
this.taxIdTypes = taxIdTypes.map((t: any) => new TaxIdTypeResponse(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TaxIdTypeResponse extends BaseResponse {
|
||||
code: string;
|
||||
country: string;
|
||||
description: string;
|
||||
example: string;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.code = this.getResponseProperty("Code");
|
||||
this.country = this.getResponseProperty("Country");
|
||||
this.description = this.getResponseProperty("Description");
|
||||
this.example = this.getResponseProperty("Example");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { TaxServiceAbstraction } from "@bitwarden/common/billing/abstractions/tax.service.abstraction";
|
||||
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
|
||||
import { TaxIdTypesResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
|
||||
|
||||
export class TaxService implements TaxServiceAbstraction {
|
||||
constructor() {}
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
async getTaxIdTypes(): Promise<TaxIdTypesResponse> {
|
||||
const response = await this.apiService.send("GET", "/tax/id-types", null, true, true);
|
||||
return new TaxIdTypesResponse(response);
|
||||
}
|
||||
|
||||
getCountries(): CountryListItem[] {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user