1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 23:03:32 +00:00

[PM-18794] Allow provider payment method (#13825)

* Allow provider payment method

* Run prettier
This commit is contained in:
Alex Morask
2025-03-14 11:33:21 -04:00
committed by GitHub
parent 4d68952ef3
commit 2ecfac40b7
9 changed files with 198 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
<ng-container bitDialogContent>
<app-payment
[showAccountCredit]="false"
[showBankAccount]="!!organizationId"
[showBankAccount]="!!organizationId || !!providerId"
[initialPaymentMethod]="initialPaymentMethod"
></app-payment>
<app-manage-tax-information

View File

@@ -22,6 +22,7 @@ export interface AdjustPaymentDialogParams {
initialPaymentMethod?: PaymentMethodType;
organizationId?: string;
productTier?: ProductTierType;
providerId?: string;
}
export enum AdjustPaymentDialogResultType {
@@ -44,6 +45,7 @@ export class AdjustPaymentDialogComponent implements OnInit {
protected initialPaymentMethod: PaymentMethodType;
protected organizationId?: string;
protected productTier?: ProductTierType;
protected providerId?: string;
protected taxInformation: TaxInformation;
@@ -61,6 +63,7 @@ export class AdjustPaymentDialogComponent implements OnInit {
this.initialPaymentMethod = this.dialogParams.initialPaymentMethod ?? PaymentMethodType.Card;
this.organizationId = this.dialogParams.organizationId;
this.productTier = this.dialogParams.productTier;
this.providerId = this.dialogParams.providerId;
}
ngOnInit(): void {
@@ -73,6 +76,13 @@ export class AdjustPaymentDialogComponent implements OnInit {
.catch(() => {
this.taxInformation = new TaxInformation();
});
} else if (this.providerId) {
this.billingApiService
.getProviderTaxInformation(this.providerId)
.then((response) => (this.taxInformation = TaxInformation.from(response)))
.catch(() => {
this.taxInformation = new TaxInformation();
});
} else {
this.apiService
.getTaxInfo()
@@ -104,10 +114,12 @@ export class AdjustPaymentDialogComponent implements OnInit {
}
try {
if (!this.organizationId) {
await this.updatePremiumUserPaymentMethod();
} else {
if (this.organizationId) {
await this.updateOrganizationPaymentMethod();
} else if (this.providerId) {
await this.updateProviderPaymentMethod();
} else {
await this.updatePremiumUserPaymentMethod();
}
this.toastService.showToast({
@@ -137,20 +149,6 @@ export class AdjustPaymentDialogComponent implements OnInit {
await this.billingApiService.updateOrganizationPaymentMethod(this.organizationId, request);
};
protected get showTaxIdField(): boolean {
if (!this.organizationId) {
return false;
}
switch (this.productTier) {
case ProductTierType.Free:
case ProductTierType.Families:
return false;
default:
return true;
}
}
private updatePremiumUserPaymentMethod = async () => {
const { type, token } = await this.paymentComponent.tokenize();
@@ -168,6 +166,30 @@ export class AdjustPaymentDialogComponent implements OnInit {
await this.apiService.postAccountPayment(request);
};
private updateProviderPaymentMethod = async () => {
const paymentSource = await this.paymentComponent.tokenize();
const request = new UpdatePaymentMethodRequest();
request.paymentSource = paymentSource;
request.taxInformation = ExpandedTaxInfoUpdateRequest.From(this.taxInformation);
await this.billingApiService.updateProviderPaymentMethod(this.providerId, request);
};
protected get showTaxIdField(): boolean {
if (this.organizationId) {
switch (this.productTier) {
case ProductTierType.Free:
case ProductTierType.Families:
return false;
default:
return true;
}
} else {
return !!this.providerId;
}
}
static open = (
dialogService: DialogService,
dialogConfig: DialogConfig<AdjustPaymentDialogParams>,