Fix PayPal capture for compliance orders + MCS-150 form generator
PayPal capture was defaulting to canada_crtc_orders table for all non-formation orders. Now properly routes compliance_batch orders to compliance_orders table with batch_id lookup. Also infers order type from ID prefix (CB-=batch, CO-=compliance, FO-=formation). MCS-150 form generator: produces DOCX with fax cover sheet + filled MCS-150 form for faxing to FMCSA at 202-366-3477. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d2b42cd4b8
commit
e82aa0b8c2
2 changed files with 431 additions and 4 deletions
|
|
@ -84,18 +84,33 @@ router.post("/api/v1/paypal/capture", async (req: Request, res: Response) => {
|
|||
|
||||
// Find the internal order and mark as paid
|
||||
const resolvedOrderId = order_id || data.purchase_units?.[0]?.custom_id || data.purchase_units?.[0]?.reference_id;
|
||||
const resolvedOrderType = order_type || "canada_crtc";
|
||||
// Infer order type from ID prefix if not provided
|
||||
let resolvedOrderType = order_type || "";
|
||||
if (!resolvedOrderType && resolvedOrderId) {
|
||||
if (resolvedOrderId.startsWith("CB-")) resolvedOrderType = "compliance_batch";
|
||||
else if (resolvedOrderId.startsWith("CO-")) resolvedOrderType = "compliance";
|
||||
else if (resolvedOrderId.startsWith("FO-")) resolvedOrderType = "formation";
|
||||
else resolvedOrderType = "canada_crtc";
|
||||
}
|
||||
|
||||
if (resolvedOrderId) {
|
||||
try {
|
||||
// Store PayPal capture details in the order before marking paid
|
||||
const captureId = data.purchase_units?.[0]?.payments?.captures?.[0]?.id || "";
|
||||
const payerEmail = data.payer?.email_address || "";
|
||||
const table = resolvedOrderType === "formation" ? "formation_orders" : "canada_crtc_orders";
|
||||
|
||||
// Update the correct table with PayPal order ID
|
||||
const tableMap: Record<string, { table: string; col: string }> = {
|
||||
formation: { table: "formation_orders", col: "order_number" },
|
||||
canada_crtc: { table: "canada_crtc_orders", col: "order_number" },
|
||||
compliance: { table: "compliance_orders", col: "order_number" },
|
||||
compliance_batch: { table: "compliance_orders", col: "batch_id" },
|
||||
};
|
||||
const target = tableMap[resolvedOrderType] || tableMap.canada_crtc;
|
||||
await pool.query(
|
||||
`UPDATE ${table} SET paypal_order_id = $1 WHERE order_number = $2`,
|
||||
`UPDATE ${target.table} SET paypal_order_id = $1, payment_method = 'paypal' WHERE ${target.col} = $2`,
|
||||
[paypal_order_id, resolvedOrderId],
|
||||
).catch(() => {});
|
||||
).catch((err: any) => console.error("[paypal] DB update failed:", err.message));
|
||||
|
||||
await handlePaymentComplete(resolvedOrderId, resolvedOrderType, `paypal-${captureId}`);
|
||||
} catch (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue