lib/active_merchant/billing/gateway.rb in bitfluent-activemerchant-1.5.1.1 vs lib/active_merchant/billing/gateway.rb in bitfluent-activemerchant-1.15.1

- old
+ new

@@ -60,11 +60,13 @@ include RequiresParameters include CreditCardFormatting include Utils DEBIT_CARDS = [ :switch, :solo ] - + CURRENCIES_WITHOUT_FRACTIONS = [ 'JPY' ] + CREDIT_DEPRECATION_MESSAGE = "Support for using credit to refund existing transactions is deprecated and will be removed from a future release of ActiveMerchant. Please use the refund method instead." + cattr_reader :implementations @@implementations = [] def self.inherited(subclass) super @@ -72,26 +74,26 @@ end # The format of the amounts used by the gateway # :dollars => '12.50' # :cents => '1250' - class_inheritable_accessor :money_format + class_attribute :money_format self.money_format = :dollars # The default currency for the transactions if no currency is provided - class_inheritable_accessor :default_currency + class_attribute :default_currency # The countries of merchants the gateway supports - class_inheritable_accessor :supported_countries + class_attribute :supported_countries self.supported_countries = [] # The supported card types for the gateway - class_inheritable_accessor :supported_cardtypes + class_attribute :supported_cardtypes self.supported_cardtypes = [] - class_inheritable_accessor :homepage_url - class_inheritable_accessor :display_name + class_attribute :homepage_url + class_attribute :display_name # The application making the calls to the gateway # Useful for things like the PayPal build notation (BN) id fields superclass_delegating_accessor :application_id self.application_id = 'ActiveMerchant' @@ -131,24 +133,29 @@ end def amount(money) return nil if money.nil? cents = if money.respond_to?(:cents) - warn "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents" + deprecated "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents" money.cents else money end - if money.is_a?(String) or cents.to_i < 0 + if money.is_a?(String) raise ArgumentError, 'money amount must be a positive Integer in cents.' end if self.money_format == :cents cents.to_s else sprintf("%.2f", cents.to_f / 100) end + end + + def localized_amount(money, currency) + amount = amount(money) + CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s) ? amount.split('.').first : amount end def currency(money) money.respond_to?(:currency) ? money.currency : self.default_currency end