feat: auto-close qris modal and harden pakasir webhook matching
This commit is contained in:
@@ -557,6 +557,7 @@
|
||||
const cancelBtn = document.getElementById('qris-cancel');
|
||||
let currentOrderId = null;
|
||||
let modalOpen = false;
|
||||
let pollTimer = null;
|
||||
|
||||
const openModal = () => {
|
||||
if (!modal) return;
|
||||
@@ -569,6 +570,38 @@
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('flex');
|
||||
modalOpen = false;
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const startPolling = () => {
|
||||
if (!currentOrderId) return;
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
}
|
||||
pollTimer = setInterval(async () => {
|
||||
if (!modalOpen || !currentOrderId) return;
|
||||
try {
|
||||
const res = await fetch("{{ route('billing.pakasir.status') }}", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
...(csrf ? { 'X-CSRF-TOKEN': csrf } : {}),
|
||||
},
|
||||
body: JSON.stringify({ order_id: currentOrderId }),
|
||||
});
|
||||
const data = await res.json().catch(() => null);
|
||||
if (res.ok && data?.paid) {
|
||||
closeModal();
|
||||
window.location.href = "{{ route('dashboard.billing', ['status' => 'success']) }}";
|
||||
}
|
||||
} catch (e) {
|
||||
// keep polling silently
|
||||
}
|
||||
}, 4000);
|
||||
};
|
||||
|
||||
cancelBtn?.addEventListener('click', async () => {
|
||||
@@ -658,6 +691,7 @@
|
||||
qrExpiry.textContent = formatted ? `Expires ${formatted}` : 'Complete within 30 minutes';
|
||||
}
|
||||
openModal();
|
||||
startPolling();
|
||||
btn.disabled = false;
|
||||
btn.textContent = original;
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user