From 039ddc0fa8c3d6f13f4e8beaa5fe6fc74b882ab8 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 3 Nov 2025 13:47:03 +0100 Subject: [PATCH] Fix admin email to display correct payment amount - Admin notification was showing 6 instead of 600 - Root cause: double cents-to-dollars conversion - webhooks.js already converts to dollars before calling sendAdminNotification - Updated sendAdminNotification to handle pre-converted dollar amounts - Simplified formatting logic for clarity server/utils/emailService.js:155-162 --- server/utils/emailService.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/utils/emailService.js b/server/utils/emailService.js index c4d41d5..1f17f2e 100644 --- a/server/utils/emailService.js +++ b/server/utils/emailService.js @@ -151,7 +151,14 @@ export async function sendContactEmail(contactData) { // Send admin notification for new order export async function sendAdminNotification(orderDetails, customerEmail) { - const subject = `New Order: ${orderDetails.tons} tons CO₂ - $${(orderDetails.totalAmount / 100).toFixed(2)}`; + // totalAmount is already in dollars (converted before calling this function) + const totalAmount = typeof orderDetails.totalAmount === 'string' + ? orderDetails.totalAmount + : (orderDetails.totalAmount / 100).toFixed(2); + + // Format amount with commas for subject line + const formattedAmount = parseFloat(totalAmount).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); + const subject = `New Order: ${orderDetails.tons} tons CO₂ - $${formattedAmount}`; const adminEmail = process.env.ADMIN_EMAIL || 'matt@puffinoffset.com'; // Check if admin notifications are enabled @@ -167,7 +174,7 @@ export async function sendAdminNotification(orderDetails, customerEmail) { { tons: orderDetails.tons, portfolioId: orderDetails.portfolioId, - totalAmount: (orderDetails.totalAmount / 100).toFixed(2), + totalAmount: totalAmount, orderId: orderDetails.orderId, customerEmail, timestamp: new Date().toLocaleString('en-US', {