Coupons, tax and shipping (E-commerce Store (full stack))

Carts now show the full price: "coupon" (code or null), "discount", "tax", "shipping" and "total". COUPON <code percent|fixed <value [min=<amount] lines create coupons (percent: whole percent; fixed: an amount). POST /cart/coupon {"code"} (any case) applies one (404 {"error":"unknown coupon"}, 400 {"error":"order minimum not met"}); DELETE /cart/coupon removes it. discount = floor(subtotal × percent / 100) or min(fixed, subtotal), and only while the subtotal meets the minimum. tax = 8% of (subtotal − discount), rounded half up to a cent. shipping = 0 for an empty cart or when (subtotal − discount) ≥ 5000, else 499. total = subtotal − discount + tax + shipping.

Input: As before, plus COUPON lines.

Output: As before.

Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Compute everything from the cart every time; never store totals.

More E-commerce Store (full stack) practice