DrillsThe rounding bug came back
The rounding bug came back
What happened
On Tuesday Kofi fixed Harbor’s invoice discounts so they round to whole cents (#218). On Friday the volume discounts branch (#226) was merged, after Claude Code resolved a conflict in the same file. Overnight, 14 invoices failed to finalize, all for teams with a coupon and at least 10 seats. CI was green the whole time.
Mei, site reliability lead14 invoices have been stuck in draft since last night, all with the same Stripe error: Invalid integer. Every one is a team with a coupon and 10 or more seats. Didn’t Kofi fix exactly this on Tuesday?
What you seeServer log
2026-12-05T03:12:08Z ERROR invoices.finalize team=team_northwind
StripeInvalidRequestError: Invalid integer: 16491.75
param: amount
at finalizeInvoice (lib/billing/finalize.js:41)
The MagisterRun it first and read what comes back. Then change the code if you like: your edits go to the review too.
Run it to see the total finalize.js sends to Stripe for Northwind.
// lib/billing/invoice-discounts.js
// Discounts on a team's monthly invoice, in cents. finalize.js sends the total to Stripe.
function percentOffCents(amountCents, percent) {
// Stripe only accepts whole cents, so round here, once (#218).
return Math.round((amountCents * percent) / 100);
}
function invoiceDiscountCents(team, coupon) {
const subtotal = team.plan.priceCents * team.seats;
// Teams with 10 or more seats get 10% off, on top of any coupon (#226).
const volume = team.seats >= 10 ? 10 : 0;
const percent = Math.min((coupon ? coupon.percentOff : 0) + volume, 100);
return (subtotal * percent) / 100;
}
function invoiceTotalCents(team, coupon) {
return team.plan.priceCents * team.seats - invoiceDiscountCents(team, coupon);
}
// Northwind's December invoice, the way finalize.js builds it.
const northwind = { id: "team_northwind", seats: 11, plan: { id: "team", priceCents: 1999 } };
const total = invoiceTotalCents(northwind, { code: "WINTER15", percentOff: 15 });
console.log("Northwind invoice total, in cents:", total);
The code runs in your browser against stand-in data. Nothing is sent anywhere.
Your answer
Reviewed by AI against what a good fix needs. About 10 seconds.Sign in to get your answer reviewed
It's free. Anything you've typed here stays in this browser and is waiting when you come back.
Sign in with email