Skip to content

Commit

Permalink
NTR: handle response
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik authored and boxblinkracer committed Sep 18, 2023
1 parent 6d42fc8 commit 41a4029
Showing 1 changed file with 29 additions and 56 deletions.
85 changes: 29 additions & 56 deletions src/Resources/views/mollie/pos/checkout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 41a4029

Please sign in to comment.