lib/active_merchant/billing/gateways/realex.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/realex.rb in activemerchant-1.80.0

- old
+ new

@@ -37,13 +37,13 @@ self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :switch, :solo, :laser ] self.supported_countries = %w(IE GB FR BE NL LU IT US CA ES) self.homepage_url = 'http://www.realexpayments.com/' self.display_name = 'Realex' - SUCCESS, DECLINED = "Successful", "Declined" - BANK_ERROR = REALEX_ERROR = "Gateway is in maintenance. Please try again later." - ERROR = CLIENT_DEACTIVATED = "Gateway Error" + SUCCESS, DECLINED = 'Successful', 'Declined' + BANK_ERROR = REALEX_ERROR = 'Gateway is in maintenance. Please try again later.' + ERROR = CLIENT_DEACTIVATED = 'Gateway Error' def initialize(options = {}) requires!(options, :login, :password) options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options.has_key?(:rebate_secret) super @@ -62,11 +62,11 @@ request = build_purchase_or_authorization_request(:authorization, money, creditcard, options) commit(request) end def capture(money, authorization, options = {}) - request = build_capture_request(authorization, options) + request = build_capture_request(money, authorization, options) commit(request) end def refund(money, authorization, options = {}) request = build_refund_request(money, authorization, options) @@ -96,11 +96,11 @@ private def commit(request) response = parse(ssl_post(self.live_url, request)) Response.new( - (response[:result] == "00"), + (response[:result] == '00'), message_from(response), response, :test => (response[:message] =~ %r{\[ test system \]}), :authorization => authorization_from(response), avs_result: AVSResult.new(code: response[:avspostcoderesponse]), @@ -145,18 +145,19 @@ add_address_and_customer_info(xml, options) end xml.target! end - def build_capture_request(authorization, options) + def build_capture_request(money, authorization, options) timestamp = new_timestamp xml = Builder::XmlMarkup.new :indent => 2 xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do add_merchant_details(xml, options) + add_amount(xml, money, options) add_transaction_identifiers(xml, authorization, options) add_comments(xml, options) - add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil) + add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil) end xml.target! end def build_refund_request(money, authorization, options) @@ -264,20 +265,20 @@ end end def format_address_code(address) code = [address[:zip].to_s, address[:address1].to_s + address[:address2].to_s] - code.collect{|e| e.gsub(/\D/, "")}.reject{|e| e.empty?}.join("|") + code.collect{|e| e.gsub(/\D/, '')}.reject{|e| e.empty?}.join('|') end def new_timestamp Time.now.strftime('%Y%m%d%H%M%S') end def add_signed_digest(xml, *values) - string = Digest::SHA1.hexdigest(values.join(".")) - xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join(".")) + string = Digest::SHA1.hexdigest(values.join('.')) + xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join('.')) end def auto_settle_flag(action) action == :authorization ? '0' : '1' end @@ -287,24 +288,24 @@ end def message_from(response) message = nil case response[:result] - when "00" + when '00' message = SUCCESS - when "101" + when '101' message = response[:message] - when "102", "103" + when '102', '103' message = DECLINED when /^2[0-9][0-9]/ message = BANK_ERROR when /^3[0-9][0-9]/ message = REALEX_ERROR when /^5[0-9][0-9]/ message = response[:message] - when "600", "601", "603" + when '600', '601', '603' message = ERROR - when "666" + when '666' message = CLIENT_DEACTIVATED else message = DECLINED end end