Eurobuilding Hotel & Suites Caracas
function isMobileView() { // Detectar dispositivos móviles return ( /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || window.innerWidth < 768 ) } function initializePaymentProcess(orderId) { const button = $("#pagar"); button.prop("disabled", false).css({ cursor: "pointer", background: "linear-gradient(135deg, #0079ff, #0051cc)", color: "white", }); $('#pagar') .off('click') .on('click', () => { handlePopUpOpen(orderId) }) }
function _dispatchSwalAlert({ status, amount, updatedAt, description }) {
Swal.fire({
title: `Payment ${status === "PAID" ? 'Successful' : 'Failed'}`,
html: `Order details:
Amount: ${amount}
Processed Time: ${updatedAt}
Concept: ${description}`,
icon: status === "PAID" ? 'success' : 'error',
confirmButtonText: 'OK'
});
}
async function cancelPayment(paymentId){ $.ajax({ url: "undefined/fast-payment/cancel-payment", type: "POST", contentType: "application/json", data: JSON.stringify({ paymentId, }), success: function (response) { console.log("Payment canceled succesfully"); }, error: function (xhr, status, error) { // Extract and parse the error message from the response const errorMessage = xhr.responseText ? JSON.parse(xhr.responseText).message : 'An unknown error occurred'; reject(new Error(errorMessage)); // Reject with the error message } }); }
function addMessageListeners(paymentId, popup) { let isMessageListenerExecuted = false; window.addEventListener("message", function (event) { if (event.origin !== "undefined") { console.warn("Unauthorized origin:", event.origin); return; } isMessageListenerExecuted = true; if (event.data?.status === "payment-success-cc") { console.log("Payment successful", event.data?.paymentDetails); _dispatchSwalAlert(event.data?.paymentDetails); } else if (event.data?.status === "payment-failed-cc") { console.log("Payment failed", event.data?.paymentDetails); _dispatchSwalAlert(event.data?.paymentDetails); } window.removeEventListener("message", () => { }); });
const interval = setInterval(() => { if (popup.closed && !isMessageListenerExecuted) { clearInterval(interval); cancelPayment(paymentId); } }, 1000); }
function handlePopUpOpen(paymentId) { const width = 600; const height = 800; const left = (window.screen.width / 2) - (width / 2); const top = (window.screen.height / 2) - (height / 2);
const redirectUrl = `undefined/open/pay/fast/checkout?payment=${paymentId}`; const popup = window.open( redirectUrl, "PaymentWindow", `width=${width},height=${height},resizable,scrollbars,top=${top},left=${left}` ); addMessageListeners(paymentId, popup); }
function observeOrderIdChange() { const target = document.querySelector("#pagar");
if (!target) { console.error("Target element #pagar not found."); return; }
const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.type === "attributes" && mutation.attributeName === "data-order-id") { const orderId = target.getAttribute("data-order-id"); if (orderId) { console.log("Detected orderId change:", orderId); initializePaymentProcess(orderId); } } }); });
observer.observe(target, { attributes: true }); }
$(document).ready(() => { const button = $("#pagar"); // Disable the button initially button.prop("disabled", true).css({ cursor: "not-allowed", background: "gray", color: "lightgray", }); observeOrderIdChange(); });
Gracias por su Pedido
Para finalizar su compra debe reportar el pago:
