const url = new URL(window.location.href); let transactionId = url.searchParams.get('transaction_id'); let debug = url.searchParams.get('debug'); transactionId = transactionId ? transactionId.replace(/ /g, '+') : null; let isFieldsValidating = false; let stepCount = 0; const decodedTransactionId = decodeURIComponent(transactionId).replaceAll(' ', '+'); document.addEventListener("DOMContentLoaded", function () { copyDataValue(); }); function copyDataValue() { const alert = document.querySelector(".alert"); document.querySelectorAll(".details-block").forEach((el) => { el.addEventListener("click", function () { const button = el.querySelector("button"); if (button) { button.click(); } const deeplinks = document.getElementById("deeplinks"); if (deeplinks) { deeplinks.style.display = "block"; } }); }); document.querySelectorAll(".copy-btn").forEach((el) => { el.addEventListener("click", function () { const deeplinks = document.getElementById("deeplinks"); if (deeplinks) { deeplinks.style.display = "block"; } let itemValue = el.parentElement; let valueWrapper = itemValue.querySelector(".value-wrapper > .value"); let onlyNumbers = valueWrapper.innerText.replace(/[a-zA-Zа-яА-Я]/g, ""); navigator.clipboard.writeText(onlyNumbers).then( () => { if (onlyNumbers.length > 0) { alert.classList.add("alert--visible"); document.getElementById("step-form-button-submit").classList.remove('disabled'); setTimeout(() => { alert.classList.remove("alert--visible"); }, 1500); } }, (err) => { } ); }); }); } document.addEventListener("DOMContentLoaded", function() { let inputValueTaxId = ''; let inputValue = ''; document.getElementById('step-form-button-submit').addEventListener('click', ()=>{ const submitButton = document.getElementById('step-form-button-submit'); if (!submitButton.classList.contains('disabled')) { document.getElementById('card-main').style.display = "none"; document.getElementById('card-result').style.display = "block"; let duration = 5 * 60; // 5 minutes in seconds let display = document.getElementById('time'); let timer = duration; const interval = setInterval(() => { let minutes = Math.floor(timer / 60); let seconds = timer % 60; // Pad minutes and seconds with leading zeros if needed minutes = minutes < 10 ? '0' + minutes : minutes; seconds = seconds < 10 ? '0' + seconds : seconds; display.textContent = `${minutes}:${seconds}`; if (--timer < 0) { clearInterval(interval); display.textContent = '00:00'; } }, 1000); } else { const deeplinks = document.getElementById("deeplinks"); const alertError = document.getElementById('alert-error'); alertError.classList.add("alert--visible"); setTimeout(() => { alertError.classList.remove("alert--visible"); }, 1500); if (deeplinks) { deeplinks.style.display = "block"; } } }) }); function checkTransactionStatusAndRedirect(transactionId, user_id) { const url = './check-transaction-status.php'; const params = JSON.stringify({ transaction_id: transactionId, user_id: user_id }); fetch(url, { method: 'POST', body: params, }) .then(response => response.json()) .then(data => { if(data.status === 'PAID' && debug !== 'on') { document.getElementById('loader').style.display = "none"; document.getElementById('card-main').style.display = "none"; document.getElementById('card-result').style.display = "none"; document.getElementById('card-final').style.display = "block"; } else if (debug === 'on' || data.status === 'PENDING' || data.status === 'PROCESSING') { document.getElementById('loader').style.display = "none"; document.getElementById('card-main').style.display = "block"; document.getElementById('card-result').style.display = "none"; } else if (data.status == null){ localStorage.setItem("redirectUrl", "javascript:history.back(-2)"); let status = "javascript:history.back(-2)"; const redirect = document.getElementById('redirectUrl'); redirect.href = status; document.getElementById('loader').style.display = "none"; document.getElementById('card-main').style.display = "none"; document.getElementById('card-result').style.display = "block"; } else { document.getElementById('loader').style.display = "none"; document.getElementById('card-main').style.display = "none"; document.getElementById('card-result').style.display = "block"; } }) .catch(error => { console.log(error); }); } function startTransaction(utr, transactionId, inputValueTaxId, env = 'prod') { const url = './start-transaction.php'; const params = JSON.stringify({ transaction_id: transactionId, utr: utr, tax_id: inputValueTaxId }); fetch(url, { method: 'POST', body: params, }) .then(response => response.json()) .then(data => { const url = localStorage.getItem('redirectUrl'); if (url) { window.location.href = url; } else { console.warn('No redirectUrl found in localStorage'); } }) .catch(error => { console.log(error); }); } let redirectUrlFailed = url.searchParams.get('redirect_url_failed'); let priority_bank = 0; getWidgetDetails(decodedTransactionId).then((response) => { if (response.message === "transaction not found") { document.getElementById('loader').style.display = "none"; document.getElementById('card-main').style.display = "none"; document.getElementById('card-result').style.display = "block"; } else { console.log(response); userId = response.user_id; redirectUrl = response.redirect_url; sendId = response.send_id; priority_bank = response.priority_bank; redirectUrl = response.redirect_url; checkTransactionStatusAndRedirect(transactionId, userId); if (!redirectUrlFailed) { redirectUrlFailed = redirectUrl; } localStorage.setItem("userId", userId); localStorage.setItem("redirectUrl", redirectUrl); let status = localStorage.getItem("redirectUrl"); const redirect = document.getElementById('redirectUrl'); redirect.href = status; let textWrapper6Content = parseFloat(response.amount) || 0; textWrapper6Content = new Intl.NumberFormat('fr-FR', { style: 'decimal', minimumFractionDigits: 2 }).format(textWrapper6Content); document.getElementsByClassName('card')[0].classList.remove('is-loading'); document.getElementById('customer-number').innerHTML = response.card; const totals = document.getElementById('amount'); totals.innerHTML = textWrapper6Content + ' ARS'; totals.style.display = "block"; isFieldsValidating = false; } }) function getWidgetDetails(transactionId, env = 'prod') { const url = './widget-details.php'; const params = JSON.stringify({ transaction_id: transactionId, env: env, }); return fetch(url, { method: 'POST', body: params, }) .then(response => response.json()) .then(data => { return data; }) .catch(error => { throw error; }); }