Sha256: 70978436079634a1cbfb95cdeff1a2de50863557465dca3e82a52851d585d28f

Contents?: true

Size: 559 Bytes

Versions: 1

Compression:

Stored size: 559 Bytes

Contents

module StripeFee
  class Error < StandardError; end
  class AmountError < ArgumentError; end
  class CurrencyError < ArgumentError; end

  class Calculator

    def initialize amount:, currency: 'usd'
      @amount = amount
      @currency = currency
    end

    def validate!
      raise ::AmountError unless @amount.to_f
      raise ::CurrencyError unless @currency == 'usd'
    end

    def amount_in_cents
      @amount.to_f * 100
    end

    def charge_amount_in_cents
      validate!
      ((amount_in_cents + 30)/(1 - 0.029)).round
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stripe_fee-0.1.0 lib/stripe_fee/calculator.rb