Checkout bugs developers fix in a Next.js store
A store's checkout is a few lines of arithmetic that every order goes through, so a small mistake there is charged to every customer. This guide covers the bugs that come up most in a Next.js and TypeScript checkout, how to spot each one, and how to test the fix. The examples come from ShopForge, Kadra's Next.js e-commerce practice codebase.
A percent coupon is a share of the subtotal
ShopForge stores money as integer cents. Its ECOM-114 ticket is a 10% coupon that takes off $10 on every order, because the code multiplies the coupon value by 100 as if it were a dollar amount. On a $200 cart the customer should save $20.
// Wrong: treats 10 (percent) as $10
return coupon.value * 100;
// Right: a share of the subtotal, rounded to a whole cent
return roundCents((subtotal * coupon.value) / 100);“the old coupon.value * 100 was treating percent coupons like fixed cents, that's the actual bug behind the ticket”Round to a whole cent right there. 10% of $19.99 is 199.9 cents, and if that fraction rides into the total it shows up later as a cent nobody can explain.
Apply tax after the discount
In ECOM-141, checkout works out sales tax on the subtotal before the coupon, so every discounted order pays tax on money the customer never spent. Orders without a coupon look fine, which is why this kind of bug survives a quick manual test.
const taxable = subtotal - discount;
return taxable + taxCents(taxable, rateBps); // tax on what's actually chargedWrite two tests: one with a coupon, where the tax goes down, and one without, where nothing changes. Tax rules do vary by place, and some discounts are taxed differently, so in a real job the ticket or the finance team tells you which rule applies.
Enforce stock on the server
ECOM-127 is a product with zero stock that can still go in the cart. Disabling the button helps, but a request can reach the server without anyone clicking it, so the rule belongs in the code that changes the cart, which in ShopForge is addToCart.
Count what's already in the cart too. Five in stock and four in the cart means one more is fine and two more is not:
const existing = cart.find((line) => line.productId === product.id);
const totalQty = (existing?.qty ?? 0) + qty;
if (product.stock < totalQty) {
throw new Error("out of stock");
}Practice on a Next.js store
ShopForge is a Next.js store with the ECOM tickets above planted in it. You get your own GitHub repo, fix each ticket on a branch and open a pull request. An AI teammate reviews the diff, and a hidden Vitest suite decides whether the fix passes.
Every ShopForge repo opens in GitHub Codespaces with Node 24 and npm installed, so there's nothing to set up on your own machine.
Questions people ask
How should I store prices in a JavaScript app?
As integer cents. JavaScript numbers are floating point, so 0.1 + 0.2 isn't exactly 0.3. Do the arithmetic in cents, round once where a fraction can appear, and format as dollars only for display.
Should sales tax be calculated before or after a discount?
Usually after a store coupon, on the amount the customer pays. The rules depend on the place and the kind of discount, so follow the ticket or ask whoever owns tax.
Is disabling a button enough to stop an invalid action?
No. It improves the experience, but the server has to check the rule again, because requests can be sent without the page.
Is Kadra free?
Yes, Kadra is free during beta with no credit card. After beta, Pro is planned at $12 a month or $79 a year, and the demo and your first full sprint stay free.
Try it on a real ticket
Pick a stack, fix a bug in a working codebase and get your pull request reviewed. Free during beta.
More guides
- How to get software engineering experience before your first job
- What your first code review at a software job looks like
- How to fix a bug in a codebase you didn't write
- What is a software engineering job simulator?
- Money bugs junior Java developers fix in banking code
- Common bugs in a Node.js CMS backend, and how to fix them
- Python ETL bugs junior data engineers fix first
- Payment bugs Python developers fix in a FastAPI service
- Go REST API bugs junior developers fix first
- Booking bugs C# developers fix in ASP.NET Core
- Realtime chat bugs developers fix in TypeScript