diff --git a/index.html b/index.html index 6433660..43b4d99 100644 --- a/index.html +++ b/index.html @@ -432,8 +432,24 @@ let dateStr = q.created_at || q.date || ""; if(dateStr && dateStr.includes('T')) dateStr = dateStr.split('T')[0].split('-').reverse().join('/'); + // 🛑 LÓGICA STRIPE: Creamos el botón rápido si está firmado, la empresa tiene Stripe y NO está pagado + let bSet = globalCompanyData?.billing_settings || {}; + if (typeof bSet === 'string') { try { bSet = JSON.parse(bSet); } catch(e) {} } + const stripeEnabled = bSet.stripe_enabled && bSet.stripe_pk; + + const isSigned = (q.status === 'accepted' || q.status === 'converted'); + let quickPayButton = ''; + + if (stripeEnabled && isSigned && q.status !== 'paid') { + quickPayButton = ` + + `; + } + // 🛑 FIX: Calcar los colores y estados del escritorio - let statusBadge = ""; + let statusBadge = ""; if (!q.status || q.status === 'pending') { statusBadge = ` Pte. Resolver`; } else if (q.status === 'accepted' || q.status === 'converted') { @@ -463,6 +479,7 @@ ${dateStr} ${amountStr}€ + ${quickPayButton} `; }); @@ -693,6 +710,26 @@ } } + // 💳 LANZAR PAGO RÁPIDO DESDE LA TARJETA EXTERNA + async function quickPayStripe(id) { + showToast("⏳ Redirigiendo a pasarela segura..."); + try { + const res = await fetch(`${API_URL}/public/portal/${urlToken}/budget/${id}/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; + } else { + showToast(data.error || "❌ Error al iniciar el pago."); + } + } catch (e) { + showToast("❌ Error de conexión con el banco."); + } + } + async function generatePDF(id) { const budget = currentQuotes.find(b => b.id === id); if(!budget) return showToast("❌ Error: Presupuesto no encontrado");