OpenBook
  • Problems
  • Tracks
  • How it works
  • Pricing
Start practicingSign In
Problems/Commerce & Billing

4. Shopping Cart with Discounts

Medium

Carts, line items, stackable percentage and fixed coupons, and a totals endpoint.

45 minute budget52.1% acceptancepricing · rules engine

Requirements

  1. 01POST /carts creates a cart. Add, update and remove line items by sku; prices and quantities are integers, money is integer cents.
  2. 02POST /carts/:id/coupons attaches one of the store's fixed coupon codes. Percentage coupons apply before fixed ones, each to the amount left after the previous one.
  3. 03GET /carts/:id/totals returns subtotalCents, discountCents, taxCents and totalCents.
  4. 04A fixed coupon never takes the amount below zero, so totals are never negative.

What the hidden tests check

  • Everything the interviewer tells you is checked.
  • Totals are checked to the exact cent, including when coupons stack and when a coupon is worth more than the cart.

4 more details are held back. In a mock interview they come out only when you ask the interviewer the right question; in practice they are listed in the workspace.

Sign in to start

Attempts, files and transcripts are saved to your account so the grader can review how you worked.

Sign inCreate an account
OpenBook

Practice for interviews where you build a feature with an AI assistant.

Early preview. Problems, grading and the interviewer are still changing.

Practice

  • Problems
  • Tracks
  • How it works
  • Pricing

Legal

  • Terms
  • Privacy
© 2026 OpenBook.