diff --git a/app.js b/app.js index 5701337..a11ef86 100644 --- a/app.js +++ b/app.js @@ -23,6 +23,7 @@ const REFERRAL_URL = `${API_BASE}/etc/referral`; // POST {referrer,friend_name,f const CREDITS_URL = `${API_BASE}/payment/credits`; // hidden form POST → 302 Stripe redirect const INVOICES_URL = `${API_BASE}/invoices`; // GET ?email= const INVOICE_EMAIL_URL = `${API_BASE}/user`; // POST {email, invoice_email} +const PORTAL_URL = `${API_BASE}/account/portal`; // GET ?email= → { url } const CONTRACT_EXTEND_URL = "https://derez.ai"; // ← replace with Stripe payment link const CONTRACT_CANCEL_URL = "https://derez.ai"; // ← replace with Stripe cancellation link @@ -1176,6 +1177,38 @@ async function saveInvoiceEmail() { } } +async function openBillingPortal() { + const btn = document.getElementById("portal-btn"); + if (!btn) return; + if (!currentEmail) { + toast("No email found. Please sign in again.", "warning"); + return; + } + btnLoad(btn, ""); + try { + const res = await apiFetch( + `${PORTAL_URL}?email=${encodeURIComponent(currentEmail)}`, + ); + if (!res.ok) throw new Error(`HTTP ${res.status}`); + const data = await res.json(); + dbg("\u2190 Portal", data); + const portalUrl = data.url || (data.data && data.data.url) || data; + if ( + portalUrl && + typeof portalUrl === "string" && + portalUrl.startsWith("http") + ) { + window.open(portalUrl, "_blank"); + } else { + throw new Error("No portal URL returned."); + } + } catch (err) { + toast(err.message, "error"); + } finally { + btnReset(btn); + } +} + async function loadInvoices() { const body = document.getElementById("invoices-body"); if (!body) return; diff --git a/index.html b/index.html index 3063e5d..a7984ec 100644 --- a/index.html +++ b/index.html @@ -917,6 +917,22 @@
+
+
+ Manage Subscriptions +
+
+ +
+
+
Affiliate Code