Fix Telegram notification: show actual paid amount after discount

Was showing service_fee_cents ($69) instead of actual charge ($35.54).
Now subtracts discount_cents and adds surcharge_cents. Also shows
discount line in notification when a promo code was used.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-29 15:51:34 -05:00
parent 607412e182
commit 9579d74d7d

View file

@ -1268,20 +1268,26 @@ export async function handlePaymentComplete(
const serviceName = (order.service_slug as string)
|| (order.service_name as string)
|| order_type;
// Calculate total in dollars
// Calculate total in dollars (after discount + surcharge)
const feeCents = Number(order.service_fee_cents || order.total_cents || 0);
const discountCents = Number(order.discount_cents || 0);
const surchargeCents = Number(order.surcharge_cents || 0);
const formationCents = Number(order.formation_fee_cents || 0);
const stateCents = Number(order.state_fee_cents || 0);
const addonCents = Number(order.addon_fee_cents || 0);
const pucCents = Number(order.puc_fee_cents || 0);
const totalCents = feeCents + formationCents + stateCents + addonCents + pucCents;
const totalCents = feeCents - discountCents + surchargeCents + formationCents + stateCents + addonCents + pucCents;
const totalDollars = (totalCents / 100).toFixed(2);
const discountLine = discountCents > 0
? `Discount: -$${(discountCents / 100).toFixed(2)} (${order.discount_code || "promo"})\n`
: "";
const msg = `💰 NEW ORDER\n\n`
+ `Customer: ${customerName}\n`
+ `Email: ${customerEmail}\n`
+ `Service: ${serviceName}\n`
+ `Total: $${totalDollars}\n`
+ discountLine
+ `Payment: ${paymentMethod}\n`
+ `Order: ${order_id}\n`
+ `Type: ${order_type}`;