diff --git a/api/src/routes/checkout.ts b/api/src/routes/checkout.ts index 5e30430..d11f4e0 100644 --- a/api/src/routes/checkout.ts +++ b/api/src/routes/checkout.ts @@ -1136,6 +1136,13 @@ export async function handlePaymentComplete( } catch (grantErr) { console.warn("[checkout] CDR grant issuance warning (non-fatal):", grantErr); } + + // Send intake/next-steps email for compliance orders + try { + await sendComplianceIntakeEmail(order_id, order_type, updated.rows); + } catch (intakeErr) { + console.error("[checkout] Compliance intake email failed (non-fatal):", intakeErr); + } } // ── Advance ERPNext Sales Order workflow (CRTC) ──────────────────────── @@ -1692,4 +1699,113 @@ router.get("/api/v1/checkout/crypto-details", async (req, res) => { } }); +// ─── Compliance intake email ──────────────────────────────────────────────── + +async function sendComplianceIntakeEmail( + orderId: string, + orderType: string, + orders: Record[], +): Promise { + if (!orders.length) return; + + const customerEmail = (orders[0].customer_email as string) || ""; + const customerName = (orders[0].customer_name as string) || ""; + if (!customerEmail) return; + + const firstName = customerName.split(" ")[0] || customerName; + const intake = orders[0].intake_data ? (typeof orders[0].intake_data === "string" ? JSON.parse(orders[0].intake_data as string) : orders[0].intake_data) as Record : {}; + const entityName = (intake.entity_name as string) || customerName; + const frn = (intake.frn as string) || ""; + + // Build service list + const serviceLines = orders + .map(o => `
  • ${o.service_name}
  • `) + .join("\n"); + + // Check if any 499-A service is included + const has499 = orders.some(o => + ((o.service_slug as string) || "").includes("499") || + ((o.service_name as string) || "").toLowerCase().includes("499"), + ); + + const usacSection = has499 ? ` +
    +

    Action Required: USAC E-File Delegation

    +

    + To prepare and file your Form 499-A, we need read access to your USAC E-File account. + Please delegate access to our filing agent: +

    +
      +
    1. Log in to USAC E-File
    2. +
    3. Go to Account Settings → Delegate Access
    4. +
    5. Add delegate email: filings@performancewest.net
    6. +
    7. Grant read and file permissions
    8. +
    9. Reply to this email to confirm delegation is complete
    10. +
    +

    + If you have multiple years of missed filings, each year must be filed separately. + We will review your history and contact you with pricing for any additional years. +

    +
    ` : ""; + + const { sendEmail } = await import("../email.js"); + await sendEmail({ + to: customerEmail, + subject: `Next Steps — ${entityName || "Your"} FCC Compliance Order`, + html: ` + + + +
    + + + + + +
    + Performance West — Compliance Services +
     
    + +

    We're Getting Started

    +

    Hi ${firstName}, thank you for your order. Here's what happens next.

    + + + + ${entityName ? `` : ""} + +
    +

    Order

    +

    ${orderId}

    +
    +

    Entity

    +

    ${entityName}${frn ? ` (FRN: ${frn})` : ""}

    +
    +

    Services Ordered

    +
      ${serviceLines}
    +
    + + ${usacSection} + +

    What to Expect

    +

    1. We will review your compliance status within 1 business day.

    +

    2. If we need any additional information, we will email you.

    +

    3. You will receive a confirmation for each filing as it is completed.

    + ${has499 ? `

    4. For 499-A filings, please complete the USAC delegation above so we can begin.

    ` : ""} + +

    + Questions? Reply to this email or contact us at + info@performancewest.net + or 1-888-411-0383. +

    + +
    +

    Performance West Inc. · performancewest.net · 1-888-411-0383

    +
    +
    +`, + }); + + console.log(`[checkout] Compliance intake email sent to ${customerEmail} for ${orderId}`); +} + export default router;