lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.7.1 vs lib/active_merchant/billing/gateways/sage_pay.rb in activemerchant-1.7.2

- old
+ new

@@ -29,10 +29,12 @@ :american_express => "AMEX", :electron => "UKE", :diners_club => "DC", :jcb => "JCB" } + + CURRENCIES_WITHOUT_FRACTIONS = [ 'YEN' ] ELECTRON = /^(424519|42496[23]|450875|48440[6-8]|4844[1-5][1-5]|4917[3-5][0-9]|491880)\d{10}(\d{3})?$/ AVS_CVV_CODE = { "NOTPROVIDED" => nil, @@ -136,12 +138,13 @@ add_pair(post, :RelatedTxAuthNo, authorization) add_pair(post, :RelatedSecurityKey, security_key) end def add_amount(post, money, options) - add_pair(post, :Amount, amount(money), :required => true) - add_pair(post, :Currency, options[:currency] || currency(money), :required => true) + currency = options[:currency] || currency(money) + add_pair(post, :Amount, localized_amount(money, currency), :required => true) + add_pair(post, :Currency, currency, :required => true) end # doesn't actually use the currency -- dodgy! def add_release_amount(post, money, options) add_pair(post, :ReleaseAmount, amount(money), :required => true) @@ -300,9 +303,14 @@ name = value.to_s.split(' ') last_name = name.pop || '' first_name = name.join(' ') [ first_name[0,20], last_name[0,20] ] + end + + def localized_amount(money, currency) + amount = amount(money) + CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s) ? amount.split('.').first : amount end end end end