Class: StripeFee::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe_fee/calculator.rb

Instance Method Summary collapse

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_centsObject



18
19
20
# File 'lib/stripe_fee/calculator.rb', line 18

def amount_in_cents
  @amount.to_f * 100
end

#charge_amount_in_centsObject



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

Raises:

  • (::AmountError)


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