diff --git a/api/src/routes/checkout.ts b/api/src/routes/checkout.ts index 194bcf0..0cc9d61 100644 --- a/api/src/routes/checkout.ts +++ b/api/src/routes/checkout.ts @@ -1279,12 +1279,16 @@ export async function handlePaymentComplete( // Create Sales Invoice try { + // Calculate batch total (sum of all line items minus discounts) + const batchTotalCents = (batchRows.rows as any[]).reduce((sum, bo) => { + return sum + (bo.service_fee_cents || 0) + (bo.gov_fee_cents || 0) - (bo.discount_cents || 0); + }, 0); const invName = await createInvoiceFromSalesOrder({ salesOrderName: soName, paymentGateway: paymentMethod, surchargePercent: (order.surcharge_pct as number) || 0, paymentReference: session_id, - paidAmountCents: 0, + paidAmountCents: batchTotalCents, externalOrderId: batchId, }); if (invName) {