Skip to content

Instantly share code, notes, and snippets.

@bespalown
Created August 31, 2015 16:28
Show Gist options
  • Save bespalown/6aa77498bb18996c77bf to your computer and use it in GitHub Desktop.
Save bespalown/6aa77498bb18996c77bf to your computer and use it in GitHub Desktop.
$(function () {
var checkoutWindow;
var statusInterval;
var timeoutInterval;
var expired = false;
var sec = 5;
var intervalId = setInterval(function () {
sec = sec - 1;
btn.value = 'Автопереход через ' + sec + ' сек.';
if (sec == 0) {
clearInterval(intervalId);
$('#checkoutOrderData').submit();
}
}, 1000);
$('#checkoutOrderData').submit(function () {
if (checkoutWindow && !checkoutWindow.closed)
checkoutWindow.close();
if (statusInterval)
window.clearInterval(statusInterval);
if (timeoutInterval)
window.clearInterval(timeoutInterval);
$('#info').css('display', 'none');
$('#processing').css('display', 'block');
checkoutWindow = window.open('', 'checkoutWindow', 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=1, Width=800, Height=600');
if (checkoutWindow) {
$('#infoText').html('Ожидание подтверждения...');
var windowInterval = window.setInterval(function () {
if (checkoutWindow == null || checkoutWindow.closed) {
window.clearInterval(windowInterval);
$('#infoText').html('Ожидание поступления платежа...');
}
}, 500);
var checkTimeoutHandler = function () {
expired = true;
console.log('expired');
window.clearInterval(timeoutInterval);
};
var statusHandler = function () {
$.ajax({
contentType: "application/json",
type: 'GET',
cache: false,
url: '/checkout/refill/PayU/CreditCardRUB/PayURUB/58937407/State?payment=Wallet.WhiteLabel.Core.Refill.AgentPayment',
success: function (data) {
console.log(JSON.stringify(data));
if (data.paymentState === "Paid")
{
checkoutWindow.close();
window.clearInterval(statusInterval);
$('#checkoutOrderData').remove();
$('#success').css('display', 'block');
window.location.href = '/checkout/refill/PayU/CreditCardRUB/PayURUB/58937407/State?payment=Wallet.WhiteLabel.Core.Refill.AgentPayment';
}
if (data.paymentState === "Processing")
{
if (!timeoutInterval)
timeoutInterval = window.setInterval(checkTimeoutHandler, 60000);
}
if (data.paymentState === "CreateError" || data.paymentState === "CheckError" || data.paymentState === "ProcessError")
{
checkoutWindow.close();
if (timeoutInterval)
window.clearInterval(timeoutInterval);
window.clearInterval(statusInterval);
$('#checkoutOrderData').remove();
$('#failure').css('display', 'block');
}
if (expired)
{
window.clearInterval(statusInterval);
if (timeoutInterval)
window.clearInterval(timeoutInterval);
$('#checkoutOrderData').remove();
$('#timeout').css('display', 'block');
}
}
});
};
statusInterval = window.setInterval(statusHandler, 5000);
} else {
alert("Вы должны разрешить всплывающие окна для данного сайта");
}
});
$('#tryAgainBtn').click(function () {
$('#checkoutOrderData').submit();
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment