lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.84.0 vs lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.85.0
- old
+ new
@@ -99,11 +99,11 @@
super
end
def purchase(amount, payment, options = {})
if payment.is_a?(String)
- commit(:cim_purchase) do |xml|
+ commit(:cim_purchase, options) do |xml|
add_cim_auth_purchase(xml, 'profileTransAuthCapture', amount, payment, options)
end
else
commit(:purchase) do |xml|
add_auth_purchase(xml, 'authCaptureTransaction', amount, payment, options)
@@ -111,11 +111,11 @@
end
end
def authorize(amount, payment, options={})
if payment.is_a?(String)
- commit(:cim_authorize) do |xml|
+ commit(:cim_authorize, options) do |xml|
add_cim_auth_purchase(xml, 'profileTransAuthOnly', amount, payment, options)
end
else
commit(:authorize) do |xml|
add_auth_purchase(xml, 'authOnlyTransaction', amount, payment, options)
@@ -271,24 +271,26 @@
add_payment_source(xml, payment, options)
add_invoice(xml, transaction_type, options)
add_tax_exempt_status(xml, options)
end
end
+ add_extra_options_for_cim(xml, options)
end
def cim_capture(amount, authorization, options)
- commit(:cim_capture) do |xml|
+ commit(:cim_capture, options) do |xml|
add_order_id(xml, options)
xml.transaction do
xml.profileTransPriorAuthCapture do
xml.amount(amount(amount))
add_tax_fields(xml, options)
add_shipping_fields(xml, options)
add_duty_fields(xml, options)
xml.transId(transaction_id_from(authorization))
end
end
+ add_extra_options_for_cim(xml, options)
end
end
def normal_capture(amount, authorization, options)
commit(:capture) do |xml|
@@ -309,11 +311,11 @@
end
def cim_refund(amount, authorization, options)
transaction_id, card_number, _ = split_authorization(authorization)
- commit(:cim_refund) do |xml|
+ commit(:cim_refund, options) do |xml|
add_order_id(xml, options)
xml.transaction do
xml.profileTransRefund do
xml.amount(amount(amount))
add_tax_fields(xml, options)
@@ -322,10 +324,11 @@
xml.creditCardNumberMasked(card_number)
add_invoice(xml, 'profileTransRefund', options)
xml.transId(transaction_id)
end
end
+ add_extra_options_for_cim(xml, options)
end
end
def normal_refund(amount, authorization, options)
transaction_id, card_number, _ = split_authorization(authorization)
@@ -353,17 +356,18 @@
end
end
end
def cim_void(authorization, options)
- commit(:cim_void) do |xml|
+ commit(:cim_void, options) do |xml|
add_order_id(xml, options)
xml.transaction do
xml.profileTransVoid do
xml.transId(transaction_id_from(authorization))
end
end
+ add_extra_options_for_cim(xml, options)
end
end
def normal_void(authorization, options)
commit(:void) do |xml|
@@ -670,12 +674,16 @@
def add_po_number(xml, options)
xml.poNumber(options[:po_number]) if options[:po_number]
end
+ def add_extra_options_for_cim(xml, options)
+ xml.extraOptions("x_delim_char=#{options[:delimiter]}") if options[:delimiter]
+ end
+
def create_customer_payment_profile(credit_card, options)
- commit(:cim_store_update) do |xml|
+ commit(:cim_store_update, options) do |xml|
xml.customerProfileId options[:customer_profile_id]
xml.paymentProfile do
add_billing_address(xml, credit_card, options)
xml.payment do
xml.creditCard do
@@ -687,11 +695,11 @@
end
end
end
def create_customer_profile(credit_card, options)
- commit(:cim_store) do |xml|
+ commit(:cim_store, options) do |xml|
xml.profile do
xml.merchantCustomerId(truncate(options[:merchant_customer_id], 20) || SecureRandom.hex(10))
xml.description(truncate(options[:description], 255)) unless empty?(options[:description])
xml.email(options[:email]) unless empty?(options[:email])
@@ -710,11 +718,11 @@
end
end
end
def delete_customer_profile(customer_profile_id)
- commit(:cim_store_delete_customer) do |xml|
+ commit(:cim_store_delete_customer, options) do |xml|
xml.customerProfileId(customer_profile_id)
end
end
def names_from(payment_source, address, options)
@@ -740,21 +748,21 @@
def url
test? ? test_url : live_url
end
- def parse(action, raw_response)
+ def parse(action, raw_response, options = {})
if is_cim_action?(action) || action == :verify_credentials
- parse_cim(raw_response)
+ parse_cim(raw_response, options)
else
parse_normal(action, raw_response)
end
end
- def commit(action, &payload)
+ def commit(action, options = {}, &payload)
raw_response = ssl_post(url, post_data(action, &payload), headers)
- response = parse(action, raw_response)
+ response = parse(action, raw_response, options)
avs_result_code = response[:avs_result_code].upcase if response[:avs_result_code]
avs_result = AVSResult.new(code: STANDARD_AVS_CODE_MAPPING[avs_result_code])
cvv_result = CVVResult.new(response[:card_code])
if using_live_gateway_in_test_mode?(response)
@@ -867,11 +875,11 @@
end
response
end
- def parse_cim(body)
+ def parse_cim(body, options)
response = {}
doc = Nokogiri::XML(body).remove_namespaces!
if (element = doc.at_xpath('//messages/message'))
@@ -902,11 +910,11 @@
response[:direct_response] = if(element = doc.at_xpath('//directResponse'))
(empty?(element.content) ? nil : element.content)
end
- response.merge!(parse_direct_response_elements(response))
+ response.merge!(parse_direct_response_elements(response, options))
response
end
def success_from(action, response)
@@ -965,14 +973,14 @@
def auth_was_for_cim?(authorization)
_, _, action = split_authorization(authorization)
action && is_cim_action?(action)
end
- def parse_direct_response_elements(response)
+ def parse_direct_response_elements(response, options)
params = response[:direct_response]
return {} unless params
- parts = params.split(',')
+ parts = params.split(options[:delimiter] || ',')
{
response_code: parts[0].to_i,
response_subcode: parts[1],
response_reason_code: parts[2],
response_reason_text: parts[3],