lib/active_merchant/billing/gateways/creditcall.rb in activemerchant-1.70.0 vs lib/active_merchant/billing/gateways/creditcall.rb in activemerchant-1.71.0

- old
+ new

@@ -12,10 +12,36 @@ self.default_currency = 'USD' self.supported_cardtypes = [:visa, :master, :american_express, :discover] self.homepage_url = 'https://www.creditcall.com' self.display_name = 'Creditcall' + + CVV_CODE = { + "matched" => "M", + "notmatched" => "N", + "notchecked" => "P", + "partialmatch" => "N" + } + + AVS_CODE = { + "matched;matched" => "D", + "matched;notchecked" =>"B", + "matched;notmatched" => "A", + "matched;partialmatch" => "A", + "notchecked;matched" => "P", + "notchecked;notchecked" =>"I", + "notchecked;notmatched" => "I", + "notchecked;partialmatch" => "I", + "notmatched;matched" => "W", + "notmatched;notchecked" =>"C", + "notmatched;notmatched" => "C", + "notmatched;partialmatch" => "C", + "partialmatched;matched" => "W", + "partialmatched;notchecked" =>"C", + "partialmatched;notmatched" => "C", + "partialmatched;partialmatch" => "C" + } def initialize(options={}) requires!(options, :terminal_id, :transaction_key) super end @@ -24,15 +50,20 @@ multi_response = MultiResponse.run do |r| r.process { authorize(money, payment_method, options) } r.process { capture(money, r.authorization, options) } end + merged_params = multi_response.responses.map { |r| r.params }.reduce({}, :merge) + Response.new( multi_response.primary_response.success?, multi_response.primary_response.message, - multi_response.primary_response.params, + merged_params, authorization: multi_response.responses.first.authorization, + avs_result: AVSResult.new(code: avs_result_code_from(merged_params)), + cvv_result: CVVResult.new(cvv_result_code_from(merged_params)), + error_code: error_result_code_from(merged_params), test: test? ) end def authorize(money, payment_method, options={}) @@ -90,10 +121,22 @@ gsub(%r((<CSC>).+?(</CSC>))i, '\1[FILTERED]\2') end private + def avs_result_code_from(params) + AVS_CODE["#{params['Address']};#{params['Zip']}"] + end + + def cvv_result_code_from(params) + CVV_CODE[params["CSC"]] + end + + def error_result_code_from(params) + params["ErrorCode"] + end + def build_xml_request builder = Nokogiri::XML::Builder.new do |xml| xml.Request(type: "CardEaseXML", version: "1.0.0") do yield(xml) end @@ -118,21 +161,26 @@ end end def add_card_details(xml, payment_method, options={}) xml.CardDetails do - xml.Manual(type: "ecommerce") do + xml.Manual(type: manual_type(options)) do xml.PAN payment_method.number xml.ExpiryDate exp_date(payment_method) xml.CSC payment_method.verification_value unless empty?(payment_method.verification_value) end - if address = options[:billing_address] - xml.AdditionalVerification do - xml.Address address[:address1] - xml.Zip address[:zip] - end + add_additional_verification(xml, options) + end + end + + def add_additional_verification(xml, options) + return unless (options[:verify_zip].to_s == 'true') || (options[:verify_address].to_s == 'true') + if address = options[:billing_address] + xml.AdditionalVerification do + xml.Zip address[:zip] if options[:verify_zip].to_s == 'true' + xml.Address address[:address1] if options[:verify_address].to_s == 'true' end end end def exp_date(payment_method) @@ -155,10 +203,20 @@ else childnode_to_response(response, childnode) end end + node = xml.xpath("//Response/CardDetails") + node.children.each do |childnode| + if childnode.elements.empty? + response[childnode.name] = childnode.text + else + childnode_to_response(response, childnode) + end + end + + response end def childnode_to_response(response, childnode) childnode.elements.each do |element| @@ -177,12 +235,13 @@ Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), - avs_result: AVSResult.new(code: response["some_avs_response_key"]), - cvv_result: CVVResult.new(response["some_cvv_response_key"]), + avs_result: AVSResult.new(code: avs_result_code_from(response)), + cvv_result: CVVResult.new(cvv_result_code_from(response)), + error_code: error_result_code_from(response), test: test? ) end def url @@ -203,8 +262,11 @@ def authorization_from(response) response["CardEaseReference"] end + def manual_type(options) + options[:manual_type] ? options[:manual_type] : "ecommerce" + end end end end