diff --git a/jslib b/jslib index 2b931963cd..3362334d2c 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2b931963cd8dbebdcbdd6a418ac3ef72adb73539 +Subproject commit 3362334d2ce2220fb0d1af322d88c9efec37763d diff --git a/src/app/settings/add-credit.component.html b/src/app/settings/add-credit.component.html index 70b0c68f29..6fdaf38594 100644 --- a/src/app/settings/add-credit.component.html +++ b/src/app/settings/add-credit.component.html @@ -4,17 +4,16 @@
+ [value]="paymentMethodType.PayPal" [(ngModel)]="method">
-
@@ -45,12 +44,12 @@ - - + + - + diff --git a/src/app/settings/add-credit.component.ts b/src/app/settings/add-credit.component.ts index 68764642a0..552d8980cc 100644 --- a/src/app/settings/add-credit.component.ts +++ b/src/app/settings/add-credit.component.ts @@ -11,12 +11,14 @@ import { import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; -import { I18nService } from 'jslib/abstractions/i18n.service'; +import { ApiService } from 'jslib/abstractions/api.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { UserService } from 'jslib/abstractions/user.service'; import { PaymentMethodType } from 'jslib/enums/paymentMethodType'; +import { BitPayInvoiceRequest } from 'jslib/models/request/bitPayInvoiceRequest'; + import { WebConstants } from '../../services/webConstants'; @Component({ @@ -37,14 +39,18 @@ export class AddCreditComponent implements OnInit { ppButtonFormAction = WebConstants.paypal.buttonActionProduction; ppButtonBusinessId = WebConstants.paypal.businessIdProduction; ppButtonCustomField: string; - ppReturnUrl: string; ppLoading = false; subject: string; + returnUrl: string; formPromise: Promise; - constructor(private userService: UserService, private i18nService: I18nService, + private userId: string; + private name: string; + private email: string; + + constructor(private userService: UserService, private apiService: ApiService, private analytics: Angulartics2, private toasterService: ToasterService, - platformUtilsService: PlatformUtilsService) { + private platformUtilsService: PlatformUtilsService) { if (platformUtilsService.isDev()) { this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox; this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox; @@ -60,17 +66,19 @@ export class AddCreditComponent implements OnInit { const org = await this.userService.getOrganization(this.organizationId); if (org != null) { this.subject = org.name; + this.name = org.name; } } else { if (this.creditAmount == null) { this.creditAmount = '10.00'; } - const userId = await this.userService.getUserId(); + this.userId = await this.userService.getUserId(); this.subject = await this.userService.getEmail(); - this.ppButtonCustomField = 'user_id:' + userId; + this.email = this.subject; + this.ppButtonCustomField = 'user_id:' + this.userId; } this.ppButtonCustomField += ',account_credit:1'; - this.ppReturnUrl = window.location.href; + this.returnUrl = window.location.href; } async submit() { @@ -83,19 +91,30 @@ export class AddCreditComponent implements OnInit { this.ppLoading = true; return; } + if (this.method === PaymentMethodType.BitPay) { + try { + const req = new BitPayInvoiceRequest(); + req.email = this.email; + req.name = this.name; + req.credit = true; + req.amount = this.creditAmountNumber; + req.organizationId = this.organizationId; + req.userId = this.userId; + req.returnUrl = this.returnUrl; + this.formPromise = this.apiService.postBitPayInvoice(req); + const bitPayUrl: string = await this.formPromise; + this.platformUtilsService.launchUri(bitPayUrl); + } catch { } + return; + } try { this.analytics.eventTrack.next({ action: 'Added Credit', }); - this.toasterService.popAsync('success', null, this.i18nService.t('updatedPaymentMethod')); this.onAdded.emit(); } catch { } } - changeMethod() { - // TODO: - } - cancel() { this.onCanceled.emit(); } @@ -113,4 +132,13 @@ export class AddCreditComponent implements OnInit { } catch { } this.creditAmount = ''; } + + get creditAmountNumber(): number { + if (this.creditAmount != null && this.creditAmount !== '') { + try { + return parseFloat(this.creditAmount); + } catch { } + } + return null; + } }