1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

[PM-13999] Show estimated tax for taxable countries (#12145)

This commit is contained in:
Jonas Hendrickx
2024-12-04 11:45:44 +01:00
committed by GitHub
parent 853db233d9
commit 1dce7f5ba0
34 changed files with 1093 additions and 1243 deletions

View File

@@ -1,17 +1,19 @@
import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
import { Component, Inject, ViewChild } from "@angular/core";
import { Component, Inject, OnInit, ViewChild } from "@angular/core";
import { FormGroup } from "@angular/forms";
import { ManageTaxInformationComponent } from "@bitwarden/angular/billing/components";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
import { PaymentMethodType } from "@bitwarden/common/billing/enums";
import { TaxInformation } from "@bitwarden/common/billing/models/domain";
import { PaymentRequest } from "@bitwarden/common/billing/models/request/payment.request";
import { TaxInfoResponse } from "@bitwarden/common/billing/models/response/tax-info.response";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { DialogService, ToastService } from "@bitwarden/components";
import { PaymentComponent } from "../payment/payment.component";
import { TaxInfoComponent } from "../tax-info.component";
export interface AdjustPaymentDialogData {
organizationId: string;
@@ -26,9 +28,9 @@ export enum AdjustPaymentDialogResult {
@Component({
templateUrl: "adjust-payment-dialog.component.html",
})
export class AdjustPaymentDialogComponent {
export class AdjustPaymentDialogComponent implements OnInit {
@ViewChild(PaymentComponent, { static: true }) paymentComponent: PaymentComponent;
@ViewChild(TaxInfoComponent, { static: true }) taxInfoComponent: TaxInfoComponent;
@ViewChild(ManageTaxInformationComponent) taxInfoComponent: ManageTaxInformationComponent;
organizationId: string;
currentType: PaymentMethodType;
@@ -37,6 +39,8 @@ export class AdjustPaymentDialogComponent {
protected DialogResult = AdjustPaymentDialogResult;
protected formGroup = new FormGroup({});
protected taxInformation: TaxInformation;
constructor(
private dialogRef: DialogRef,
@Inject(DIALOG_DATA) protected data: AdjustPaymentDialogData,
@@ -50,26 +54,48 @@ export class AdjustPaymentDialogComponent {
this.currentType = data.currentType;
}
ngOnInit(): void {
if (this.organizationId) {
this.organizationApiService
.getTaxInfo(this.organizationId)
.then((response: TaxInfoResponse) => {
this.taxInformation = TaxInformation.from(response);
})
.catch(() => {
this.taxInformation = new TaxInformation();
});
} else {
this.apiService
.getTaxInfo()
.then((response: TaxInfoResponse) => {
this.taxInformation = TaxInformation.from(response);
})
.catch(() => {
this.taxInformation = new TaxInformation();
});
}
}
submit = async () => {
if (!this.taxInfoComponent?.taxFormGroup.valid && this.taxInfoComponent?.taxFormGroup.touched) {
this.taxInfoComponent.taxFormGroup.markAllAsTouched();
if (!this.taxInfoComponent?.validate()) {
return;
}
const request = new PaymentRequest();
const response = this.paymentComponent.createPaymentToken().then((result) => {
request.paymentToken = result[0];
request.paymentMethodType = result[1];
request.postalCode = this.taxInfoComponent.taxFormGroup?.value.postalCode;
request.country = this.taxInfoComponent.taxFormGroup?.value.country;
request.postalCode = this.taxInformation?.postalCode;
request.country = this.taxInformation?.country;
if (this.organizationId == null) {
return this.apiService.postAccountPayment(request);
} else {
request.taxId = this.taxInfoComponent.taxFormGroup?.value.taxId;
request.state = this.taxInfoComponent.taxFormGroup?.value.state;
request.line1 = this.taxInfoComponent.taxFormGroup?.value.line1;
request.line2 = this.taxInfoComponent.taxFormGroup?.value.line2;
request.city = this.taxInfoComponent.taxFormGroup?.value.city;
request.state = this.taxInfoComponent.taxFormGroup?.value.state;
request.taxId = this.taxInformation?.taxId;
request.state = this.taxInformation?.state;
request.line1 = this.taxInformation?.line1;
request.line2 = this.taxInformation?.line2;
request.city = this.taxInformation?.city;
request.state = this.taxInformation?.state;
return this.organizationApiService.updatePayment(this.organizationId, request);
}
});
@@ -83,8 +109,9 @@ export class AdjustPaymentDialogComponent {
this.dialogRef.close(AdjustPaymentDialogResult.Adjusted);
};
changeCountry() {
if (this.taxInfoComponent.taxInfo.country === "US") {
taxInformationChanged(event: TaxInformation) {
this.taxInformation = event;
if (event.country === "US") {
this.paymentComponent.hideBank = !this.organizationId;
} else {
this.paymentComponent.hideBank = true;