{"id":7,"date":"2026-03-17T21:59:53","date_gmt":"2026-03-17T21:59:53","guid":{"rendered":"https:\/\/preciojusto.uy\/?page_id=7"},"modified":"2026-03-17T21:59:53","modified_gmt":"2026-03-17T21:59:53","slug":"pago","status":"publish","type":"page","link":"https:\/\/preciojusto.uy\/?page_id=7","title":{"rendered":"Procesar Pago"},"content":{"rendered":"<!DOCTYPE html>\n<html>\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Confirmar compra<\/title>\n    <style>\n        body { font-family: Arial; padding: 20px; max-width: 800px; margin: 0 auto; background: #f5f5f5; }\n        .cart-container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }\n        table { width: 100%; border-collapse: collapse; margin: 20px 0; }\n        th, td { padding: 12px; border-bottom: 1px solid #ddd; text-align: left; }\n        .total { font-size: 24px; font-weight: bold; text-align: right; margin: 20px 0; }\n        .pay-btn, .cancel-btn { padding: 15px 30px; font-size: 18px; border-radius: 4px; cursor: pointer; width: 100%; margin-top: 10px; text-align: center; display: inline-block; }\n        .pay-btn { background: #28a745; color: white; border: none; }\n        .pay-btn:hover { background: #218838; }\n        .cancel-btn { background: #dc3545; color: white; text-decoration: none; border: none; }\n        .cancel-btn:hover { background: #c82333; text-decoration: none; }\n        .buttons { display: flex; gap: 10px; margin-top: 20px; }\n        .buttons form, .buttons a { flex: 1; }\n        .remove-btn { background: #dc3545; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }\n        .remove-btn:hover { background: #c82333; }\n        .quantity-input { width: 60px; padding: 5px; text-align: center; }\n        .single-message { background: #e7f3ff; padding: 10px; border-radius: 5px; margin-bottom: 20px; text-align: center; }\n        #loading { text-align: center; padding: 20px; }\n    <\/style>\n<\/head>\n<body>\n    <div id=\"loading\">Cargando carrito...<\/div>\n    <div id=\"cart-content\" style=\"display:none;\">\n        <div class=\"cart-container\">\n            <h1>Resumen de compra<\/h1>\n            <div id=\"single-message\" style=\"display:none;\" class=\"single-message\">\n                Esta m\u00e1quina solo permite un producto por compra.\n            <\/div>\n            <table id=\"cart-table\">\n                <thead>\n                    <tr>\n                        <th>Producto<\/th>\n                        <th>Precio unitario<\/th>\n                        <th>Cantidad<\/th>\n                        <th>Subtotal<\/th>\n                        <th><\/th>\n                    <\/thead>\n                <tbody id=\"cart-body\"><\/tbody>\n            <\/table>\n            <div class=\"total\" id=\"total\"><\/div>\n\n            <div class=\"buttons\">\n                <form method=\"post\" action=\"https:\/\/preciojusto.uy\/wp-admin\/admin-post.php\" id=\"payment-form\" style=\"flex:1;\">\n                    <input type=\"hidden\" name=\"action\" value=\"pjiot_process_payment\">\n                    <input type=\"hidden\" name=\"machine_id\" id=\"machine_id\" value=\"\">\n                    <input type=\"hidden\" name=\"cart\" id=\"cart-field\" value=\"\">\n                    <p>\n                        <label>Email (para confirmaci\u00f3n):<\/label><br>\n                        <input type=\"email\" name=\"email\" required style=\"width: 100%; padding: 8px;\">\n                    <\/p>\n                    <button type=\"submit\" class=\"pay-btn\">Pagar ahora<\/button>\n                <\/form>\n\n                <a href=\"#\" id=\"cancel-btn\" class=\"cancel-btn\" style=\"text-align: center; line-height: 48px;\">Cancelar compra<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <script>\n    document.addEventListener('DOMContentLoaded', function() {\n        let cart = JSON.parse(sessionStorage.getItem('pjiot_cart') || '[]');\n        const machineId = sessionStorage.getItem('pjiot_machine_id');\n        const layoutType = sessionStorage.getItem('pjiot_machine_layout_type') || 'grid';\n\n        if (!cart.length || !machineId) {\n            alert('No hay productos en el carrito. Ser\u00e1s redirigido.');\n            window.location.href = '\/';\n            return;\n        }\n\n        document.getElementById('loading').style.display = 'none';\n        document.getElementById('cart-content').style.display = 'block';\n\n        \/\/ Si es m\u00e1quina single, mostrar mensaje\n        const isSingle = layoutType === 'single';\n        if (isSingle) {\n            document.getElementById('single-message').style.display = 'block';\n        }\n\n        function renderCart() {\n            const tbody = document.getElementById('cart-body');\n            tbody.innerHTML = '';\n            let total = 0;\n\n            \/\/ Agrupar productos por ID\n            const grouped = {};\n            cart.forEach(item => {\n                const id = parseInt(item.id);\n                if (grouped[id]) {\n                    grouped[id].quantity += 1;\n                } else {\n                    grouped[id] = {\n                        id: id,\n                        name: item.name,\n                        price: parseFloat(item.price),\n                        quantity: 1,\n                        relay: parseInt(item.relay)\n                    };\n                }\n            });\n\n            \/\/ Si es m\u00e1quina single, limitar a solo el primer producto\n            let itemsToRender = grouped;\n            if (isSingle && Object.keys(grouped).length > 1) {\n                const firstId = Object.keys(grouped)[0];\n                itemsToRender = { [firstId]: grouped[firstId] };\n                alert('Esta m\u00e1quina solo permite un producto por compra. Solo se mantendr\u00e1 el primer producto.');\n                \/\/ Limpiar el carrito para que solo quede ese producto\n                cart = cart.filter(item => parseInt(item.id) === parseInt(firstId));\n                sessionStorage.setItem('pjiot_cart', JSON.stringify(cart));\n                renderCart(); \/\/ re-renderizar despu\u00e9s de limpiar\n                return;\n            }\n\n            for (let id in itemsToRender) {\n                const item = itemsToRender[id];\n                const subtotal = item.price * item.quantity;\n                total += subtotal;\n\n                const row = tbody.insertRow();\n                row.insertCell(0).textContent = item.name;\n                row.insertCell(1).textContent = '$' + item.price.toFixed(2);\n                const qtyCell = row.insertCell(2);\n                const input = document.createElement('input');\n                input.type = 'number';\n                input.value = item.quantity;\n                input.min = 1;\n                input.className = 'quantity-input';\n                \n                \/\/ Si es m\u00e1quina single, deshabilitar el input y fijar cantidad 1\n                if (isSingle) {\n                    input.value = 1;\n                    input.disabled = true;\n                } else {\n                    input.addEventListener('change', function() {\n                        let newQty = parseInt(this.value);\n                        if (isNaN(newQty) || newQty < 1) {\n                            newQty = 1;\n                            this.value = 1;\n                        }\n                        const template = cart.find(original => parseInt(original.id) === item.id);\n                        if (!template) return;\n                        let newCart = cart.filter(original => parseInt(original.id) !== item.id);\n                        for (let i = 0; i < newQty; i++) {\n                            newCart.push({\n                                id: parseInt(template.id),\n                                name: template.name,\n                                price: parseFloat(template.price),\n                                relay: parseInt(template.relay)\n                            });\n                        }\n                        cart = newCart;\n                        sessionStorage.setItem('pjiot_cart', JSON.stringify(cart));\n                        renderCart();\n                    });\n                }\n                qtyCell.appendChild(input);\n                row.insertCell(3).textContent = '$' + subtotal.toFixed(2);\n                const removeCell = row.insertCell(4);\n                const removeBtn = document.createElement('button');\n                removeBtn.textContent = 'Eliminar';\n                removeBtn.className = 'remove-btn';\n                if (!isSingle) {\n                    removeBtn.addEventListener('click', function() {\n                        cart = cart.filter(original => parseInt(original.id) !== item.id);\n                        sessionStorage.setItem('pjiot_cart', JSON.stringify(cart));\n                        renderCart();\n                    });\n                } else {\n                    removeBtn.disabled = true;\n                    removeBtn.style.opacity = '0.5';\n                }\n                removeCell.appendChild(removeBtn);\n            }\n\n            document.getElementById('total').innerText = 'Total: $' + total.toFixed(2);\n            document.getElementById('machine_id').value = machineId;\n            document.getElementById('cart-field').value = JSON.stringify(cart);\n        }\n\n        renderCart();\n\n        \/\/ Bot\u00f3n de cancelar compra\n        const cancelBtn = document.getElementById('cancel-btn');\n        if (cancelBtn) {\n            cancelBtn.addEventListener('click', function(e) {\n                e.preventDefault();\n                \/\/ Limpiar sessionStorage del carrito para esta m\u00e1quina\n                const cartKey = 'pjiot_cart_' + machineId;\n                sessionStorage.removeItem(cartKey);\n                sessionStorage.removeItem('pjiot_cart'); \/\/ tambi\u00e9n la global por si acaso\n                sessionStorage.removeItem('pjiot_machine_id');\n                \/\/ Redirigir a la p\u00e1gina de la m\u00e1quina (sin carrito)\n                window.location.href = '\/?page_id=6&machine_id=' + machineId;\n            });\n        }\n    });\n    <\/script>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/preciojusto.uy\/index.php?rest_route=\/wp\/v2\/pages\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preciojusto.uy\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/preciojusto.uy\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/preciojusto.uy\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/preciojusto.uy\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/preciojusto.uy\/index.php?rest_route=\/wp\/v2\/pages\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/preciojusto.uy\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}