2018-06-28 20:05:04 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
import { Angulartics2 } from 'angulartics2';
|
|
|
|
|
|
|
|
import { BillingResponse } from 'jslib/models/response/billingResponse';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2019-09-19 21:46:33 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-06-28 20:05:04 +02:00
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
import { PaymentMethodType } from 'jslib/enums/paymentMethodType';
|
2019-02-09 06:19:54 +01:00
|
|
|
import { TransactionType } from 'jslib/enums/transactionType';
|
2019-02-18 21:28:23 +01:00
|
|
|
import { VerifyBankRequest } from 'jslib/models/request/verifyBankRequest';
|
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;
|
2018-06-28 20:05:04 +02:00
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
verifyBankPromise: Promise<any>;
|
2018-06-29 22:55:54 +02:00
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
constructor(protected apiService: ApiService, protected i18nService: I18nService,
|
2019-09-19 21:46:33 +02:00
|
|
|
protected analytics: Angulartics2, protected toasterService: ToasterService,
|
|
|
|
protected platformUtilsService: PlatformUtilsService) { }
|
2018-06-28 20:05:04 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2018-06-29 22:55:54 +02:00
|
|
|
await this.load();
|
|
|
|
this.firstLoaded = true;
|
2018-06-29 05:05:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
async load() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-18 21:28:23 +01:00
|
|
|
this.loading = true;
|
|
|
|
if (this.organizationId != null) {
|
|
|
|
this.billing = await this.apiService.getOrganizationBilling(this.organizationId);
|
2018-07-03 15:27:59 +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;
|
|
|
|
}
|
|
|
|
|
2019-02-18 21:28:23 +01:00
|
|
|
async verifyBank() {
|
2018-06-29 22:55:54 +02:00
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-02-18 21:28:23 +01:00
|
|
|
const request = new VerifyBankRequest();
|
|
|
|
request.amount1 = this.verifyAmount1;
|
|
|
|
request.amount2 = this.verifyAmount2;
|
|
|
|
this.verifyBankPromise = this.apiService.postOrganizationVerifyBank(this.organizationId, request);
|
|
|
|
await this.verifyBankPromise;
|
|
|
|
this.analytics.eventTrack.next({ action: 'Verified Bank Account' });
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('verifiedBankAccount'));
|
2018-06-29 22:55:54 +02:00
|
|
|
this.load();
|
|
|
|
} catch { }
|
|
|
|
}
|
|
|
|
|
2019-02-20 23:33:05 +01:00
|
|
|
addCredit() {
|
2019-09-19 21:46:33 +02:00
|
|
|
if (this.paymentSourceInApp) {
|
|
|
|
this.platformUtilsService.showDialog(this.i18nService.t('cannotPerformInAppPurchase'));
|
|
|
|
return;
|
|
|
|
}
|
2019-02-20 23:33:05 +01:00
|
|
|
this.showAddCredit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeAddCredit(load: boolean) {
|
|
|
|
this.showAddCredit = false;
|
|
|
|
if (load) {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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'));
|
|
|
|
return;
|
|
|
|
}
|
2018-06-30 19:36:39 +02:00
|
|
|
this.showAdjustPayment = true;
|
|
|
|
}
|
2018-06-29 22:55:54 +02:00
|
|
|
|
2018-06-30 19:36:39 +02:00
|
|
|
closePayment(load: boolean) {
|
|
|
|
this.showAdjustPayment = false;
|
|
|
|
if (load) {
|
|
|
|
this.load();
|
|
|
|
}
|
2018-06-29 22:55:54 +02:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:34:57 +01:00
|
|
|
get isCreditBalance() {
|
|
|
|
return this.billing == null || this.billing.balance <= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get creditOrBalance() {
|
|
|
|
return Math.abs(this.billing != null ? this.billing.balance : 0);
|
|
|
|
}
|
|
|
|
|
2018-06-29 22:55:54 +02:00
|
|
|
get paymentSource() {
|
|
|
|
return this.billing != null ? this.billing.paymentSource : null;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:46:33 +02:00
|
|
|
get paymentSourceInApp() {
|
|
|
|
return this.paymentSource != null &&
|
|
|
|
(this.paymentSource.type === PaymentMethodType.AppleInApp ||
|
|
|
|
this.paymentSource.type === PaymentMethodType.GoogleInApp);
|
|
|
|
}
|
|
|
|
|
2019-02-09 06:19:54 +01:00
|
|
|
get invoices() {
|
|
|
|
return this.billing != null ? this.billing.invoices : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get transactions() {
|
|
|
|
return this.billing != null ? this.billing.transactions : null;
|
2018-06-29 22:55:54 +02:00
|
|
|
}
|
2018-06-28 20:05:04 +02:00
|
|
|
}
|