Passer au contenu principal
Store
Delivery
Contact Us
FAQ
EN
TH
FR
Menu
(function () { var BACKEND = 'https://mistercochon-backend.onrender.com'; var overlay = null; var pollTimer = null; var injected = false; function removeOverlay() { if (overlay) { overlay.remove(); overlay = null; } if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } injected = false; } function showQR(amount, qrUrl, intentId) { if (overlay) return; var amtFmt = parseFloat(amount).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); overlay = document.createElement('div'); overlay.id = 'mc-pp-overlay'; overlay.innerHTML = [ '
', '
', '
🐷 Mister Cochon
', '
Paiement PromptPay
', '
...
', '
Montant total TTC
', '
', '
', '
', '
1. Ouvrez votre app bancaire
', '
2. Scannez le QR PromptPay
', '
3. Confirmez le montant
', '
En attente du paiement...
', '
Annuler
', '
', '
' ].join(''); document.body.appendChild(overlay); overlay.querySelector('#mc-amt').textContent = '\u0E3F' + amtFmt; overlay.querySelector('#mc-qr-img').src = qrUrl; overlay.querySelector('#mc-pp-cancel').onclick = removeOverlay; pollTimer = setInterval(function () { fetch(BACKEND + '/check-intent/' + intentId) .then(function (r) { return r.json(); }) .then(function (d) { if (!d.paid) return; clearInterval(pollTimer); pollTimer = null; var st = overlay ? overlay.querySelector('#mc-pp-status') : null; if (st) st.innerHTML = '
Paiement recu !
'; setTimeout(function () { var btns = document.querySelectorAll('button'); for (var i = 0; i < btns.length; i++) { var t = (btns[i].textContent || '').trim().toLowerCase(); if (t.indexOf('order') !== -1 || t.indexOf('place') !== -1 || t.indexOf('passer') !== -1 || t.indexOf('confirm') !== -1 || t.indexOf('commande') !== -1) { btns[i].click(); break; } } removeOverlay(); }, 1500); }).catch(function () {}); }, 3000); } function doInject() { if (injected) return; injected = true; if (typeof Ecwid === 'undefined' || !Ecwid.Cart) { injected = false; return; } Ecwid.Cart.get(function (cart) { var total = cart.total || 0; if (total <= 0) { injected = false; return; } fetch(BACKEND + '/qr?amount=' + total) .then(function (r) { return r.json(); }) .then(function (data) { showQR(total, data.qr_url, data.intent_id); }) .catch(function (e) { injected = false; console.error('[MC]', e); }); }); } function waitForEcwid() { if (typeof Ecwid !== 'undefined' && Ecwid.OnPageLoaded) { Ecwid.OnPageLoaded.add(function (page) { if (page.type === 'CHECKOUT_PAYMENT_DETAILS') { injected = false; setTimeout(doInject, 600); } else { removeOverlay(); injected = false; } }); } else { setTimeout(waitForEcwid, 300); } } waitForEcwid(); })();