Checkout and payment (E-commerce Store (full stack))

POST /checkout {"card"} pays for the cart. The card number (spaces ignored) must be 13–19 digits and pass the Luhn check → else 400 {"error":"invalid card"}. Empty cart → 400 {"error":"cart is empty"}; not enough stock → 409 {"error":"only <n <id left"}; the test card 4000000000000002 → 402 {"error":"card declined"}. Success: create order ord<n, take the items out of stock, empty the cart → 201 {"order":{"id","items":[{"price","product","qty"}],"status":"paid","subtotal","total"}}. A request starting with idem=<key that repeats a key already used by the same user returns the first answer again and charges nothing.

Input: As before, plus idem=.

Output: As before.

Difficulty: Hard. 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

  • Luhn: from the right, double every second digit (subtract 9 if over 9), and the sum must end in 0.

More E-commerce Store (full stack) practice