diff --git a/index2.html b/index2.html index 8ef6cda..4e8136d 100644 --- a/index2.html +++ b/index2.html @@ -173,13 +173,20 @@
-
- - + +
+ + +
@@ -520,9 +527,22 @@ const btnContainer = document.getElementById('qmDecisionButtons'); const msgContainer = document.getElementById('qmStatusMessage'); const sigArea = document.getElementById('qmSignatureArea'); + const btnStripe = document.getElementById('btnStripePay'); sigArea.classList.add('hidden'); + // 🛑 LÓGICA STRIPE: Evaluar si se debe mostrar el botón de pago + let bSet = globalCompanyData?.billing_settings || {}; + if (typeof bSet === 'string') { try { bSet = JSON.parse(bSet); } catch(e) {} } + + if (bSet.stripe_enabled && bSet.stripe_pk) { + btnStripe.classList.remove('hidden'); + btnStripe.classList.add('flex'); + } else { + btnStripe.classList.add('hidden'); + btnStripe.classList.remove('flex'); + } + if (!q.status || q.status === 'pending') { btnContainer.classList.remove('hidden'); msgContainer.classList.add('hidden'); @@ -633,6 +653,26 @@ // --- LÓGICA DE PDF AÑADIDA --- let allServicesGlobalBackup = []; // <--- Variable para no perder los datos del cliente + // 💳 LANZAR PAGO CON STRIPE + async function payWithStripe() { + showToast("⏳ Redirigiendo a pasarela segura..."); + try { + const res = await fetch(`${API_URL}/public/portal/${urlToken}/budget/${currentBudgetIdForSignature}/checkout`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' } + }); + const data = await res.json(); + + if (data.ok && data.checkout_url) { + window.location.href = data.checkout_url; // Redirigimos a la ventana de pago de Stripe + } else { + showToast(data.error || "❌ Error al iniciar el pago.", true); + } + } catch (e) { + showToast("❌ Error de conexión con el banco.", true); + } + } + async function generatePDF(id) { const budget = currentQuotes.find(b => b.id === id); if(!budget) return showToast("❌ Error: Presupuesto no encontrado");