Abstract Payment Methods
Medium · Classes
The abstract class PaymentMethod cannot be created directly. Every subclass must provide a name and a fee(amount) method, and inherits checkout(amount), which returns the name and the amount plus the fee, rounded to 2 decimals.
Write three subclasses:
- Card(brand): the name is the brand, the fee is 3% of the amount
- BankTransfer(): name "Bank transfer", the fee is always 1.5
- Crypto(network): name "Crypto (<network>)", the fee is 1% of the amount but at least 2
checkoutAll is already written: it creates the payment methods and calls checkout().
Next: Roman Numerals Both Ways