File: /var/www/vhost/disk-apps/qas.sports-crowd.com/resources/views/paymentGateway/pay/js.blade.php
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
$(document).ready(function() {
function formatCurrency(value) {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: <?php echo json_encode($corporateIdentity->currency); ?>,
currencyDisplay: 'narrowSymbol',
minimumFractionDigits: <?php echo json_encode($corporateIdentity->minimum_fraction_digits); ?>,
maximumFractionDigits: <?php echo json_encode($corporateIdentity->maximum_fraction_digits); ?>,
}).format(value);
}
// Formatear precios en la sección de resumen
$('.price').each(function() {
let amountText = $(this).text();
let formatted = formatCurrency(amountText);
$(this).text(formatted);
});
});
// Temporizador 30 minutos
let time = <?php echo $paymentDetails->duration; ?>;
let timerInterval;
const timerEl = document.getElementById("timer");
function updateTimer() {
if (time <= 0) {
timerEl.textContent = "00:00:00";
clearInterval(timerInterval);
Swal.fire({
icon: 'error',
title: 'Tiempo agotado',
text: 'El tiempo para completar el pago ha expirado.',
showConfirmButton: true,
confirmButtonText: 'Aceptar',
confirmButtonColor: '<?php echo $corporateIdentity->btnBox_color; ?>',
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false
}).then(() => {
window.location.href = <?php echo json_encode($paymentDetails->return_page); ?>; // Redirigir a la página principal o a donde sea necesario
});
return;
}
let minutes = String(Math.floor(time / 60)).padStart(2, '0');
let seconds = String(time % 60).padStart(2, '0');
timerEl.textContent = `00:${minutes}:${seconds}`;
time--;
}
updateTimer();
timerInterval = setInterval(updateTimer, 1000);
// Habilitar botón de pago al seleccionar una pasarela
document.querySelectorAll('input[name="gateway"]').forEach(input => {
input.addEventListener('change', function() {
const continueBtn = document.querySelector('.continue-btn');
continueBtn.disabled = false;
continueBtn.style.backgroundColor = '<?php echo $corporateIdentity->btnBox_color; ?>';
// Scroll a la sección de resumen
document.querySelector('.summary-section').scrollIntoView({
behavior: 'smooth'
});
});
});
if (document.getElementById('pay-btn')) {
document.getElementById('pay-btn').addEventListener('click', async function(e) {
const selected = document.querySelector('input[name="gateway"]:checked');
if (!selected) {
Swal.fire({
icon: 'warning',
title: 'Selección de pasarela',
text: 'Por favor selecciona una pasarela de pago antes de continuar.',
showConfirmButton: true,
confirmButtonText: 'Aceptar',
confirmButtonColor: '<?php echo $corporateIdentity->btnBox_color; ?>',
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false
});
return;
}
const gateway = selected.value;
const urlComplement = "{{ $urlComplement }}";
const decodedString = urlComplement.replace(/&/g, "&");
window.location.href = `../../../store/webcheckout?paymentGatewayId=${gateway}${decodedString}`;
});
}
</script>