Functional Weave
Code in Python

retail.gift-card-balance@1.0.0

README.md

1,042 bytes · view raw

# retail.gift-card-balance

A gift card pays for as much of the bill as its balance allows. The card pays
`min(balance, amountDue)`; the rest stays on the card or is left for another
tender (card, cash, a second gift card).

The result carries all three amounts, applied, remaining balance and still
due, so the till never derives one from the other two, and `applied +
remainingBalance` is always the old balance and `applied + stillDue` always the
amount due, to the minor unit.

## What it does not do

- Refunds onto a gift card are top-ups, a different operation with its own
  rules (maximum balance, fraud checks), so a negative `amountDue` is an error
  rather than a silent credit.
- Expiry, dormancy fees and activation are the card issuer's rules and are
  not modelled; check them before calling this. (In the UK, gift cards often
  carry an expiry date set by the issuer; there is no statutory minimum.)
- Currencies must match. A card in euros cannot pay a bill in pounds without a
  conversion, which is `money.convert`'s job.