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

- old
+ new

@@ -29,11 +29,11 @@ :american_express => "AMEX", :electron => "UKE", :diners_club => "DC", :jcb => "JCB" } - + 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, "NOTCHECKED" => 'X', @@ -103,22 +103,27 @@ action = abort_or_void_from(identification) commit(action, post) end - # Crediting requires a new order_id to passed in, as well as a description - def credit(money, identification, options = {}) + # Refunding requires a new order_id to passed in, as well as a description + def refund(money, identification, options = {}) requires!(options, :order_id, :description) post = {} add_credit_reference(post, identification) add_amount(post, money, options) add_invoice(post, options) commit(:credit, post) end + + def credit(money, identification, options = {}) + deprecated CREDIT_DEPRECATION_MESSAGE + refund(money, identification, options) + end private def add_reference(post, identification) order_id, transaction_id, authorization, security_key = identification.split(';') @@ -136,12 +141,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 +306,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