From 41a4029b32a019b4dd6d969b89f7de8900a33fc1 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Fri, 15 Sep 2023 12:01:20 +0200 Subject: [PATCH] NTR: handle response --- .../views/mollie/pos/checkout.html.twig | 85 +++++++------------ 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/src/Resources/views/mollie/pos/checkout.html.twig b/src/Resources/views/mollie/pos/checkout.html.twig index bfec5cf0b..9fb7d97a7 100644 --- a/src/Resources/views/mollie/pos/checkout.html.twig +++ b/src/Resources/views/mollie/pos/checkout.html.twig @@ -218,68 +218,41 @@ const loadingElements = Array.from(document.getElementsByClassName('loading')); const successElements = Array.from(document.getElementsByClassName('success')); const failedElements = Array.from(document.getElementsByClassName('failed')); - function requestStatus() { - const xhr = new XMLHttpRequest(); - xhr.open('GET', '/mollie/pos/{{ swOrderId }}/{{ molliePaymentId }}/status'); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onload = function (response) { - console.log(response.target.response); - const json = JSON.parse(response.target.response); - - if (json.ready) { - clearInterval(interval); - if(statusChangeButton !== null){ - statusChangeButton.style.display = 'none'; - } - loadingElements.forEach(function(element){ - element.style.display = 'none'; - }); - returnButton.style.display = 'block'; - returnButton.href= json.redirectUrl; - if(json.status === 'open' || json.status === 'paid'){ - successElements.forEach(function(element){ - element.style.display = 'block'; - }); - }else{ - failedElements.forEach(function(element){ - element.style.display = 'block'; - }); - } + function handleResponse(response){ + console.log(response.target.response); + const json = JSON.parse(response.target.response); + if (json.ready) { + clearInterval(interval); + if(statusChangeButton !== null){ + statusChangeButton.style.display = 'none'; + } + loadingElements.forEach(function(element){ + element.style.display = 'none'; + }); + returnButton.style.display = 'block'; + returnButton.href= json.redirectUrl; + if(json.status === 'open' || json.status === 'paid'){ + successElements.forEach(function(element){ + element.style.display = 'block'; + }); + }else{ + failedElements.forEach(function(element){ + element.style.display = 'block'; + }); } - }; - xhr.onerror = function (response) { - console.log(response.target.response); - const json = JSON.parse(response.target.response); + } + } + function requestStatus() { + const xhr = new XMLHttpRequest(); + xhr.open('GET', '/mollie/pos/{{ swOrderId }}/{{ molliePaymentId }}/status'); + xhr.setRequestHeader('Content-Type', 'application/json'); - if (json.ready) { - clearInterval(interval); - loadingElements.forEach(function(element){ - element.style.display = 'none'; - }); - if(statusChangeButton !== null){ - statusChangeButton.style.display = 'none'; - } - returnButton.style.display = 'block'; - returnButton.href= json.redirectUrl; - - - returnButton.style.display = 'block'; - returnButton.href= json.redirectUrl; - if(json.status === 'open' || json.status === 'paid'){ - successElements.forEach(function(element){ - element.style.display = 'block'; - }); - }else{ - failedElements.forEach(function(element){ - element.style.display = 'block'; - }); - } + xhr.onload = handleResponse; - } - }; + xhr.onerror = handleResponse; xhr.send(); }