From 1d4d8d00e01f605ea53a51606d91ce090b86b187 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Sun, 25 Aug 2019 01:34:40 +0530 Subject: [PATCH] feat: link modals to server endpoints --- app/controllers/orders/pending.js | 51 +++++++++++++++---- app/templates/components/modals/paytm-otp.hbs | 2 +- .../modals/paytm-payment-options.hbs | 2 +- app/templates/orders/pending.hbs | 4 +- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/app/controllers/orders/pending.js b/app/controllers/orders/pending.js index bd2571ed0dd..c7cb4aa2343 100644 --- a/app/controllers/orders/pending.js +++ b/app/controllers/orders/pending.js @@ -51,20 +51,53 @@ export default Controller.extend({ this.notify.error(this.l10n.t(error.error)); } }, - openPaytmModal() { + async openPaytmModal() { // Model controller for PaytmModal - this.setProperties({ - 'isPaytmModalOpen': true - }); + try { + const res = await this.loader.post(`orders/${this.model.order.identifier}/paytm/initiate-transaction`); + this.setProperties({ + 'isPaytmModalOpen' : true, + 'txnToken' : res.body.txnToken + }); + } catch (error) { + this.notify.error(this.l10n.t(error.error)); + } }, - openOTPController() { + async openOTPController(mobileNumber) { // Modal controller for OTP step - this.setProperties({ - 'isPaytmModalOpen' : false, - 'isOTPModalOpen' : true - }); + try { + const payload = { + 'data': { + 'phone': mobileNumber + } + }; + await this.loader.post(`orders/${this.model.order.identifier}/paytm/send_otp/${this.txnToken}`, payload); + this.setProperties({ + 'isPaytmModalOpen' : false, + 'isOTPModalOpen' : true + }); + } catch (error) { + this.notify.error(this.l10n.t(error.error)); + } + }, + + async verifyOtp(OTP) { + try { + const payload = { + 'data': { + 'otp': OTP + } + }; + await this.loader.post(`orders/${this.model.order.identifier}/paytm/validate_otp/${this.txnToken}`, payload); + this.setProperties({ + 'isOTPModalOpen': false + }); + } catch (error) { + this.notify.error(this.l10n.t(error.error)); + } }, + processStripeToken(token) { // Send this token to server to process payment this.set('isLoading', true); diff --git a/app/templates/components/modals/paytm-otp.hbs b/app/templates/components/modals/paytm-otp.hbs index b8aa7f34568..1116a1a67f6 100644 --- a/app/templates/components/modals/paytm-otp.hbs +++ b/app/templates/components/modals/paytm-otp.hbs @@ -14,7 +14,7 @@ - diff --git a/app/templates/components/modals/paytm-payment-options.hbs b/app/templates/components/modals/paytm-payment-options.hbs index 8d44106f2ff..cf2375c4952 100644 --- a/app/templates/components/modals/paytm-payment-options.hbs +++ b/app/templates/components/modals/paytm-payment-options.hbs @@ -26,7 +26,7 @@ - diff --git a/app/templates/orders/pending.hbs b/app/templates/orders/pending.hbs index 07c22869ca8..aa4b1e38389 100644 --- a/app/templates/orders/pending.hbs +++ b/app/templates/orders/pending.hbs @@ -80,5 +80,5 @@ -{{modals/paytm-payment-options isLoading=isLoading isOpen=isPaytmModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency openOTPController=(action 'openOTPController')}} -{{modals/paytm-otp isLoading=isLoading isOpen=isOTPModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency}} +{{modals/paytm-payment-options isLoading=isLoading isOpen=isPaytmModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency openOTPController=(action 'openOTPController') txnToken=txnToken}} +{{modals/paytm-otp isLoading=isLoading isOpen=isOTPModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency txnToken=txnToken verifyOtp=(action 'verifyOtp')}}