2018-06-28 20:05:04 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { PaymentMethodType } from "jslib-common/enums/paymentMethodType";
|
|
|
|
import { TransactionType } from "jslib-common/enums/transactionType";
|
|
|
|
import { VerifyBankRequest } from "jslib-common/models/request/verifyBankRequest";
|
2022-02-24 12:10:07 +01:00
|
|
|
import { BillingResponse } from "jslib-common/models/response/billingResponse";
|
2018-06-29 22:55:54 +02:00
|
|
|
|
2018-06-28 20:05:04 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-user-billing",
|
|
|
|
templateUrl: "user-billing.component.html",
|
|
|
|
})
|
|
|
|
export class UserBillingComponent 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;
|
2018-06-29 22:55:54 +02:00
|
|
|
billing: BillingResponse;
|
|
|
|
paymentMethodType = PaymentMethodType;
|
2019-02-09 06:19:54 +01:00
|
|
|
transactionType = TransactionType;
|
2019-02-18 21:28:23 +01:00
|
|
|
organizationId: string;
|
|
|
|
verifyAmount1: number;
|
|
|
|
verifyAmount2: number;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
verifyBankPromise: Promise<any>;
|
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,
|
2021-10-20 18:30:04 +02:00
|
|
|
private logService: LogService
|
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-06-28 20:05:04 +02:00
|
|
|
async ngOnInit() {
|
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;
|
|
|
|
if (this.organizationId != null) {
|
|
|
|
this.billing = await this.apiService.getOrganizationBilling(this.organizationId);
|
2018-06-29 22:55:54 +02:00
|
|
|
} else {
|
2019-02-18 21:28:23 +01:00
|
|
|
this.billing = await this.apiService.getUserBilling();
|
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
|
|
|
|
2019-02-20 23:33:05 +01:00
|
|
|
async verifyBank() {
|
2019-09-19 21:46:33 +02:00
|
|
|
if (this.loading) {
|
|
|
|
return;
|
2019-02-20 23:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const request = new VerifyBankRequest();
|
2019-02-18 21:28:23 +01:00
|
|
|
request.amount1 = this.verifyAmount1;
|
2019-02-20 23:33:05 +01:00
|
|
|
request.amount2 = this.verifyAmount2;
|
2019-02-18 21:28:23 +01:00
|
|
|
this.verifyBankPromise = this.apiService.postOrganizationVerifyBank(
|
|
|
|
this.organizationId,
|
2021-12-17 15:57:11 +01:00
|
|
|
request
|
|
|
|
);
|
2019-02-20 23:33:05 +01:00
|
|
|
await this.verifyBankPromise;
|
|
|
|
this.platformUtilsService.showToast(
|
2021-12-17 15:57:11 +01:00
|
|
|
"success",
|
|
|
|
null,
|
2019-02-20 23:33:05 +01:00
|
|
|
this.i18nService.t("verifiedBankAccount")
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2019-02-20 23:33:05 +01:00
|
|
|
this.load();
|
|
|
|
} catch (e) {
|
2021-10-20 18:30:04 +02:00
|
|
|
this.logService.error(e);
|
2019-02-20 23:33:05 +01:00
|
|
|
}
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-09 06:19:54 +01:00
|
|
|
get invoices() {
|
2018-06-29 22:55:54 +02:00
|
|
|
return this.billing != null ? this.billing.invoices : null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 06:19:54 +01:00
|
|
|
get transactions() {
|
|
|
|
return this.billing != null ? this.billing.transactions : null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-28 20:05:04 +02:00
|
|
|
}
|