From 68fa5e1e4d49f2c802356ebdcd2dd414927f94e1 Mon Sep 17 00:00:00 2001 From: yixian Date: Tue, 14 Apr 2020 15:41:09 +0800 Subject: [PATCH] payment ui --- .../static/templates/payment/v1/card_pay.js | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/ui/static/templates/payment/v1/card_pay.js b/src/main/ui/static/templates/payment/v1/card_pay.js index 725460eb4..c4aed4789 100644 --- a/src/main/ui/static/templates/payment/v1/card_pay.js +++ b/src/main/ui/static/templates/payment/v1/card_pay.js @@ -1,7 +1,10 @@ $(function () { let $container = $('.card-input-box')[0]; + let ctrl = {ready: false, pending: false} let cardFrame = window.channel_account_id ? new TokenInputFrame($container, window.channel_account_id) : new CardInputFrame($container); + let $errorMsgBox = $('#errorMsgBox'); cardFrame.onSuccess = function (secretData) { + ctrl.pending = true; $.ajax({ url: 'commit', data: JSON.stringify(secretData), @@ -11,10 +14,11 @@ $(function () { startCheckOrder(window.client_moniker, window.partner_order_id); }, error: function (jqXHR) { + ctrl.pending = false; let errorText = jqXHR.responseText; let err = JSON.parse(errorText); - if(err){ - $('#errorMsgBox').text(err.message).show(); + if (err) { + $errorMsgBox.text(err.message).show(); } } }) @@ -25,16 +29,26 @@ $(function () { border: 'none', borderRadius: '10px' }; - cardFrame.onReady = function(){ - $('#readyModal').hide() + cardFrame.onReady = function () { + $('#readyModal').hide(); + $('#payBtn').removeAttr('disabled'); + ctrl.ready = true; }; cardFrame.onError = function (msg) { - $('#errorMsgBox').text(msg).show(); + $errorMsgBox.text(msg).show(); }; cardFrame.show(); $('#payBtn').click(function () { - $('#errorMsgBox').hide(); + if (!ctrl.ready) { + $errorMsgBox.text('Loading...').show(); + return; + } + if (ctrl.pending) { + $errorMsgBox.text('Pending...').show(); + return; + } + $errorMsgBox.hide(); cardFrame.commit(); });