Skip to content

Commit

Permalink
feat: link modals to server endpoints (#3476)
Browse files Browse the repository at this point in the history
  • Loading branch information
uds5501 authored and abhinavk96 committed Aug 26, 2019
1 parent 01ab287 commit 80a8416
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
51 changes: 42 additions & 9 deletions app/controllers/orders/pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/modals/paytm-otp.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<button type="button" class="ui black button" {{action 'close'}}>
{{t 'Cancel'}}
</button>
<button class="ui green button">
<button {{action verifyOtp otp}} class="ui green button">
{{t 'Verify'}}
</button>
</div>
2 changes: 1 addition & 1 deletion app/templates/components/modals/paytm-payment-options.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<button type="button" class="ui black button" {{action 'close'}}>
{{t 'Cancel'}}
</button>
<button {{action openOTPController}} class="ui green button" disabled={{not isWalletSelected}}>
<button {{action openOTPController mobileNumber}} class="ui green button" disabled={{not isWalletSelected}}>
{{t 'Proceed'}}
</button>
</div>
4 changes: 2 additions & 2 deletions app/templates/orders/pending.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@
</div>
</div>
</div>
{{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')}}

0 comments on commit 80a8416

Please sign in to comment.