Spec a wallet payment that never refuses exact change

Vibe codingMedium25 minStripe and Shopify style

Your task

Your checkout runs on Node and JavaScript. Users top up a wallet and pay from it. Support has tickets from users who had exactly enough and were refused. An agent will rewrite the cart total, canPay(balance, price) and the payment step that returns the remaining balance.

Write the spec you would hand the agent.

What you know:

  • balances live in Postgres as numeric(12,2), and the pg driver returns them as strings
  • line item prices come from the catalog the same way, and today the code adds them up to make the cart total
  • wallets hold USD or EUR today, and JPY arrives next quarter
  • a user can pay from 2 browser tabs at the same moment

Then, in a few sentences: what does "check if balance >= price and subtract" let through?