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.
This commit is contained in:
2026-06-03 03:42:50 +00:00
parent 2550ec5695
commit f8e9746340
+3 -62
View File
@@ -6,6 +6,7 @@
require_once __DIR__ . '/../includes/functions.php'; require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/stripe.php'; require_once __DIR__ . '/../includes/stripe.php';
require_once __DIR__ . '/../includes/email.php';
header('Content-Type: application/json'); header('Content-Type: application/json');
@@ -51,7 +52,7 @@ switch ($eventType) {
); );
$order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]); $order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]);
if ($order) { if ($order) {
sendOrderConfirmationEmail($order); emailService()->sendOrderConfirmation($order);
} }
} }
break; break;
@@ -74,7 +75,7 @@ switch ($eventType) {
); );
$order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]); $order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]);
if ($order) { if ($order) {
sendOrderConfirmationEmail($order); emailService()->sendOrderConfirmation($order);
} }
} }
} }
@@ -109,63 +110,3 @@ switch ($eventType) {
http_response_code(200); http_response_code(200);
echo json_encode(['received' => true]); 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(
'<tr><td>%s x%d</td><td style="text-align:right;">$%.2f</td></tr>',
htmlspecialchars($item['name']),
$item['quantity'],
$item['total']
);
}
$html = <<<HTML
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<div style="background: #8B4513; color: white; padding: 20px; text-align: center;">
<h1 style="margin: 0;">Tom's Java Jive</h1>
</div>
<div style="padding: 30px; background: #FDFBF7;">
<h2>Order Confirmed!</h2>
<p>Thank you for your order, {$order['customer_name']}!</p>
<div style="background: white; padding: 20px; border-radius: 8px; margin: 20px 0;">
<p><strong>Order #:</strong> {$order['order_number']}</p>
<p><strong>Total:</strong> \${$order['total']}</p>
</div>
<h3>Order Details</h3>
<table style="width: 100%; border-collapse: collapse;">
{$itemsHtml}
<tr style="border-top: 2px solid #ccc;">
<td><strong>Total</strong></td>
<td style="text-align:right;"><strong>\${$order['total']}</strong></td>
</tr>
</table>
<h3>Shipping To</h3>
<p>
{$shippingAddress['address']}<br>
{$shippingAddress['city']}, {$shippingAddress['state']} {$shippingAddress['zip']}
</p>
<p style="color: #666; font-size: 14px;">
We'll send you tracking information once your order ships.
</p>
</div>
<div style="padding: 20px; text-align: center; color: #666; font-size: 12px;">
<p>Tom's Java Jive | Premium Coffee</p>
</div>
</div>
HTML;
sendEmail($order['customer_email'], "Order Confirmed - #{$order['order_number']}", $html);
}