Skip to content

Commit 80a8416

Browse files
uds5501abhinavk96
authored andcommitted
feat: link modals to server endpoints (#3476)
1 parent 01ab287 commit 80a8416

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

app/controllers/orders/pending.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,53 @@ export default Controller.extend({
5151
this.notify.error(this.l10n.t(error.error));
5252
}
5353
},
54-
openPaytmModal() {
54+
async openPaytmModal() {
5555
// Model controller for PaytmModal
56-
this.setProperties({
57-
'isPaytmModalOpen': true
58-
});
56+
try {
57+
const res = await this.loader.post(`orders/${this.model.order.identifier}/paytm/initiate-transaction`);
58+
this.setProperties({
59+
'isPaytmModalOpen' : true,
60+
'txnToken' : res.body.txnToken
61+
});
62+
} catch (error) {
63+
this.notify.error(this.l10n.t(error.error));
64+
}
5965
},
6066

61-
openOTPController() {
67+
async openOTPController(mobileNumber) {
6268
// Modal controller for OTP step
63-
this.setProperties({
64-
'isPaytmModalOpen' : false,
65-
'isOTPModalOpen' : true
66-
});
69+
try {
70+
const payload = {
71+
'data': {
72+
'phone': mobileNumber
73+
}
74+
};
75+
await this.loader.post(`orders/${this.model.order.identifier}/paytm/send_otp/${this.txnToken}`, payload);
76+
this.setProperties({
77+
'isPaytmModalOpen' : false,
78+
'isOTPModalOpen' : true
79+
});
80+
} catch (error) {
81+
this.notify.error(this.l10n.t(error.error));
82+
}
83+
},
84+
85+
async verifyOtp(OTP) {
86+
try {
87+
const payload = {
88+
'data': {
89+
'otp': OTP
90+
}
91+
};
92+
await this.loader.post(`orders/${this.model.order.identifier}/paytm/validate_otp/${this.txnToken}`, payload);
93+
this.setProperties({
94+
'isOTPModalOpen': false
95+
});
96+
} catch (error) {
97+
this.notify.error(this.l10n.t(error.error));
98+
}
6799
},
100+
68101
processStripeToken(token) {
69102
// Send this token to server to process payment
70103
this.set('isLoading', true);

app/templates/components/modals/paytm-otp.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<button type="button" class="ui black button" {{action 'close'}}>
1515
{{t 'Cancel'}}
1616
</button>
17-
<button class="ui green button">
17+
<button {{action verifyOtp otp}} class="ui green button">
1818
{{t 'Verify'}}
1919
</button>
2020
</div>

app/templates/components/modals/paytm-payment-options.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<button type="button" class="ui black button" {{action 'close'}}>
2727
{{t 'Cancel'}}
2828
</button>
29-
<button {{action openOTPController}} class="ui green button" disabled={{not isWalletSelected}}>
29+
<button {{action openOTPController mobileNumber}} class="ui green button" disabled={{not isWalletSelected}}>
3030
{{t 'Proceed'}}
3131
</button>
3232
</div>

app/templates/orders/pending.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@
8080
</div>
8181
</div>
8282
</div>
83-
{{modals/paytm-payment-options isLoading=isLoading isOpen=isPaytmModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency openOTPController=(action 'openOTPController')}}
84-
{{modals/paytm-otp isLoading=isLoading isOpen=isOTPModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency}}
83+
{{modals/paytm-payment-options isLoading=isLoading isOpen=isPaytmModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency openOTPController=(action 'openOTPController') txnToken=txnToken}}
84+
{{modals/paytm-otp isLoading=isLoading isOpen=isOTPModalOpen amount=model.order.amount currency=model.order.event.paymentCurrency txnToken=txnToken verifyOtp=(action 'verifyOtp')}}

0 commit comments

Comments
 (0)