2018-06-28 20:05:04 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
2022-05-09 14:21:52 +02:00
|
|
|
import { Router } from "@angular/router";
|
2018-06-28 20:05:04 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { PaymentMethodType } from "@bitwarden/common/enums/paymentMethodType";
|
|
|
|
import { BillingPaymentResponse } from "@bitwarden/common/models/response/billingPaymentResponse";
|
2018-06-29 22:55:54 +02:00
|
|
|
|
2018-06-28 20:05:04 +02:00
|
|
|
@Component({
|
2022-05-09 14:21:52 +02:00
|
|
|
selector: "app-payment-method",
|
|
|
|
templateUrl: "payment-method.component.html",
|
2018-06-28 20:05:04 +02:00
|
|
|
})
|
2022-05-09 14:21:52 +02:00
|
|
|
export class PaymentMethodComponent implements OnInit {
|
2018-06-29 22:55:54 +02:00
|
|
|
loading = false;
|
|
|
|
firstLoaded = false;
|
2018-06-30 19:36:39 +02:00
|
|
|
showAdjustPayment = false;
|
2019-02-20 23:33:05 +01:00
|
|
|
showAddCredit = false;
|
2022-05-09 14:21:52 +02:00
|
|
|
billing: BillingPaymentResponse;
|
2018-06-29 22:55:54 +02:00
|
|
|
paymentMethodType = PaymentMethodType;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
constructor(
|
|
|
|
protected apiService: ApiService,
|
|
|
|
protected i18nService: I18nService,
|
2021-12-07 20:41:45 +01:00
|
|
|
protected platformUtilsService: PlatformUtilsService,
|
2022-05-09 14:21:52 +02:00
|
|
|
private router: Router
|
2021-10-20 18:30:04 +02:00
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-06-28 20:05:04 +02:00
|
|
|
async ngOnInit() {
|
2022-05-09 14:21:52 +02:00
|
|
|
if (this.platformUtilsService.isSelfHost()) {
|
|
|
|
this.router.navigate(["/settings/subscription"]);
|
|
|
|
}
|
2018-06-29 22:55:54 +02:00
|
|
|
await this.load();
|
|
|
|
this.firstLoaded = true;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
async load() {
|
|
|
|
if (this.loading) {
|
2021-12-17 15:57:11 +01:00
|
|
|
return;
|
2018-06-29 05:05:49 +02:00
|
|
|
}
|
2019-02-18 21:28:23 +01:00
|
|
|
this.loading = true;
|
2022-05-09 14:21:52 +02:00
|
|
|
this.billing = await this.apiService.getUserBillingPayment();
|
2018-06-29 22:55:54 +02:00
|
|
|
this.loading = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-29 22:55:54 +02:00
|
|
|
|
|
|
|
addCredit() {
|
2019-09-19 21:46:33 +02:00
|
|
|
if (this.paymentSourceInApp) {
|
2019-09-19 22:34:44 +02:00
|
|
|
this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t("cannotPerformInAppPurchase"),
|
|
|
|
this.i18nService.t("addCredit"),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
"warning"
|
|
|
|
);
|
2019-09-19 21:46:33 +02:00
|
|
|
return;
|
2018-06-30 19:36:39 +02:00
|
|
|
}
|
2019-02-20 23:33:05 +01:00
|
|
|
this.showAddCredit = true;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-29 22:55:54 +02:00
|
|
|
|
2018-06-30 19:36:39 +02:00
|
|
|
closeAddCredit(load: boolean) {
|
|
|
|
this.showAddCredit = false;
|
|
|
|
if (load) {
|
|
|
|
this.load();
|
2018-06-29 22:55:54 +02:00
|
|
|
}
|
2019-02-18 23:34:57 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
changePayment() {
|
2019-09-19 21:46:33 +02:00
|
|
|
if (this.paymentSourceInApp) {
|
|
|
|
this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t("cannotPerformInAppPurchase"),
|
|
|
|
this.i18nService.t("changePaymentMethod"),
|
2019-02-09 06:19:54 +01:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
"warning"
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2019-02-09 06:19:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-06-30 19:36:39 +02:00
|
|
|
this.showAdjustPayment = true;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2019-02-09 06:19:54 +01:00
|
|
|
|
|
|
|
closePayment(load: boolean) {
|
|
|
|
this.showAdjustPayment = false;
|
2019-02-20 23:33:05 +01:00
|
|
|
if (load) {
|
2019-02-09 06:19:54 +01:00
|
|
|
this.load();
|
2018-06-29 22:55:54 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:34:57 +01:00
|
|
|
get isCreditBalance() {
|
|
|
|
return this.billing == null || this.billing.balance <= 0;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:34:57 +01:00
|
|
|
get creditOrBalance() {
|
|
|
|
return Math.abs(this.billing != null ? this.billing.balance : 0);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2019-09-19 21:46:33 +02:00
|
|
|
get paymentSource() {
|
2018-06-29 22:55:54 +02:00
|
|
|
return this.billing != null ? this.billing.paymentSource : null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2019-09-19 21:46:33 +02:00
|
|
|
get paymentSourceInApp() {
|
2021-12-17 15:57:11 +01:00
|
|
|
return (
|
2019-09-19 21:46:33 +02:00
|
|
|
this.paymentSource != null &&
|
|
|
|
(this.paymentSource.type === PaymentMethodType.AppleInApp ||
|
|
|
|
this.paymentSource.type === PaymentMethodType.GoogleInApp)
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
2018-06-28 20:05:04 +02:00
|
|
|
}
|