// ============================ // CONFIG // ============================ const SUPABASE_URL = 'https://your-project-id.supabase.co'; const SUPABASE_ANON_KEY = 'your-anon-key'; const supabaseClient = supabase.createClient( SUPABASE_URL, SUPABASE_ANON_KEY ); const stripe = Stripe('pk_live_51SQSHyHXPMNwqdWuX9ndcrTT1eZ1kbGUpk0mXwRwaQbqiWLPpUXwQrromjY16keMZCu69FZYgFf7zPxgIbvf585i00qCKiJAau'); let checkoutInstance = null; // ============================ // INIT USER IDENTITY // ============================ document.addEventListener('DOMContentLoaded', async () => { lucide.createIcons(); const badge = document.getElementById('identity-badge'); const light = document.getElementById('identity-light'); const { data: { user }, error } = await supabaseClient.auth.getUser(); if (!user || error) { badge.innerText = "Vault Unlinked // Redirecting..."; setTimeout(() => window.location.href = '/login', 800); return; } sessionStorage.setItem('gev_user_email', user.email); badge.innerText = `Sovereign Link: ${user.email.toUpperCase()}`; light.classList.add('bg-[#00FF00]', 'shadow-[0_0_20px_#00FF00]'); }); // ============================ // HANDLE PAYMENT INJECTION // ============================ async function handleInjection(tierKey, e) { const btn = e.currentTarget; const email = sessionStorage.getItem('gev_user_email'); if (!email) { alert("Session expired. Please log in again."); window.location.href = "/login"; return; } const modal = document.getElementById('checkout-modal'); const container = document.getElementById('checkout-container'); btn.disabled = true; btn.innerText = "SYNCHRONIZING..."; try { const res = await fetch('/api/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tier: tierKey, email }) }); const data = await res.json(); if (!data.success || !data.clientSecret) { throw new Error(data.message || "Checkout init failed"); } modal.classList.add('active'); container.innerHTML = ""; checkoutInstance = await stripe.initEmbeddedCheckout({ clientSecret: data.clientSecret }); checkoutInstance.mount("#checkout-container"); btn.innerText = "INJECTED ✓"; btn.disabled = false; } catch (err) { console.error(err); btn.innerText = "PIPELINE ERROR"; btn.disabled = false; alert("Payment system error. Try again."); } } // ============================ // CLOSE CHECKOUT // ============================ function closeCheckout() { const modal = document.getElementById('checkout-modal'); modal.classList.remove('active'); if (checkoutInstance) { checkoutInstance.destroy(); checkoutInstance = null; } }