Functional Weave
Code in Python

charity.donation-matching@1.0.0

README.md

1,182 bytes · view raw

# charity.donation-matching

How much an employer (or any match funder) adds to a donation under a matched
giving scheme: a ratio, a cap per donor and a budget for the whole programme.

- The ratio is in basis points of the donation: 10000 is 1:1 (£1 for every
  £1), 20000 is 2:1, 5000 is 50p per £1. The uncapped match is rounded down to
  the minor unit, since a funder pays whole pennies and never more than
  promised.
- The match is then limited to the room left under the donor's cap
  (`donorCap - donorMatchedSoFar`) and under the programme budget
  (`programmeCap - programmeMatchedSoFar`). Room is never negative: a donor
  already past the cap gets 0, not a clawback. Pass `null` for a cap that
  does not apply.
- `cappedBy` says which limit reduced the match (`donor` when both leave the
  same room), or `none`. A match that exactly fills a cap is not capped.

The caller keeps the running totals and adds `matched` to both after paying,
which keeps the function pure. Which donations qualify (minimum amounts,
eligible charities, time limits) is scheme policy and stays with the caller.
Matched funds are the employer's own gift: they are not Gift Aid donations.