lib/active_merchant/billing/gateways/mit.rb in activemerchant-1.131.0 vs lib/active_merchant/billing/gateways/mit.rb in activemerchant-1.133.0

- old
+ new

@@ -91,12 +91,11 @@ post_to_json = post.to_json post_to_json_encrypt = encrypt(post_to_json, @options[:key_session]) final_post = '<authorization>' + post_to_json_encrypt + '</authorization><dataID>' + @options[:user] + '</dataID>' - json_post = {} - json_post[:payload] = final_post + json_post = final_post commit('sale', json_post) end def capture(money, authorization, options = {}) post = { @@ -112,12 +111,11 @@ post_to_json = post.to_json post_to_json_encrypt = encrypt(post_to_json, @options[:key_session]) final_post = '<capture>' + post_to_json_encrypt + '</capture><dataID>' + @options[:user] + '</dataID>' - json_post = {} - json_post[:payload] = final_post + json_post = final_post commit('capture', json_post) end def refund(money, authorization, options = {}) post = { @@ -134,23 +132,30 @@ post_to_json = post.to_json post_to_json_encrypt = encrypt(post_to_json, @options[:key_session]) final_post = '<refund>' + post_to_json_encrypt + '</refund><dataID>' + @options[:user] + '</dataID>' - json_post = {} - json_post[:payload] = final_post + json_post = final_post commit('refund', json_post) end def supports_scrubbing? true end + def extract_mit_responses_from_transcript(transcript) + groups = transcript.scan(/reading \d+ bytes(.*?)read \d+ bytes/m) + groups.map do |group| + group.first.scan(/-> "(.*?)"/).flatten.map(&:strip).join('') + end + end + def scrub(transcript) ret_transcript = transcript auth_origin = ret_transcript[/<authorization>(.*?)<\/authorization>/, 1] unless auth_origin.nil? + auth_origin = auth_origin.gsub('\n', '') auth_decrypted = decrypt(auth_origin, @options[:key_session]) auth_json = JSON.parse(auth_decrypted) auth_json['card'] = '[FILTERED]' auth_json['cvv'] = '[FILTERED]' auth_json['apikey'] = '[FILTERED]' @@ -160,10 +165,11 @@ ret_transcript = ret_transcript.gsub(/<authorization>(.*?)<\/authorization>/, auth_tagged) end cap_origin = ret_transcript[/<capture>(.*?)<\/capture>/, 1] unless cap_origin.nil? + cap_origin = cap_origin.gsub('\n', '') cap_decrypted = decrypt(cap_origin, @options[:key_session]) cap_json = JSON.parse(cap_decrypted) cap_json['apikey'] = '[FILTERED]' cap_json['key_session'] = '[FILTERED]' cap_to_json = cap_json.to_json @@ -171,28 +177,24 @@ ret_transcript = ret_transcript.gsub(/<capture>(.*?)<\/capture>/, cap_tagged) end ref_origin = ret_transcript[/<refund>(.*?)<\/refund>/, 1] unless ref_origin.nil? + ref_origin = ref_origin.gsub('\n', '') ref_decrypted = decrypt(ref_origin, @options[:key_session]) ref_json = JSON.parse(ref_decrypted) ref_json['apikey'] = '[FILTERED]' ref_json['key_session'] = '[FILTERED]' ref_to_json = ref_json.to_json ref_tagged = '<refund>' + ref_to_json + '</refund>' ret_transcript = ret_transcript.gsub(/<refund>(.*?)<\/refund>/, ref_tagged) end - res_origin = ret_transcript[/#{Regexp.escape('reading ')}(.*?)#{Regexp.escape('read')}/m, 1] - loop do - break if res_origin.nil? - - resp_origin = res_origin[/#{Regexp.escape('"')}(.*?)#{Regexp.escape('"')}/m, 1] - resp_decrypted = decrypt(resp_origin, @options[:key_session]) - ret_transcript[/#{Regexp.escape('reading ')}(.*?)#{Regexp.escape('read')}/m, 1] = resp_decrypted - ret_transcript = ret_transcript.sub('reading ', 'response: ') - res_origin = ret_transcript[/#{Regexp.escape('reading ')}(.*?)#{Regexp.escape('read')}/m, 1] + groups = extract_mit_responses_from_transcript(transcript) + groups.each do |group| + group_decrypted = decrypt(group, @options[:key_session]) + ret_transcript = ret_transcript.gsub('Conn close', "\n" + group_decrypted + "\nConn close") end ret_transcript end @@ -217,12 +219,10 @@ post[:cvv] = payment.verification_value post[:name_client] = [payment.first_name, payment.last_name].join(' ') end def commit(action, parameters) - json_str = JSON.generate(parameters) - cleaned_str = json_str.gsub('\n', '') - raw_response = ssl_post(live_url, cleaned_str, { 'Content-type' => 'application/json' }) + raw_response = ssl_post(live_url, parameters, { 'Content-type' => 'text/plain' }) response = JSON.parse(decrypt(raw_response, @options[:key_session])) Response.new( success_from(response), message_from(response),