diff --git a/jslib b/jslib index 9c44fc1329..36e65f08ca 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 9c44fc1329b9595560462ffb7cd4d32bb0e22a68 +Subproject commit 36e65f08cad6cebdb5b90c88a68360296e8ff2ec diff --git a/src/app/settings/adjust-payment.component.ts b/src/app/settings/adjust-payment.component.ts index 2f871cdb66..53953c1e6a 100644 --- a/src/app/settings/adjust-payment.component.ts +++ b/src/app/settings/adjust-payment.component.ts @@ -39,8 +39,9 @@ export class AdjustPaymentComponent { async submit() { try { const request = new PaymentRequest(); - this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { - request.paymentToken = token; + this.formPromise = this.paymentComponent.createPaymentToken().then((result) => { + request.paymentToken = result[0]; + request.paymentMethodType = result[1]; if (this.organizationId == null) { return this.apiService.postAccountPayment(request); } else { diff --git a/src/app/settings/create-organization.component.ts b/src/app/settings/create-organization.component.ts index 19491c7f29..f25662d370 100644 --- a/src/app/settings/create-organization.component.ts +++ b/src/app/settings/create-organization.component.ts @@ -128,7 +128,7 @@ export class CreateOrganizationComponent implements OnInit { } else { return this.paymentComponent.createPaymentToken(); } - }).then((token: string) => { + }).then((tokenResult) => { if (this.selfHosted) { const fd = new FormData(); fd.append('license', files[0]); @@ -145,7 +145,8 @@ export class CreateOrganizationComponent implements OnInit { if (this.plan === 'free') { request.planType = PlanType.Free; } else { - request.paymentToken = token; + request.paymentToken = tokenResult[0]; + request.paymentMethodType = tokenResult[1]; request.businessName = this.ownedBusiness ? this.businessName : null; request.additionalSeats = this.additionalSeats; request.additionalStorageGb = this.additionalStorage; diff --git a/src/app/settings/payment.component.ts b/src/app/settings/payment.component.ts index 1c8b77c5ac..1ff2ed1d9b 100644 --- a/src/app/settings/payment.component.ts +++ b/src/app/settings/payment.component.ts @@ -4,6 +4,8 @@ import { OnInit, } from '@angular/core'; +import { PaymentMethodType } from 'jslib/enums/paymentMethodType'; + import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; const Keys = { @@ -149,20 +151,22 @@ export class PaymentComponent implements OnInit { } } - createPaymentToken(): Promise { + createPaymentToken(): Promise<[string, PaymentMethodType]> { return new Promise((resolve, reject) => { if (this.method === 'paypal') { this.btInstance.requestPaymentMethod().then((payload: any) => { - resolve(payload.nonce); + resolve([payload.nonce, PaymentMethodType.PayPal]); }).catch((err: any) => { reject(err.message); }); } else if (this.method === 'card' || this.method === 'bank') { + let type = PaymentMethodType.Card; let sourceObj: any = null; let createObj: any = null; if (this.method === 'card') { sourceObj = this.stripeCardNumberElement; } else { + type = PaymentMethodType.BankAccount; sourceObj = 'bank_account'; createObj = this.bank; } @@ -170,7 +174,7 @@ export class PaymentComponent implements OnInit { if (result.error) { reject(result.error.message); } else if (result.token && result.token.id != null) { - resolve(result.token.id); + resolve([result.token.id, type]); } else { reject(); } diff --git a/src/app/settings/premium.component.ts b/src/app/settings/premium.component.ts index 55596d317c..f94ec47632 100644 --- a/src/app/settings/premium.component.ts +++ b/src/app/settings/premium.component.ts @@ -76,9 +76,10 @@ export class PremiumComponent implements OnInit { return this.finalizePremium(); }); } else { - this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { + this.formPromise = this.paymentComponent.createPaymentToken().then((result) => { const fd = new FormData(); - fd.append('paymentToken', token); + fd.append('paymentMethodType', result[1].toString()); + fd.append('paymentToken', result[0]); fd.append('additionalStorageGb', (this.additionalStorage || 0).toString()); return this.apiService.postPremium(fd); }).then(() => {