lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.103.0 vs lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.104.0

- old
+ new

@@ -43,11 +43,11 @@ post[:description] = options[:description] add_common_params(post, options) MultiResponse.run do |r| identifier = - if(payment_method.respond_to?(:number)) + if payment_method.respond_to?(:number) r.process { store(payment_method, options) } r.authorization else payment_method end @@ -61,11 +61,11 @@ post[:description] = options[:description] add_common_params(post, options) MultiResponse.run do |r| identifier = - if(payment_method.respond_to?(:number)) + if payment_method.respond_to?(:number) r.process { store(payment_method, options) } r.authorization else payment_method end @@ -137,11 +137,11 @@ post[:amount] = amount(money) if money end def add_address(post, options) address = (options[:billing_address] || options[:address]) - if(address && address[:zip].present?) + if address && address[:zip].present? post[:address] = {} post[:address][:line1] = address[:address1] if address[:address1] post[:address][:line2] = address[:address2] if address[:address2] post[:address][:city] = address[:city] if address[:city] post[:address][:state] = address[:state] if address[:state] @@ -157,18 +157,20 @@ end def commit(entity_name, path, post, method=:post) raw_response = begin - parse(ssl_request( - method, - live_url + "/#{path}", - post_data(post), - headers - )) + parse( + ssl_request( + method, + live_url + "/#{path}", + post_data(post), + headers + )) rescue ResponseError => e - raise unless(e.response.code.to_s =~ /4\d\d/) + raise unless e.response.code.to_s =~ /4\d\d/ + parse(e.response.body) end Response.new( success_from(entity_name, raw_response), @@ -179,25 +181,25 @@ ) end def success_from(entity_name, raw_response) entity = (raw_response[entity_name] || []).first - if(!entity) + if !entity false - elsif((entity_name == 'refunds') && entity.include?('status')) + elsif (entity_name == 'refunds') && entity.include?('status') %w(succeeded pending).include?(entity['status']) - elsif(entity.include?('status')) + elsif entity.include?('status') (entity['status'] == 'succeeded') - elsif(entity_name == 'cards') + elsif entity_name == 'cards' !!entity['id'] else false end end def message_from(raw_response) - if(raw_response['errors']) + if raw_response['errors'] error = raw_response['errors'].first (error['additional'] || error['message'] || error['description']) else 'Success' end @@ -223,9 +225,10 @@ def post_data(params) return nil unless params params.map do |key, value| next if value.blank? + if value.is_a?(Hash) h = {} value.each do |k, v| h["#{key}[#{k}]"] = v unless v.blank? end