import { Component, EventEmitter, Input, Output } from "@angular/core"; import { lastValueFrom } from "rxjs"; import { DialogService } from "@bitwarden/components"; import { SharedModule } from "../../../shared"; import { BitwardenSubscriber } from "../../types"; import { MaskedPaymentMethod } from "../types"; import { ChangePaymentMethodDialogComponent } from "./change-payment-method-dialog.component"; @Component({ selector: "app-display-payment-method", template: `

{{ "paymentMethod" | i18n }}

@if (paymentMethod) { @switch (paymentMethod.type) { @case ("bankAccount") { @if (paymentMethod.hostedVerificationUrl) {

{{ "verifyBankAccountWithStripe" | i18n }} {{ "verifyNow" | i18n }}

}

{{ paymentMethod.bankName }}, *{{ paymentMethod.last4 }} @if (paymentMethod.hostedVerificationUrl) { - {{ "unverified" | i18n }} }

} @case ("card") {

@let brandIcon = getBrandIconForCard(); @if (brandIcon !== null) { } @else { } {{ paymentMethod.brand | titlecase }}, *{{ paymentMethod.last4 }}, {{ paymentMethod.expiration }}

} @case ("payPal") {

{{ paymentMethod.email }}

} } } @else {

{{ "noPaymentMethod" | i18n }}

} @let key = paymentMethod ? "changePaymentMethod" : "addPaymentMethod";
`, standalone: true, imports: [SharedModule], }) export class DisplayPaymentMethodComponent { @Input({ required: true }) subscriber!: BitwardenSubscriber; @Input({ required: true }) paymentMethod!: MaskedPaymentMethod | null; @Output() updated = new EventEmitter(); protected availableCardIcons: Record = { amex: "card-amex", diners: "card-diners-club", discover: "card-discover", jcb: "card-jcb", mastercard: "card-mastercard", unionpay: "card-unionpay", visa: "card-visa", }; constructor(private dialogService: DialogService) {} changePaymentMethod = async (): Promise => { const dialogRef = ChangePaymentMethodDialogComponent.open(this.dialogService, { data: { subscriber: this.subscriber, }, }); const result = await lastValueFrom(dialogRef.closed); if (result?.type === "success") { this.updated.emit(result.paymentMethod); } }; protected getBrandIconForCard = (): string | null => { if (this.paymentMethod?.type !== "card") { return null; } return this.paymentMethod.brand in this.availableCardIcons ? this.availableCardIcons[this.paymentMethod.brand] : null; }; }