From fbd620074bd7cbb76569acbc3b368c0b07909f16 Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 9 Jun 2026 14:09:45 -0300 Subject: [PATCH] set invoice mail --- app.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index d2e0b13..b01af7a 100644 --- a/app.js +++ b/app.js @@ -22,7 +22,7 @@ const REFERRAL_URL = `${API_BASE}/etc/referral`; // POST {referrer,friend_name,f // WIZZARD=false is written via AGENT_INFO_URL (POST { uuid, key, value }) 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}/account/invoice-email`; // POST {email, invoice_email} +const INVOICE_EMAIL_URL = `${API_BASE}/user`; // POST {email, invoice_email} const CONTRACT_EXTEND_URL = "https://derez.ai"; // ← replace with Stripe payment link const CONTRACT_CANCEL_URL = "https://derez.ai"; // ← replace with Stripe cancellation link @@ -1122,15 +1122,28 @@ async function saveInvoiceEmail() { async function loadInvoices() { const body = document.getElementById("invoices-body"); + if (!body) return; body.innerHTML = '
'; try { const res = await apiFetch( `${INVOICES_URL}?email=${encodeURIComponent(currentEmail || "")}`, ); if (!res.ok) throw new Error(`HTTP ${res.status}`); - const data = await res.json(); - renderInvoices(Array.isArray(data) ? data : []); + let data = await res.json(); + dbg("\u2190 Invoices", data); + // unwrap n8n envelope: [{json:{...}}] → [{...}] + if (Array.isArray(data)) { + data = data.map((item) => + item && typeof item === "object" && "json" in item ? item.json : item, + ); + } else if (data && typeof data === "object" && "json" in data) { + data = [data.json]; + } else { + data = []; + } + renderInvoices(data); } catch (err) { + dbg("\u2190 Invoices error", err.message); body.innerHTML = '

Could not load invoices.

'; }