Charge a Fee per Payment Method
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Payments are a union told apart by method, with amounts in pence: card (with an international flag), bank, or voucher (with a code). Export the Payment type, a FeeTable type with one fee function per method, each taking only its own kind of payment, a FEES table of that type, and fee(payment), which looks up the right function: card costs 2% of the amount, rounded (3% when international), bank a flat 25, voucher nothing. Type FeeTable from Payment so that leaving out a method is a type error, as is a payment with an unknown method.
Your code must pass
- Charges card payments a percentage
- Charges bank and voucher payments
- Has no type errors
- The fee table needs every method
- Each fee gets its own payment type
- Rejects an unknown method