mirror of
https://github.com/bitwarden/browser
synced 2026-02-12 14:34:02 +00:00
wip
This commit is contained in:
@@ -131,11 +131,10 @@
|
||||
<bit-section>
|
||||
<h3 bitTypography="h2">{{ "paymentInformation" | i18n }}</h3>
|
||||
<app-payment-v2 [showBankAccount]="false"></app-payment-v2>
|
||||
<app-tax-info></app-tax-info>
|
||||
<app-tax-info (onTaxInformationChanged)="onTaxInformationChanged()"></app-tax-info>
|
||||
<div class="tw-mb-4">
|
||||
<div class="tw-text-muted tw-text-sm tw-flex tw-flex-col">
|
||||
<span>{{ "planPrice" | i18n }}: {{ subtotal | currency: "USD $" }}</span>
|
||||
<!-- TODO: Currently incorrect - https://bitwarden.atlassian.net/browse/PM-11525 -->
|
||||
<span>{{ "estimatedTax" | i18n }}: {{ estimatedTax | currency: "USD $" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,10 +3,13 @@ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||
import { FormControl, FormGroup, Validators } from "@angular/forms";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { combineLatest, concatMap, from, Observable, of } from "rxjs";
|
||||
import { debounceTime } from "rxjs/operators";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
||||
import { TaxServiceAbstraction } from "@bitwarden/common/billing/abstractions/tax.service.abstraction";
|
||||
import { PreviewIndividualInvoiceRequest } from "@bitwarden/common/billing/models/request/preview-individual-invoice.request";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
@@ -42,6 +45,7 @@ export class PremiumV2Component {
|
||||
FeatureFlag.PM11901_RefactorSelfHostingLicenseUploader,
|
||||
);
|
||||
|
||||
protected estimatedTax: number = 0;
|
||||
protected readonly familyPlanMaxUserCount = 6;
|
||||
protected readonly premiumPrice = 10;
|
||||
protected readonly storageGBPrice = 4;
|
||||
@@ -58,6 +62,7 @@ export class PremiumV2Component {
|
||||
private syncService: SyncService,
|
||||
private toastService: ToastService,
|
||||
private tokenService: TokenService,
|
||||
private taxService: TaxServiceAbstraction,
|
||||
) {
|
||||
this.isSelfHost = this.platformUtilsService.isSelfHost();
|
||||
|
||||
@@ -80,6 +85,12 @@ export class PremiumV2Component {
|
||||
}),
|
||||
)
|
||||
.subscribe();
|
||||
|
||||
this.addOnFormGroup.controls.additionalStorage.valueChanges
|
||||
.pipe(debounceTime(1000), takeUntilDestroyed())
|
||||
.subscribe(() => {
|
||||
this.refreshSalesTax();
|
||||
});
|
||||
}
|
||||
|
||||
finalizeUpgrade = async () => {
|
||||
@@ -156,12 +167,6 @@ export class PremiumV2Component {
|
||||
return this.storageGBPrice * this.addOnFormGroup.value.additionalStorage;
|
||||
}
|
||||
|
||||
protected get estimatedTax(): number {
|
||||
return this.taxInfoComponent?.taxRate != null
|
||||
? (this.taxInfoComponent.taxRate / 100) * this.subtotal
|
||||
: 0;
|
||||
}
|
||||
|
||||
protected get premiumURL(): string {
|
||||
return `${this.cloudWebVaultURL}/#/settings/subscription/premium`;
|
||||
}
|
||||
@@ -177,4 +182,33 @@ export class PremiumV2Component {
|
||||
protected async onLicenseFileSelectedChanged(): Promise<void> {
|
||||
await this.postFinalizeUpgrade();
|
||||
}
|
||||
|
||||
protected refreshSalesTax(): void {
|
||||
if (!this.taxInfoComponent.country || !this.taxInfoComponent.postalCode) {
|
||||
return;
|
||||
}
|
||||
const request: PreviewIndividualInvoiceRequest = {
|
||||
passwordManager: {
|
||||
additionalStorage: this.addOnFormGroup.value.additionalStorage,
|
||||
},
|
||||
taxInformation: {
|
||||
postalCode: this.taxInfoComponent.postalCode,
|
||||
country: this.taxInfoComponent.country,
|
||||
taxId: this.taxInfoComponent.taxId,
|
||||
},
|
||||
};
|
||||
|
||||
this.taxService
|
||||
.previewIndividualInvoice(request)
|
||||
.then((invoice) => {
|
||||
this.estimatedTax = invoice.taxAmount;
|
||||
})
|
||||
.catch(() => {
|
||||
this.estimatedTax = 0;
|
||||
});
|
||||
}
|
||||
|
||||
protected onTaxInformationChanged(): void {
|
||||
this.refreshSalesTax();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,12 +197,22 @@ export class PaymentMethodComponent implements OnInit, OnDestroy {
|
||||
};
|
||||
|
||||
submitTaxInfo = async () => {
|
||||
await this.taxInfo.submitTaxInfo();
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: null,
|
||||
message: this.i18nService.t("taxInfoUpdated"),
|
||||
});
|
||||
await this.taxInfo
|
||||
.submitTaxInfo()
|
||||
.then(() => {
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: null,
|
||||
message: this.i18nService.t("taxInfoUpdated"),
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
title: null,
|
||||
message: this.i18nService.t(error.message),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
determineOrgsWithUpcomingPaymentIssues() {
|
||||
|
||||
@@ -19,57 +19,47 @@
|
||||
<input bitInput type="text" formControlName="postalCode" autocomplete="postal-code" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6" *ngIf="showTaxIdCheckbox">
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-control>
|
||||
<input bitCheckbox type="checkbox" formControlName="includeTaxId" />
|
||||
<bit-label>{{ "includeVAT" | i18n }}</bit-label>
|
||||
</bit-form-control>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tw-grid tw-grid-cols-12 tw-gap-4" *ngIf="showTaxIdFields">
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "taxIdNumber" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="taxId" />
|
||||
</bit-form-field>
|
||||
<ng-container *ngIf="showTaxIdFields">
|
||||
<div class="tw-grid tw-grid-cols-12 tw-gap-4">
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "taxIdNumber" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="taxId" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "taxIdType" | i18n }}</bit-label>
|
||||
<bit-select formControlName="taxIdType">
|
||||
<bit-option
|
||||
*ngFor="let taxIdType of taxIdTypes"
|
||||
[value]="taxIdType.code"
|
||||
[label]="taxIdType.description"
|
||||
/>
|
||||
</bit-select>
|
||||
</bit-form-field>
|
||||
<div class="tw-grid tw-grid-cols-12 tw-gap-4">
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "address1" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="line1" autocomplete="address-line1" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "address2" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="line2" autocomplete="address-line2" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label for="addressCity">{{ "cityTown" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="city" autocomplete="address-level2" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "stateProvince" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="state" autocomplete="address-level1" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tw-grid tw-grid-cols-12 tw-gap-4" *ngIf="showTaxIdFields">
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "address1" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="line1" autocomplete="address-line1" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "address2" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="line2" autocomplete="address-line2" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label for="addressCity">{{ "cityTown" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="city" autocomplete="address-level2" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
<div class="tw-col-span-6">
|
||||
<bit-form-field>
|
||||
<bit-label>{{ "stateProvince" | i18n }}</bit-label>
|
||||
<input bitInput type="text" formControlName="state" autocomplete="address-level1" />
|
||||
</bit-form-field>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
</form>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
||||
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from "@angular/core";
|
||||
import { FormControl, FormGroup, Validators } from "@angular/forms";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
import { Subject, takeUntil } from "rxjs";
|
||||
import { debounceTime } from "rxjs/operators";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
|
||||
@@ -9,13 +10,13 @@ import { TaxServiceAbstraction } from "@bitwarden/common/billing/abstractions/ta
|
||||
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
|
||||
import { ExpandedTaxInfoUpdateRequest } from "@bitwarden/common/billing/models/request/expanded-tax-info-update.request";
|
||||
import { TaxInfoUpdateRequest } from "@bitwarden/common/billing/models/request/tax-info-update.request";
|
||||
import { TaxIdTypeResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
|
||||
import { TaxInfoResponse } from "@bitwarden/common/billing/models/response/tax-info.response";
|
||||
import { TaxRateResponse } from "@bitwarden/common/billing/models/response/tax-rate.response";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
import { SharedModule } from "../../shared";
|
||||
|
||||
|
||||
type TaxInfoView = Omit<TaxInfoResponse, "taxIdType"> & {
|
||||
includeTaxId: boolean;
|
||||
[key: string]: unknown;
|
||||
@@ -28,17 +29,18 @@ type TaxInfoView = Omit<TaxInfoResponse, "taxIdType"> & {
|
||||
imports: [SharedModule],
|
||||
})
|
||||
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
||||
export class TaxInfoComponent implements OnInit {
|
||||
export class TaxInfoComponent implements OnInit, OnDestroy {
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
@Input() trialFlow = false;
|
||||
@Output() onCountryChanged = new EventEmitter();
|
||||
private destroy$ = new Subject<void>();
|
||||
@Output() onTaxInformationChanged: EventEmitter<void> = new EventEmitter<void>();
|
||||
|
||||
taxFormGroup = new FormGroup({
|
||||
country: new FormControl(null, [Validators.required]),
|
||||
postalCode: new FormControl(null),
|
||||
includeTaxId: new FormControl(null),
|
||||
taxId: new FormControl(null),
|
||||
taxIdType: new FormControl(null),
|
||||
line1: new FormControl(null),
|
||||
line2: new FormControl(null),
|
||||
city: new FormControl(null),
|
||||
@@ -60,7 +62,7 @@ export class TaxInfoComponent implements OnInit {
|
||||
};
|
||||
countryList: CountryListItem[] = this.taxService.getCountries();
|
||||
taxRates: TaxRateResponse[];
|
||||
taxIdTypes: TaxIdTypeResponse[];
|
||||
private taxSupportedCountryCodes: string[] = this.taxService.getSupportedCountries();
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
@@ -71,67 +73,35 @@ export class TaxInfoComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
get country(): string {
|
||||
return this.taxFormGroup.get("country").value;
|
||||
}
|
||||
|
||||
set country(country: string) {
|
||||
this.taxFormGroup.get("country").setValue(country);
|
||||
return this.taxFormGroup.controls.country.value;
|
||||
}
|
||||
|
||||
get postalCode(): string {
|
||||
return this.taxFormGroup.get("postalCode").value;
|
||||
}
|
||||
|
||||
set postalCode(postalCode: string) {
|
||||
this.taxFormGroup.get("postalCode").setValue(postalCode);
|
||||
}
|
||||
|
||||
get includeTaxId(): boolean {
|
||||
return this.taxFormGroup.get("includeTaxId").value;
|
||||
}
|
||||
|
||||
set includeTaxId(includeTaxId: boolean) {
|
||||
this.taxFormGroup.get("includeTaxId").setValue(includeTaxId);
|
||||
return this.taxFormGroup.controls.postalCode.value;
|
||||
}
|
||||
|
||||
get taxId(): string {
|
||||
return this.taxFormGroup.get("taxId").value;
|
||||
}
|
||||
|
||||
set taxId(taxId: string) {
|
||||
this.taxFormGroup.get("taxId").setValue(taxId);
|
||||
return this.taxFormGroup.controls.taxId.value;
|
||||
}
|
||||
|
||||
get line1(): string {
|
||||
return this.taxFormGroup.get("line1").value;
|
||||
}
|
||||
|
||||
set line1(line1: string) {
|
||||
this.taxFormGroup.get("line1").setValue(line1);
|
||||
return this.taxFormGroup.controls.line1.value;
|
||||
}
|
||||
|
||||
get line2(): string {
|
||||
return this.taxFormGroup.get("line2").value;
|
||||
}
|
||||
|
||||
set line2(line2: string) {
|
||||
this.taxFormGroup.get("line2").setValue(line2);
|
||||
return this.taxFormGroup.controls.line2.value;
|
||||
}
|
||||
|
||||
get city(): string {
|
||||
return this.taxFormGroup.get("city").value;
|
||||
}
|
||||
|
||||
set city(city: string) {
|
||||
this.taxFormGroup.get("city").setValue(city);
|
||||
return this.taxFormGroup.controls.city.value;
|
||||
}
|
||||
|
||||
get state(): string {
|
||||
return this.taxFormGroup.get("state").value;
|
||||
return this.taxFormGroup.controls.state.value;
|
||||
}
|
||||
|
||||
set state(state: string) {
|
||||
this.taxFormGroup.get("state").setValue(state);
|
||||
protected get includeTaxId(): boolean {
|
||||
return this.taxFormGroup.controls.includeTaxId.value;
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
@@ -148,21 +118,21 @@ export class TaxInfoComponent implements OnInit {
|
||||
try {
|
||||
const taxInfo = await this.organizationApiService.getTaxInfo(this.organizationId);
|
||||
if (taxInfo) {
|
||||
this.taxId = taxInfo.taxId;
|
||||
this.state = taxInfo.state;
|
||||
this.line1 = taxInfo.line1;
|
||||
this.line2 = taxInfo.line2;
|
||||
this.city = taxInfo.city;
|
||||
this.state = taxInfo.state;
|
||||
this.postalCode = taxInfo.postalCode;
|
||||
this.country = taxInfo.country || "US";
|
||||
this.includeTaxId =
|
||||
this.taxFormGroup.controls.taxId.setValue(taxInfo.taxId);
|
||||
this.taxFormGroup.controls.state.setValue(taxInfo.state);
|
||||
this.taxFormGroup.controls.line1.setValue(taxInfo.line1);
|
||||
this.taxFormGroup.controls.line2.setValue(taxInfo.line2);
|
||||
this.taxFormGroup.controls.city.setValue(taxInfo.city);
|
||||
this.taxFormGroup.controls.postalCode.setValue(taxInfo.postalCode);
|
||||
this.taxFormGroup.controls.country.setValue(taxInfo.country || "US");
|
||||
this.taxFormGroup.controls.includeTaxId.setValue(
|
||||
this.countrySupportsTax(this.country) &&
|
||||
(!!taxInfo.taxId ||
|
||||
!!taxInfo.line1 ||
|
||||
!!taxInfo.line2 ||
|
||||
!!taxInfo.city ||
|
||||
!!taxInfo.state);
|
||||
(!!taxInfo.taxId ||
|
||||
!!taxInfo.line1 ||
|
||||
!!taxInfo.line2 ||
|
||||
!!taxInfo.city ||
|
||||
!!taxInfo.state),
|
||||
);
|
||||
this.setTaxInfoObject();
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -172,8 +142,8 @@ export class TaxInfoComponent implements OnInit {
|
||||
try {
|
||||
const taxInfo = await this.apiService.getTaxInfo();
|
||||
if (taxInfo) {
|
||||
this.postalCode = taxInfo.postalCode;
|
||||
this.country = taxInfo.country || "US";
|
||||
this.taxFormGroup.controls.postalCode.setValue(taxInfo.postalCode);
|
||||
this.taxFormGroup.controls.country.setValue(taxInfo.country || "US");
|
||||
}
|
||||
this.setTaxInfoObject();
|
||||
} catch (e) {
|
||||
@@ -182,8 +152,8 @@ export class TaxInfoComponent implements OnInit {
|
||||
}
|
||||
|
||||
if (this.country === "US") {
|
||||
this.taxFormGroup.get("postalCode").setValidators([Validators.required]);
|
||||
this.taxFormGroup.get("postalCode").updateValueAndValidity();
|
||||
this.taxFormGroup.controls.postalCode.setValidators([Validators.required]);
|
||||
this.taxFormGroup.controls.postalCode.updateValueAndValidity();
|
||||
}
|
||||
|
||||
if (this.country !== "US") {
|
||||
@@ -191,9 +161,8 @@ export class TaxInfoComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
this.taxFormGroup
|
||||
.get("country")
|
||||
.valueChanges.pipe(takeUntil(this.destroy$))
|
||||
this.taxFormGroup.controls.country.valueChanges
|
||||
.pipe(debounceTime(1000), takeUntil(this.destroy$))
|
||||
.subscribe((value) => {
|
||||
if (value === "US") {
|
||||
this.taxFormGroup.get("postalCode").setValidators([Validators.required]);
|
||||
@@ -203,6 +172,25 @@ export class TaxInfoComponent implements OnInit {
|
||||
this.taxFormGroup.get("postalCode").updateValueAndValidity();
|
||||
this.setTaxInfoObject();
|
||||
this.changeCountry();
|
||||
this.onTaxInformationChanged.emit();
|
||||
});
|
||||
|
||||
this.taxFormGroup.controls.postalCode.valueChanges
|
||||
.pipe(debounceTime(1000), takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.onTaxInformationChanged.emit();
|
||||
});
|
||||
|
||||
this.taxFormGroup.controls.taxId.valueChanges
|
||||
.pipe(debounceTime(1000), takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.onTaxInformationChanged.emit();
|
||||
});
|
||||
|
||||
this.taxFormGroup.controls.includeTaxId.valueChanges
|
||||
.pipe(debounceTime(1000), takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.clearTaxInformationFields();
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -210,10 +198,6 @@ export class TaxInfoComponent implements OnInit {
|
||||
if (taxRates) {
|
||||
this.taxRates = taxRates.data;
|
||||
}
|
||||
const taxIdTypes = await this.taxService.getTaxIdTypes();
|
||||
if (taxIdTypes) {
|
||||
this.taxIdTypes = taxIdTypes.taxIdTypes;
|
||||
}
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
} finally {
|
||||
@@ -221,6 +205,11 @@ export class TaxInfoComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
get taxRate() {
|
||||
if (this.taxRates != null) {
|
||||
const localTaxRate = this.taxRates.find(
|
||||
@@ -241,48 +230,20 @@ export class TaxInfoComponent implements OnInit {
|
||||
this.taxInfo.state = this.state;
|
||||
}
|
||||
|
||||
get showTaxIdCheckbox() {
|
||||
return (
|
||||
(this.organizationId || this.providerId) &&
|
||||
this.country !== "US" &&
|
||||
this.countrySupportsTax(this.taxInfo.country)
|
||||
);
|
||||
}
|
||||
|
||||
get showTaxIdFields() {
|
||||
return (
|
||||
(this.organizationId || this.providerId) &&
|
||||
this.includeTaxId &&
|
||||
this.countrySupportsTax(this.country)
|
||||
);
|
||||
get showTaxIdFields(): boolean {
|
||||
return this.includeTaxId && this.countrySupportsTax(this.country);
|
||||
}
|
||||
|
||||
getTaxInfoRequest(): TaxInfoUpdateRequest {
|
||||
if (this.organizationId || this.providerId) {
|
||||
const request = new ExpandedTaxInfoUpdateRequest();
|
||||
request.country = this.country;
|
||||
request.postalCode = this.postalCode;
|
||||
|
||||
if (this.includeTaxId) {
|
||||
request.taxId = this.taxId;
|
||||
request.line1 = this.line1;
|
||||
request.line2 = this.line2;
|
||||
request.city = this.city;
|
||||
request.state = this.state;
|
||||
} else {
|
||||
request.taxId = null;
|
||||
request.line1 = null;
|
||||
request.line2 = null;
|
||||
request.city = null;
|
||||
request.state = null;
|
||||
}
|
||||
return request;
|
||||
} else {
|
||||
const request = new TaxInfoUpdateRequest();
|
||||
request.postalCode = this.postalCode;
|
||||
request.country = this.country;
|
||||
return request;
|
||||
}
|
||||
const request = new ExpandedTaxInfoUpdateRequest();
|
||||
request.country = this.country;
|
||||
request.postalCode = this.postalCode;
|
||||
request.taxId = this.taxId;
|
||||
request.line1 = this.line1;
|
||||
request.line2 = this.line2;
|
||||
request.city = this.city;
|
||||
request.state = this.state;
|
||||
return request;
|
||||
}
|
||||
|
||||
submitTaxInfo(): Promise<any> {
|
||||
@@ -299,30 +260,23 @@ export class TaxInfoComponent implements OnInit {
|
||||
|
||||
changeCountry() {
|
||||
if (!this.countrySupportsTax(this.country)) {
|
||||
this.includeTaxId = false;
|
||||
this.taxId = null;
|
||||
this.line1 = null;
|
||||
this.line2 = null;
|
||||
this.city = null;
|
||||
this.state = null;
|
||||
this.taxFormGroup.controls.includeTaxId.setValue(false);
|
||||
this.clearTaxInformationFields();
|
||||
this.setTaxInfoObject();
|
||||
}
|
||||
// reorder tax id types based on country
|
||||
this.taxIdTypes = this.taxIdTypes.sort((a, b) => {
|
||||
if (a.country === this.country && b.country !== this.country) {
|
||||
return -1;
|
||||
} else if (a.country !== this.country && b.country === this.country) {
|
||||
return 1;
|
||||
} else {
|
||||
return a.description.localeCompare(b.description);
|
||||
}
|
||||
});
|
||||
|
||||
this.onCountryChanged.emit();
|
||||
}
|
||||
|
||||
private clearTaxInformationFields(): void {
|
||||
this.taxFormGroup.controls.taxId.setValue(null);
|
||||
this.taxFormGroup.controls.line1.setValue(null);
|
||||
this.taxFormGroup.controls.line2.setValue(null);
|
||||
this.taxFormGroup.controls.city.setValue(null);
|
||||
this.taxFormGroup.controls.state.setValue(null);
|
||||
}
|
||||
|
||||
countrySupportsTax(countryCode: string) {
|
||||
return this.taxSupportedCountryCodes.includes(countryCode);
|
||||
}
|
||||
|
||||
private taxSupportedCountryCodes: string[] = this.taxService.getSupportedCountries();
|
||||
}
|
||||
|
||||
@@ -4655,9 +4655,6 @@
|
||||
"taxIdNumber": {
|
||||
"message": "VAT/GST Tax ID"
|
||||
},
|
||||
"taxIdType": {
|
||||
"message": "Tax ID Type"
|
||||
},
|
||||
"taxInfoUpdated": {
|
||||
"message": "Tax information updated."
|
||||
},
|
||||
@@ -9120,6 +9117,12 @@
|
||||
"updatedTaxInformation": {
|
||||
"message": "Updated tax information"
|
||||
},
|
||||
"billingInvalidTaxIdError": {
|
||||
"message": "Invalid tax ID, if you believe this is an error please contact support."
|
||||
},
|
||||
"billingTaxIdTypeInferenceError": {
|
||||
"message": "We were unable to validate your tax ID, if you believe this is an error please contact support."
|
||||
},
|
||||
"unverified": {
|
||||
"message": "Unverified"
|
||||
},
|
||||
|
||||
@@ -19,6 +19,7 @@ export class ManageTaxInformationComponent implements OnInit, OnDestroy {
|
||||
postalCode: ["", Validators.required],
|
||||
includeTaxId: false,
|
||||
taxId: "",
|
||||
taxIdType: "",
|
||||
line1: "",
|
||||
line2: "",
|
||||
city: "",
|
||||
@@ -74,6 +75,7 @@ export class ManageTaxInformationComponent implements OnInit, OnDestroy {
|
||||
country: values.country,
|
||||
postalCode: values.postalCode,
|
||||
taxId: values.taxId,
|
||||
taxIdType: values.taxIdType,
|
||||
line1: values.line1,
|
||||
line2: values.line2,
|
||||
city: values.city,
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { CountryListItem } from "@bitwarden/common/billing/models/domain";
|
||||
import { TaxIdTypesResponse } from "@bitwarden/common/billing/models/response/tax-id-types.response";
|
||||
import { PreviewIndividualInvoiceRequest } from "@bitwarden/common/billing/models/request/preview-individual-invoice.request";
|
||||
import { PreviewInvoiceResponse } from "@bitwarden/common/billing/models/response/preview-invoice.response";
|
||||
|
||||
export abstract class TaxServiceAbstraction {
|
||||
getTaxIdTypes: () => Promise<TaxIdTypesResponse>;
|
||||
|
||||
getCountries: () => CountryListItem[];
|
||||
|
||||
/**
|
||||
* Whether the country supports tax.
|
||||
*/
|
||||
getSupportedCountries: () => string[];
|
||||
|
||||
previewIndividualInvoice: (
|
||||
request: PreviewIndividualInvoiceRequest,
|
||||
) => Promise<PreviewInvoiceResponse>;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ export class TaxInformation {
|
||||
country: string;
|
||||
postalCode: string;
|
||||
taxId: string;
|
||||
taxIdType: string;
|
||||
line1: string;
|
||||
line2: string;
|
||||
city: string;
|
||||
@@ -14,6 +15,7 @@ export class TaxInformation {
|
||||
country: null,
|
||||
postalCode: null,
|
||||
taxId: null,
|
||||
taxIdType: null,
|
||||
line1: null,
|
||||
line2: null,
|
||||
city: null,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export class PreviewIndividualInvoiceRequest {
|
||||
passwordManager: PasswordManager;
|
||||
taxInformation: TaxInformation;
|
||||
}
|
||||
|
||||
class PasswordManager {
|
||||
additionalStorage: number;
|
||||
}
|
||||
|
||||
class TaxInformation {
|
||||
postalCode: string;
|
||||
country: string;
|
||||
taxId: string;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
|
||||
|
||||
export class PreviewInvoiceResponse extends BaseResponse {
|
||||
effectiveTaxRate: number;
|
||||
taxableBaseAmount: number;
|
||||
taxAmount: number;
|
||||
totalAmount: number;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.effectiveTaxRate = this.getResponseProperty("EffectiveTaxRate");
|
||||
this.taxableBaseAmount = this.getResponseProperty("TaxableBaseAmount");
|
||||
this.taxAmount = this.getResponseProperty("TaxAmount");
|
||||
this.totalAmount = this.getResponseProperty("TotalAmount");
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
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";
|
||||
import { PreviewIndividualInvoiceRequest } from "@bitwarden/common/billing/models/request/preview-individual-invoice.request";
|
||||
import { PreviewInvoiceResponse } from "@bitwarden/common/billing/models/response/preview-invoice.response";
|
||||
|
||||
export class TaxService implements TaxServiceAbstraction {
|
||||
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 [
|
||||
{ name: "-- Select --", value: "", disabled: false },
|
||||
@@ -344,4 +340,17 @@ export class TaxService implements TaxServiceAbstraction {
|
||||
"VN",
|
||||
];
|
||||
}
|
||||
|
||||
async previewIndividualInvoice(
|
||||
request: PreviewIndividualInvoiceRequest,
|
||||
): Promise<PreviewInvoiceResponse> {
|
||||
const response = await this.apiService.send(
|
||||
"POST",
|
||||
"/accounts/billing/preview-invoice",
|
||||
request,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new PreviewInvoiceResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user