lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.46.0 vs lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.47.0
- old
+ new
@@ -121,10 +121,20 @@
r.process { authorize(100, credit_card, options) }
r.process(:ignore_result) { void(r.authorization, options) }
end
end
+ def supports_scrubbing?
+ true
+ end
+
+ def scrub(transcript)
+ transcript.
+ gsub(%r((<cardNumber>).+(</cardNumber>)), '\1[FILTERED]\2').
+ gsub(%r((<cardCode>).+(</cardCode>)), '\1[FILTERED]\2')
+ end
+
private
def add_payment_source(xml, source)
return unless source
if card_brand(source) == 'check'
@@ -265,11 +275,15 @@
xml.faxNumber(truncate(billing_address[:fax], 25)) unless empty?(billing_address[:fax])
end
unless shipping_address.blank?
xml.shipTo do
- first_name, last_name = names_from(payment_source, shipping_address, options)
+ (first_name, last_name) = if shipping_address[:name]
+ shipping_address[:name].split
+ else
+ [shipping_address[:first_name], shipping_address[:last_name]]
+ end
xml.firstName(truncate(first_name, 50)) unless empty?(first_name)
xml.lastName(truncate(last_name, 50)) unless empty?(last_name)
xml.company(truncate(shipping_address[:company], 50)) unless empty?(shipping_address[:company])
xml.address(truncate(shipping_address[:address1], 60))
@@ -312,20 +326,24 @@
url = (test? ? test_url : live_url)
response = parse(action, ssl_post(url, post_data(&payload), 'Content-Type' => 'text/xml'))
avs_result = AVSResult.new(code: response[:avs_result_code])
cvv_result = CVVResult.new(response[:card_code])
- Response.new(
- success_from(response),
- message_from(response, avs_result, cvv_result),
- response,
- authorization: authorization_from(response),
- test: test?,
- avs_result: avs_result,
- cvv_result: cvv_result,
- fraud_review: fraud_review?(response)
- )
+ if using_live_gateway_in_test_mode?(response)
+ Response.new(false, "Using a live Authorize.net account in Test Mode is not permitted.")
+ else
+ Response.new(
+ success_from(response),
+ message_from(response, avs_result, cvv_result),
+ response,
+ authorization: authorization_from(response),
+ test: test?,
+ avs_result: avs_result,
+ cvv_result: cvv_result,
+ fraud_review: fraud_review?(response)
+ )
+ end
end
def post_data
Nokogiri::XML::Builder.new do |xml|
xml.createTransactionRequest('xmlns' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd') do
@@ -384,10 +402,14 @@
response[:account_number] = if(element = doc.at_xpath("//accountNumber"))
(empty?(element.content) ? nil : element.content[-4..-1])
end
+ response[:test_request] = if(element = doc.at_xpath("//testRequest"))
+ (empty?(element.content) ? nil : element.content)
+ end
+
response
end
def success_from(response)
(
@@ -422,9 +444,13 @@
end
def truncate(value, max_size)
return nil unless value
value.to_s[0, max_size]
+ end
+
+ def using_live_gateway_in_test_mode?(response)
+ !test? && response[:test_request] == "1"
end
end
end
end