From 3c65dd874817cab1125c6554ec2cd5b5c761e697 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 9 Jun 2026 14:31:42 -0500 Subject: [PATCH] fix(checkout): pull company from intake_data (compliance has no customer_company col) compliance_orders stores company in intake_data JSON, not a column; read it from there (company/legal_name/entity_name) with graceful fallback. Fix e2e test seed accordingly. --- api/src/routes/checkout.ts | 13 ++++++++++++- scripts/e2e-paypal-portal-fix.mjs | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/src/routes/checkout.ts b/api/src/routes/checkout.ts index a88bc85..de035e0 100644 --- a/api/src/routes/checkout.ts +++ b/api/src/routes/checkout.ts @@ -188,7 +188,18 @@ async function ensureCompliancePortalUser( if (!first) return; const email = ((first.customer_email as string) || "").toLowerCase().trim(); const name = (first.customer_name as string) || email.split("@")[0] || "Customer"; - const company = (first.customer_company as string) || null; + // Company: compliance_orders has no customer_company column; it lives in + // intake_data. Fall back gracefully across order types. + let company: string | null = (first.customer_company as string) || null; + if (!company && first.intake_data) { + try { + const intake = typeof first.intake_data === "string" + ? JSON.parse(first.intake_data as string) + : (first.intake_data as Record); + company = (intake.company as string) || (intake.legal_name as string) + || (intake.entity_name as string) || null; + } catch { /* ignore */ } + } if (!email) return; // Skip only the genuine FMCSA-census placeholder, never a real customer who diff --git a/scripts/e2e-paypal-portal-fix.mjs b/scripts/e2e-paypal-portal-fix.mjs index 55aeec7..4399f96 100644 --- a/scripts/e2e-paypal-portal-fix.mjs +++ b/scripts/e2e-paypal-portal-fix.mjs @@ -25,9 +25,10 @@ try { await pool.query( `INSERT INTO compliance_orders (order_number, service_slug, service_name, customer_name, customer_email, - customer_company, payment_method, payment_status, total_cents, service_fee_cents) + payment_method, payment_status, total_cents, service_fee_cents, intake_data) VALUES ($1,'dot-drug-alcohol','DOT Drug & Alcohol Compliance Program', - 'E2E Tester','${EMAIL}','E2E Co','paypal','pending_payment',14900,14900)`, + 'E2E Tester','${EMAIL}','paypal','pending_payment',14900,14900, + '{"company":"E2E Co"}'::jsonb)`, [ORDER], ); ok(`seeded pending compliance order ${ORDER}`);