Subversion Repositories SmartDukaan

Rev

Rev 36851 | Rev 37458 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36851 Rev 37194
Line 444... Line 444...
444
            btn.text('Resend OTP (' + remaining + 's)');
444
            btn.text('Resend OTP (' + remaining + 's)');
445
        }
445
        }
446
    }, 1000);
446
    }, 1000);
447
}
447
}
448
 
448
 
-
 
449
function showOtpStatus(color, text) {
-
 
450
    $('#otp_status').show().css('color', color).text(text);
-
 
451
}
-
 
452
 
449
$(document).on('click', "#LOI_otp", function () {
453
$(document).on('click', "#LOI_otp", function () {
450
    let btn = $(this);
454
    let btn = $(this);
451
    let loiId = btn.val();
455
    let loiId = btn.val();
452
    if (otpCountdownTimer) return;
456
    if (otpCountdownTimer) return;
453
    let isResend = btn.text().indexOf('Resend') >= 0;
457
    let isResend = btn.text().indexOf('Resend') >= 0;
454
    if (!isResend && !confirm("Are you sure to send OTP ?")) return;
458
    if (!isResend && !confirm("Are you sure to send OTP ?")) return;
-
 
459
    let previousText = btn.text();
455
    btn.prop('disabled', true).text('Sending...');
460
    btn.prop('disabled', true).text('Sending...');
456
    doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
461
    doPostAjaxRequestHandler(`${context}/loiAcceptanceOtp?loiId=` + loiId,
457
        function (response) {
462
        function (response) {
-
 
463
            let res = null;
-
 
464
            try {
-
 
465
                res = (typeof response === 'string' ? JSON.parse(response) : response);
-
 
466
            } catch (e) {
-
 
467
                res = null;
-
 
468
            }
-
 
469
            if (!res || typeof res.status === 'undefined') {
-
 
470
                showOtpStatus('red', 'Could not confirm the OTP was sent. Check with tech support before retrying.');
-
 
471
                btn.prop('disabled', false).text(previousText);
-
 
472
                return;
-
 
473
            }
-
 
474
            if (res.status && res.sent) {
458
            $('#otp_status').show().text('OTP Sent Successfully!');
475
                showOtpStatus('green', res.message || 'OTP sent.');
-
 
476
                startResendCountdown(btn);
-
 
477
            } else if (res.status) {
-
 
478
                // Accepted, but nothing was dispatched - the previous OTP is still valid (resend throttle).
-
 
479
                showOtpStatus('#c07000', 'No new OTP sent - ' + (res.message || 'the previous OTP is still valid.'));
459
            startResendCountdown(btn);
480
                startResendCountdown(btn);
-
 
481
            } else {
-
 
482
                showOtpStatus('red', 'OTP NOT sent - ' + (res.message || 'unknown reason.'));
-
 
483
                btn.prop('disabled', false).text(previousText);
-
 
484
            }
-
 
485
        },
-
 
486
        function (xhr, msg) {
-
 
487
            showOtpStatus('red', 'OTP NOT sent - request failed (' + xhr.status + ').');
-
 
488
            btn.prop('disabled', false).text(previousText);
460
        });
489
        });
461
});
490
});
462
 
491
 
463
//confirmPayment
492
//confirmPayment
464
$(document).on('click', ".paymentConfirmBtn", function () {
493
$(document).on('click', ".paymentConfirmBtn", function () {