mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
[PM-11730] Remove feature flag: AC-2476-deprecate-stripe-sources-api (#13032)
* Remove FF from trial-billing-step.component * Remove FF from user-subscription.component * Remove FF from individual-billing-routing.module * Remove FF from organization-billing.service * Remove FF from organization-subscription-cloud.component * Remove FF from organization-billing-routing.mdoule * Remove FF from organization-plans.component * Remove FF from change-plan-dialog.component * Remove FF * Remove legacy payment.component * Rename V2: adjust-payment-dialog.component * Rename V2: adjust-storage-dialog.component * Rename V2: payment-label.component * Rename V2: payment.component * Rename V2: premium.component * Patrick's feedback
This commit is contained in:
@@ -1,59 +1,66 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
|
||||
import { Component, Inject, OnInit, ViewChild } from "@angular/core";
|
||||
import { FormGroup } from "@angular/forms";
|
||||
import { Component, forwardRef, Inject, OnInit, ViewChild } from "@angular/core";
|
||||
|
||||
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 { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions";
|
||||
import { PaymentMethodType, ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { TaxInformation } from "@bitwarden/common/billing/models/domain";
|
||||
import { ExpandedTaxInfoUpdateRequest } from "@bitwarden/common/billing/models/request/expanded-tax-info-update.request";
|
||||
import { PaymentRequest } from "@bitwarden/common/billing/models/request/payment.request";
|
||||
import { UpdatePaymentMethodRequest } from "@bitwarden/common/billing/models/request/update-payment-method.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";
|
||||
|
||||
export interface AdjustPaymentDialogData {
|
||||
organizationId: string;
|
||||
currentType: PaymentMethodType;
|
||||
export interface AdjustPaymentDialogParams {
|
||||
initialPaymentMethod?: PaymentMethodType;
|
||||
organizationId?: string;
|
||||
productTier?: ProductTierType;
|
||||
}
|
||||
|
||||
export enum AdjustPaymentDialogResult {
|
||||
Adjusted = "adjusted",
|
||||
Cancelled = "cancelled",
|
||||
export enum AdjustPaymentDialogResultType {
|
||||
Closed = "closed",
|
||||
Submitted = "submitted",
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: "adjust-payment-dialog.component.html",
|
||||
templateUrl: "./adjust-payment-dialog.component.html",
|
||||
})
|
||||
export class AdjustPaymentDialogComponent implements OnInit {
|
||||
@ViewChild(PaymentComponent, { static: true }) paymentComponent: PaymentComponent;
|
||||
@ViewChild(ManageTaxInformationComponent) taxInfoComponent: ManageTaxInformationComponent;
|
||||
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
|
||||
@ViewChild(forwardRef(() => ManageTaxInformationComponent))
|
||||
taxInfoComponent: ManageTaxInformationComponent;
|
||||
|
||||
organizationId: string;
|
||||
currentType: PaymentMethodType;
|
||||
paymentMethodType = PaymentMethodType;
|
||||
protected readonly PaymentMethodType = PaymentMethodType;
|
||||
protected readonly ResultType = AdjustPaymentDialogResultType;
|
||||
|
||||
protected DialogResult = AdjustPaymentDialogResult;
|
||||
protected formGroup = new FormGroup({});
|
||||
protected dialogHeader: string;
|
||||
protected initialPaymentMethod: PaymentMethodType;
|
||||
protected organizationId?: string;
|
||||
protected productTier?: ProductTierType;
|
||||
|
||||
protected taxInformation: TaxInformation;
|
||||
|
||||
constructor(
|
||||
private dialogRef: DialogRef,
|
||||
@Inject(DIALOG_DATA) protected data: AdjustPaymentDialogData,
|
||||
private apiService: ApiService,
|
||||
private i18nService: I18nService,
|
||||
private billingApiService: BillingApiServiceAbstraction,
|
||||
private organizationApiService: OrganizationApiServiceAbstraction,
|
||||
private configService: ConfigService,
|
||||
@Inject(DIALOG_DATA) protected dialogParams: AdjustPaymentDialogParams,
|
||||
private dialogRef: DialogRef<AdjustPaymentDialogResultType>,
|
||||
private i18nService: I18nService,
|
||||
private toastService: ToastService,
|
||||
) {
|
||||
this.organizationId = data.organizationId;
|
||||
this.currentType = data.currentType;
|
||||
const key = this.dialogParams.initialPaymentMethod ? "changePaymentMethod" : "addPaymentMethod";
|
||||
this.dialogHeader = this.i18nService.t(key);
|
||||
this.initialPaymentMethod = this.dialogParams.initialPaymentMethod ?? PaymentMethodType.Card;
|
||||
this.organizationId = this.dialogParams.organizationId;
|
||||
this.productTier = this.dialogParams.productTier;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -78,65 +85,92 @@ export class AdjustPaymentDialogComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
submit = async () => {
|
||||
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.taxInformation?.postalCode;
|
||||
request.country = this.taxInformation?.country;
|
||||
request.taxId = this.taxInformation?.taxId;
|
||||
if (this.organizationId == null) {
|
||||
return this.apiService.postAccountPayment(request);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
});
|
||||
await response;
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: null,
|
||||
message: this.i18nService.t("updatedPaymentMethod"),
|
||||
});
|
||||
this.dialogRef.close(AdjustPaymentDialogResult.Adjusted);
|
||||
};
|
||||
|
||||
taxInformationChanged(event: TaxInformation) {
|
||||
this.taxInformation = event;
|
||||
if (event.country === "US") {
|
||||
this.paymentComponent.hideBank = !this.organizationId;
|
||||
this.paymentComponent.showBankAccount = !!this.organizationId;
|
||||
} else {
|
||||
this.paymentComponent.hideBank = true;
|
||||
if (this.paymentComponent.method === PaymentMethodType.BankAccount) {
|
||||
this.paymentComponent.method = PaymentMethodType.Card;
|
||||
this.paymentComponent.changeMethod();
|
||||
this.paymentComponent.showBankAccount = false;
|
||||
if (this.paymentComponent.selected === PaymentMethodType.BankAccount) {
|
||||
this.paymentComponent.select(PaymentMethodType.Card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected get showTaxIdField(): boolean {
|
||||
return !!this.organizationId;
|
||||
}
|
||||
}
|
||||
submit = async (): Promise<void> => {
|
||||
if (!this.taxInfoComponent.validate()) {
|
||||
this.taxInfoComponent.markAllAsTouched();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strongly typed helper to open a AdjustPaymentDialog
|
||||
* @param dialogService Instance of the dialog service that will be used to open the dialog
|
||||
* @param config Configuration for the dialog
|
||||
*/
|
||||
export function openAdjustPaymentDialog(
|
||||
dialogService: DialogService,
|
||||
config: DialogConfig<AdjustPaymentDialogData>,
|
||||
) {
|
||||
return dialogService.open<AdjustPaymentDialogResult>(AdjustPaymentDialogComponent, config);
|
||||
try {
|
||||
if (!this.organizationId) {
|
||||
await this.updatePremiumUserPaymentMethod();
|
||||
} else {
|
||||
await this.updateOrganizationPaymentMethod();
|
||||
}
|
||||
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: null,
|
||||
message: this.i18nService.t("updatedPaymentMethod"),
|
||||
});
|
||||
|
||||
this.dialogRef.close(AdjustPaymentDialogResultType.Submitted);
|
||||
} catch (error) {
|
||||
const msg = typeof error == "object" ? error.message : error;
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
title: null,
|
||||
message: this.i18nService.t(msg) || msg,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private updateOrganizationPaymentMethod = async () => {
|
||||
const paymentSource = await this.paymentComponent.tokenize();
|
||||
|
||||
const request = new UpdatePaymentMethodRequest();
|
||||
request.paymentSource = paymentSource;
|
||||
request.taxInformation = ExpandedTaxInfoUpdateRequest.From(this.taxInformation);
|
||||
|
||||
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();
|
||||
|
||||
const request = new PaymentRequest();
|
||||
request.paymentMethodType = type;
|
||||
request.paymentToken = token;
|
||||
request.country = this.taxInformation.country;
|
||||
request.postalCode = this.taxInformation.postalCode;
|
||||
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;
|
||||
await this.apiService.postAccountPayment(request);
|
||||
};
|
||||
|
||||
static open = (
|
||||
dialogService: DialogService,
|
||||
dialogConfig: DialogConfig<AdjustPaymentDialogParams>,
|
||||
) =>
|
||||
dialogService.open<AdjustPaymentDialogResultType>(AdjustPaymentDialogComponent, dialogConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user