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( - '
Thank you for your order, {$order['customer_name']}!
- -Order #: {$order['order_number']}
-Total: \${$order['total']}
-| Total | -\${$order['total']} | -
- {$shippingAddress['address']}
- {$shippingAddress['city']}, {$shippingAddress['state']} {$shippingAddress['zip']}
-
- We'll send you tracking information once your order ships. -
-Tom's Java Jive | Premium Coffee
-