From c65cd8242b39ab6b91cb4ea31bb5bdf7362005b8 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Mon, 2 Mar 2026 14:32:54 -0800 Subject: [PATCH] Round balance amounts to cents before applying Prevents sub-cent precision (e.g. $0.883125) from accumulating in BalanceApplied and payment records. All balance math now rounds to nearest cent first. Co-Authored-By: Claude Opus 4.6 --- api/orders/submitCash.cfm | 5 +++-- api/stripe/createPaymentIntent.cfm | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/orders/submitCash.cfm b/api/orders/submitCash.cfm index e99b021..c9620e1 100644 --- a/api/orders/submitCash.cfm +++ b/api/orders/submitCash.cfm @@ -79,7 +79,7 @@ - + @@ -92,7 +92,8 @@ )> - + + = ?", diff --git a/api/stripe/createPaymentIntent.cfm b/api/stripe/createPaymentIntent.cfm index 1871dee..34aa7d0 100644 --- a/api/stripe/createPaymentIntent.cfm +++ b/api/stripe/createPaymentIntent.cfm @@ -134,13 +134,14 @@ try { userBalance = val(qOrder.Balance ?: 0); orderUserID = val(qOrder.UserID ?: 0); if (userBalance > 0 && orderUserID > 0) { - balanceApplied = min(userBalance, totalBeforeCardFee); + // Round to cents to avoid sub-cent precision issues + balanceApplied = round(min(userBalance, totalBeforeCardFee) * 100) / 100; // Ensure Stripe minimum: adjusted amount after card fee must be >= $0.50 adjustedTest = ((totalBeforeCardFee - balanceApplied) + cardFeeFixed) / (1 - cardFeePercent); if (adjustedTest < 0.50) { // Cap balance so Stripe charge stays >= $0.50 maxBalance = totalBeforeCardFee - ((0.50 * (1 - cardFeePercent)) - cardFeeFixed); - balanceApplied = max(0, min(userBalance, maxBalance)); + balanceApplied = round(max(0, min(userBalance, maxBalance)) * 100) / 100; } // Store intent on order (actual deduction happens in webhook after payment succeeds) if (balanceApplied > 0) {