Class: StripeFee::Calculator
- Inherits:
-
Object
- Object
- StripeFee::Calculator
- Defined in:
- lib/stripe_fee/calculator.rb
Instance Method Summary collapse
- #amount_in_cents ⇒ Object
- #charge_amount_in_cents ⇒ Object
-
#initialize(amount:, currency: 'usd') ⇒ Calculator
constructor
A new instance of Calculator.
- #validate! ⇒ Object
Constructor Details
#initialize(amount:, currency: 'usd') ⇒ Calculator
8 9 10 11 |
# File 'lib/stripe_fee/calculator.rb', line 8 def initialize amount:, currency: 'usd' @amount = amount @currency = currency end |
Instance Method Details
#amount_in_cents ⇒ Object
18 19 20 |
# File 'lib/stripe_fee/calculator.rb', line 18 def amount_in_cents @amount.to_f * 100 end |
#charge_amount_in_cents ⇒ Object
22 23 24 25 |
# File 'lib/stripe_fee/calculator.rb', line 22 def charge_amount_in_cents validate! ((amount_in_cents + 30)/(1 - 0.029)).round end |
#validate! ⇒ Object
13 14 15 16 |
# File 'lib/stripe_fee/calculator.rb', line 13 def validate! raise ::AmountError unless @amount.to_f raise ::CurrencyError unless @currency == 'usd' end |