Add compliance intake email after payment
Sends next-steps email with services list, USAC delegation instructions for 499-A, and multi-year catch-up note. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3acdc68994
commit
28d82912f7
1 changed files with 116 additions and 0 deletions
|
|
@ -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<string, unknown>[],
|
||||
): Promise<void> {
|
||||
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<string, unknown> : {};
|
||||
const entityName = (intake.entity_name as string) || customerName;
|
||||
const frn = (intake.frn as string) || "";
|
||||
|
||||
// Build service list
|
||||
const serviceLines = orders
|
||||
.map(o => `<li style="margin:4px 0;font-size:14px;color:#374151;">${o.service_name}</li>`)
|
||||
.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 ? `
|
||||
<div style="background:#fef3c7;border:1px solid #fcd34d;border-radius:8px;padding:16px 20px;margin:20px 0;">
|
||||
<p style="margin:0 0 8px;font-size:14px;font-weight:700;color:#92400e;">Action Required: USAC E-File Delegation</p>
|
||||
<p style="margin:0 0 12px;font-size:13px;color:#78350f;line-height:1.5;">
|
||||
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:
|
||||
</p>
|
||||
<ol style="margin:0 0 12px;padding-left:20px;font-size:13px;color:#78350f;line-height:1.7;">
|
||||
<li>Log in to <a href="https://forms.universalservice.org" style="color:#1e40af;">USAC E-File</a></li>
|
||||
<li>Go to <strong>Account Settings → Delegate Access</strong></li>
|
||||
<li>Add delegate email: <strong>filings@performancewest.net</strong></li>
|
||||
<li>Grant <strong>read and file</strong> permissions</li>
|
||||
<li>Reply to this email to confirm delegation is complete</li>
|
||||
</ol>
|
||||
<p style="margin:0;font-size:12px;color:#92400e;">
|
||||
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.
|
||||
</p>
|
||||
</div>` : "";
|
||||
|
||||
const { sendEmail } = await import("../email.js");
|
||||
await sendEmail({
|
||||
to: customerEmail,
|
||||
subject: `Next Steps — ${entityName || "Your"} FCC Compliance Order`,
|
||||
html: `<!DOCTYPE html>
|
||||
<html><head><meta charset="UTF-8"></head>
|
||||
<body style="margin:0;padding:0;background:#eef0f3;font-family:Arial,sans-serif;">
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#eef0f3;padding:20px 0;">
|
||||
<tr><td align="center">
|
||||
<table width="620" cellpadding="0" cellspacing="0" style="width:620px;max-width:620px;background:#fff;border-radius:8px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.08);">
|
||||
<tr><td style="background:#1a2744;padding:18px 40px 14px;">
|
||||
<span style="color:#8fa8d0;font-size:11px;letter-spacing:1.5px;text-transform:uppercase;">Performance West — Compliance Services</span>
|
||||
</td></tr>
|
||||
<tr><td style="background:#059669;height:3px;font-size:0;"> </td></tr>
|
||||
<tr><td style="padding:32px 40px;">
|
||||
|
||||
<h1 style="margin:0 0 8px;font-size:22px;font-weight:700;color:#111827;">We're Getting Started</h1>
|
||||
<p style="margin:0 0 20px;font-size:15px;color:#6b7280;">Hi ${firstName}, thank you for your order. Here's what happens next.</p>
|
||||
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f9fafb;border:1px solid #e5e7eb;border-radius:6px;margin-bottom:20px;">
|
||||
<tr><td style="padding:16px 20px;">
|
||||
<p style="margin:0 0 4px;font-size:12px;font-weight:600;color:#6b7280;text-transform:uppercase;">Order</p>
|
||||
<p style="margin:0;font-size:14px;font-weight:600;color:#1a2744;font-family:monospace;">${orderId}</p>
|
||||
</td></tr>
|
||||
${entityName ? `<tr><td style="border-top:1px solid #e5e7eb;padding:16px 20px;">
|
||||
<p style="margin:0 0 4px;font-size:12px;font-weight:600;color:#6b7280;text-transform:uppercase;">Entity</p>
|
||||
<p style="margin:0;font-size:14px;color:#111827;">${entityName}${frn ? ` (FRN: ${frn})` : ""}</p>
|
||||
</td></tr>` : ""}
|
||||
<tr><td style="border-top:1px solid #e5e7eb;padding:16px 20px;">
|
||||
<p style="margin:0 0 8px;font-size:12px;font-weight:600;color:#6b7280;text-transform:uppercase;">Services Ordered</p>
|
||||
<ul style="margin:0;padding-left:18px;">${serviceLines}</ul>
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
${usacSection}
|
||||
|
||||
<h2 style="margin:24px 0 8px;font-size:16px;font-weight:700;color:#111827;">What to Expect</h2>
|
||||
<p style="margin:0 0 4px;font-size:14px;color:#374151;"><span style="color:#1e3a5f;font-weight:600;">1.</span> We will review your compliance status within 1 business day.</p>
|
||||
<p style="margin:0 0 4px;font-size:14px;color:#374151;"><span style="color:#1e3a5f;font-weight:600;">2.</span> If we need any additional information, we will email you.</p>
|
||||
<p style="margin:0 0 4px;font-size:14px;color:#374151;"><span style="color:#1e3a5f;font-weight:600;">3.</span> You will receive a confirmation for each filing as it is completed.</p>
|
||||
${has499 ? `<p style="margin:0 0 4px;font-size:14px;color:#374151;"><span style="color:#1e3a5f;font-weight:600;">4.</span> For 499-A filings, please complete the USAC delegation above so we can begin.</p>` : ""}
|
||||
|
||||
<p style="margin:20px 0 0;font-size:13px;color:#9ca3af;">
|
||||
Questions? Reply to this email or contact us at
|
||||
<a href="mailto:info@performancewest.net" style="color:#1e40af;">info@performancewest.net</a>
|
||||
or <a href="tel:+18884110383" style="color:#1e40af;">1-888-411-0383</a>.
|
||||
</p>
|
||||
|
||||
</td></tr>
|
||||
<tr><td style="background:#f4f5f7;border-top:1px solid #e8ecf0;padding:16px 40px;text-align:center;">
|
||||
<p style="margin:0;font-size:11px;color:#9ca3af;">Performance West Inc. · performancewest.net · 1-888-411-0383</p>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr></table>
|
||||
</body></html>`,
|
||||
});
|
||||
|
||||
console.log(`[checkout] Compliance intake email sent to ${customerEmail} for ${orderId}`);
|
||||
}
|
||||
|
||||
export default router;
|
||||
|
|
|
|||
Loading…
Reference in a new issue