From f8e97463408fa2ad4461546ce768a778e0703ac6 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Wed, 3 Jun 2026 03:42:50 +0000 Subject: [PATCH] Route webhook order emails through Email class for email_log visibility Replaced local sendOrderConfirmationEmail() with emailService()->sendOrderConfirmation(). Order confirmations now log to email_log table and use the branded template (orange header, full subtotal/tax/discount breakdown) instead of the minimal brown-header version that was invisible to the admin Email Log. --- api/webhook.php | 65 +++---------------------------------------------- 1 file changed, 3 insertions(+), 62 deletions(-) diff --git a/api/webhook.php b/api/webhook.php index 8756b68..bc875b6 100644 --- a/api/webhook.php +++ b/api/webhook.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/../includes/functions.php'; require_once __DIR__ . '/../includes/stripe.php'; +require_once __DIR__ . '/../includes/email.php'; header('Content-Type: application/json'); @@ -51,7 +52,7 @@ switch ($eventType) { ); $order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]); if ($order) { - sendOrderConfirmationEmail($order); + emailService()->sendOrderConfirmation($order); } } break; @@ -74,7 +75,7 @@ switch ($eventType) { ); $order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]); if ($order) { - sendOrderConfirmationEmail($order); + emailService()->sendOrderConfirmation($order); } } } @@ -109,63 +110,3 @@ switch ($eventType) { http_response_code(200); echo json_encode(['received' => true]); -/** - * Send order confirmation email - */ -function sendOrderConfirmationEmail($order) { - $items = json_decode($order['items'], true) ?? []; - $shippingAddress = json_decode($order['shipping_address'], true) ?? []; - - $itemsHtml = ''; - foreach ($items as $item) { - $itemsHtml .= sprintf( - '%s x%d$%.2f', - htmlspecialchars($item['name']), - $item['quantity'], - $item['total'] - ); - } - - $html = << -
-

Tom's Java Jive

-
- -
-

Order Confirmed!

-

Thank you for your order, {$order['customer_name']}!

- -
-

Order #: {$order['order_number']}

-

Total: \${$order['total']}

-
- -

Order Details

- - {$itemsHtml} - - - - -
Total\${$order['total']}
- -

Shipping To

-

- {$shippingAddress['address']}
- {$shippingAddress['city']}, {$shippingAddress['state']} {$shippingAddress['zip']} -

- -

- We'll send you tracking information once your order ships. -

-
- -
-

Tom's Java Jive | Premium Coffee

-
- - HTML; - - sendEmail($order['customer_email'], "Order Confirmed - #{$order['order_number']}", $html); -}