pass payment method type

This commit is contained in:
Kyle Spearrin 2019-02-19 17:06:01 -05:00
parent 0b1abc9ab0
commit 4fc90984d8
5 changed files with 17 additions and 10 deletions

2
jslib

@ -1 +1 @@
Subproject commit 9c44fc1329b9595560462ffb7cd4d32bb0e22a68 Subproject commit 36e65f08cad6cebdb5b90c88a68360296e8ff2ec

View File

@ -39,8 +39,9 @@ export class AdjustPaymentComponent {
async submit() { async submit() {
try { try {
const request = new PaymentRequest(); const request = new PaymentRequest();
this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { this.formPromise = this.paymentComponent.createPaymentToken().then((result) => {
request.paymentToken = token; request.paymentToken = result[0];
request.paymentMethodType = result[1];
if (this.organizationId == null) { if (this.organizationId == null) {
return this.apiService.postAccountPayment(request); return this.apiService.postAccountPayment(request);
} else { } else {

View File

@ -128,7 +128,7 @@ export class CreateOrganizationComponent implements OnInit {
} else { } else {
return this.paymentComponent.createPaymentToken(); return this.paymentComponent.createPaymentToken();
} }
}).then((token: string) => { }).then((tokenResult) => {
if (this.selfHosted) { if (this.selfHosted) {
const fd = new FormData(); const fd = new FormData();
fd.append('license', files[0]); fd.append('license', files[0]);
@ -145,7 +145,8 @@ export class CreateOrganizationComponent implements OnInit {
if (this.plan === 'free') { if (this.plan === 'free') {
request.planType = PlanType.Free; request.planType = PlanType.Free;
} else { } else {
request.paymentToken = token; request.paymentToken = tokenResult[0];
request.paymentMethodType = tokenResult[1];
request.businessName = this.ownedBusiness ? this.businessName : null; request.businessName = this.ownedBusiness ? this.businessName : null;
request.additionalSeats = this.additionalSeats; request.additionalSeats = this.additionalSeats;
request.additionalStorageGb = this.additionalStorage; request.additionalStorageGb = this.additionalStorage;

View File

@ -4,6 +4,8 @@ import {
OnInit, OnInit,
} from '@angular/core'; } from '@angular/core';
import { PaymentMethodType } from 'jslib/enums/paymentMethodType';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
const Keys = { const Keys = {
@ -149,20 +151,22 @@ export class PaymentComponent implements OnInit {
} }
} }
createPaymentToken(): Promise<string> { createPaymentToken(): Promise<[string, PaymentMethodType]> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.method === 'paypal') { if (this.method === 'paypal') {
this.btInstance.requestPaymentMethod().then((payload: any) => { this.btInstance.requestPaymentMethod().then((payload: any) => {
resolve(payload.nonce); resolve([payload.nonce, PaymentMethodType.PayPal]);
}).catch((err: any) => { }).catch((err: any) => {
reject(err.message); reject(err.message);
}); });
} else if (this.method === 'card' || this.method === 'bank') { } else if (this.method === 'card' || this.method === 'bank') {
let type = PaymentMethodType.Card;
let sourceObj: any = null; let sourceObj: any = null;
let createObj: any = null; let createObj: any = null;
if (this.method === 'card') { if (this.method === 'card') {
sourceObj = this.stripeCardNumberElement; sourceObj = this.stripeCardNumberElement;
} else { } else {
type = PaymentMethodType.BankAccount;
sourceObj = 'bank_account'; sourceObj = 'bank_account';
createObj = this.bank; createObj = this.bank;
} }
@ -170,7 +174,7 @@ export class PaymentComponent implements OnInit {
if (result.error) { if (result.error) {
reject(result.error.message); reject(result.error.message);
} else if (result.token && result.token.id != null) { } else if (result.token && result.token.id != null) {
resolve(result.token.id); resolve([result.token.id, type]);
} else { } else {
reject(); reject();
} }

View File

@ -76,9 +76,10 @@ export class PremiumComponent implements OnInit {
return this.finalizePremium(); return this.finalizePremium();
}); });
} else { } else {
this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { this.formPromise = this.paymentComponent.createPaymentToken().then((result) => {
const fd = new FormData(); 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()); fd.append('additionalStorageGb', (this.additionalStorage || 0).toString());
return this.apiService.postPremium(fd); return this.apiService.postPremium(fd);
}).then(() => { }).then(() => {