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

- old
+ new

@@ -137,11 +137,11 @@ gsub(%r((<CVC2>)[^<]+(</CVC2>)), '\1[FILTERED]\2') end private def clean_description(description) - description.to_s.slice(0,32).encode("US-ASCII", invalid: :replace, undef: :replace, replace: '?') + description.to_s.slice(0,32).encode('US-ASCII', invalid: :replace, undef: :replace, replace: '?') end def prepare_options_hash(options) result = @options.merge(options) setup_address_hash!(result) @@ -172,23 +172,23 @@ headers = { 'Content-Type' => 'text/xml', 'Authorization' => encoded_credentials } response = parse(ssl_post(test? ? self.test_url : self.live_url, request, headers)) # Pending Status also means Acknowledged (as stated in their specification) - success = response[:FunctionResult] == "ACK" || response[:FunctionResult] == "PENDING" + success = response[:FunctionResult] == 'ACK' || response[:FunctionResult] == 'PENDING' message = response[:Message] authorization = response[:GuWID] Response.new(success, message, response, :test => test?, :authorization => authorization, :avs_result => { :code => avs_code(response, options) }, :cvv_result => response[:CVCResponseCode] ) rescue ResponseError => e - if e.response.code == "401" - return Response.new(false, "Invalid Login") + if e.response.code == '401' + return Response.new(false, 'Invalid Login') else raise end end @@ -198,16 +198,16 @@ options[:action] = action xml = Builder::XmlMarkup.new :indent => 2 xml.instruct! xml.tag! 'WIRECARD_BXML' do xml.tag! 'W_REQUEST' do - xml.tag! 'W_JOB' do - xml.tag! 'JobID', '' - # UserID for this transaction - xml.tag! 'BusinessCaseSignature', options[:signature] || options[:login] - # Create the whole rest of the message - add_transaction_data(xml, money, options) + xml.tag! 'W_JOB' do + xml.tag! 'JobID', '' + # UserID for this transaction + xml.tag! 'BusinessCaseSignature', options[:signature] || options[:login] + # Create the whole rest of the message + add_transaction_data(xml, money, options) end end end xml.target! end @@ -259,11 +259,11 @@ xml.tag! 'Amount', localized_amount(money, options[:currency] || currency(money)) end # Includes the credit-card data to the transaction-xml def add_creditcard(xml, creditcard) - raise "Creditcard must be supplied!" if creditcard.nil? + raise 'Creditcard must be supplied!' if creditcard.nil? xml.tag! 'CREDIT_CARD_DATA' do xml.tag! 'CreditCardNumber', creditcard.number xml.tag! 'CVC2', creditcard.verification_value xml.tag! 'ExpirationYear', creditcard.year xml.tag! 'ExpirationMonth', format(creditcard.month, :two_digits) @@ -307,37 +307,37 @@ response = {} xml = REXML::Document.new(xml) if root = REXML::XPath.first(xml, "#{basepath}/W_JOB") parse_response(response, root) - elsif root = REXML::XPath.first(xml, "//ERROR") + elsif root = REXML::XPath.first(xml, '//ERROR') parse_error_only_response(response, root) else response[:Message] = "No valid XML response message received. \ Propably wrong credentials supplied with HTTP header." end response end def parse_error_only_response(response, root) - error_code = REXML::XPath.first(root, "Number") + error_code = REXML::XPath.first(root, 'Number') response[:ErrorCode] = error_code.text if error_code response[:Message] = parse_error(root) end # Parse the <ProcessingStatus> Element which contains all important information def parse_response(response, root) status = nil root.elements.to_a.each do |node| if node.name =~ /FNC_CC_/ - status = REXML::XPath.first(node, "CC_TRANSACTION/PROCESSING_STATUS") + status = REXML::XPath.first(node, 'CC_TRANSACTION/PROCESSING_STATUS') end end - message = "" + message = '' if status if info = status.elements['Info'] message << info.text end @@ -350,20 +350,20 @@ response[name.to_sym] = (childnode.text || '').strip end end end - error_code = REXML::XPath.first(status, "ERROR/Number") + error_code = REXML::XPath.first(status, 'ERROR/Number') response['ErrorCode'] = error_code.text if error_code end parse_error(root, message) response[:Message] = message end # Parse a generic error response from the gateway - def parse_error(root, message = "") + def parse_error(root, message = '') # Get errors if available and append them to the message errors = errors_to_string(root) unless errors.strip.blank? message << ' - ' unless message.strip.blank? message << errors @@ -374,11 +374,11 @@ # Parses all <ERROR> elements in the response and converts the information # to a single string def errors_to_string(root) # Get context error messages (can be 0..*) errors = [] - REXML::XPath.each(root, "//ERROR") do |error_elem| + REXML::XPath.each(root, '//ERROR') do |error_elem| error = {} error[:Advice] = [] error[:Message] = error_elem.elements['Message'].text error_elem.elements.each('Advice') do |advice| error[:Advice] << advice.text @@ -399,22 +399,22 @@ string end # Amex have different AVS response codes AMEX_TRANSLATED_AVS_CODES = { - "A" => "B", # CSC and Address Matched - "F" => "D", # All Data Matched - "N" => "I", # CSC Match - "U" => "U", # Data Not Checked - "Y" => "D", # All Data Matched - "Z" => "P", # CSC and Postcode Matched + 'A' => 'B', # CSC and Address Matched + 'F' => 'D', # All Data Matched + 'N' => 'I', # CSC Match + 'U' => 'U', # Data Not Checked + 'Y' => 'D', # All Data Matched + 'Z' => 'P', # CSC and Postcode Matched } # Amex have different AVS response codes to visa etc def avs_code(response, options) if response.has_key?(:AVS_ProviderResultCode) - if options[:credit_card].present? && ActiveMerchant::Billing::CreditCard.brand?(options[:credit_card].number) == "american_express" + if options[:credit_card].present? && ActiveMerchant::Billing::CreditCard.brand?(options[:credit_card].number) == 'american_express' AMEX_TRANSLATED_AVS_CODES[response[:AVS_ProviderResultCode]] else response[:AVS_ProviderResultCode] end end @@ -422,10 +422,10 @@ # Encode login and password in Base64 to supply as HTTP header # (for http basic authentication) def encoded_credentials credentials = [@options[:login], @options[:password]].join(':') - "Basic " << Base64.encode64(credentials).strip + 'Basic ' << Base64.encode64(credentials).strip end end end end