Sha256: 3b6ccd4e06fcf67080395dc7246124b5c5134863c29f66605f0fa51800a97a11

Contents?: true

Size: 579 Bytes

Versions: 1

Compression:

Stored size: 579 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 && @amount.to_f > 0
      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.1 lib/stripe_fee/calculator.rb