lib/active_merchant/billing/gateways/secure_net.rb in activemerchant-1.48.0 vs lib/active_merchant/billing/gateways/secure_net.rb in activemerchant-1.49.0
- old
+ new
@@ -91,12 +91,11 @@
def build_sale_or_authorization(creditcard, options, action, money)
xml = Builder::XmlMarkup.new
xml.tag! 'AMOUNT', amount(money)
add_credit_card(xml, creditcard)
- add_params_in_required_order(xml, action, options)
- add_address(xml, creditcard, options)
+ add_params_in_required_order(xml, action, creditcard, options)
add_more_required_params(xml, options)
xml.target!
end
@@ -108,11 +107,11 @@
xml.tag! 'AMOUNT', amount(money) || amount_in_ref
xml.tag!("CARD") do
xml.tag! 'CARDNUMBER', last_four
end
- add_params_in_required_order(xml, action, options)
+ add_params_in_required_order(xml, action, nil, options)
xml.tag! 'REF_TRANSID', transaction_id
add_more_required_params(xml, options)
xml.target!
end
@@ -134,10 +133,11 @@
xml.tag! 'CUSTOMERIP', options[:ip]
end
end
def add_address(xml, creditcard, options)
+ return unless creditcard
if address = options[:billing_address] || options[:address]
xml.tag!("CUSTOMER_BILL") do
xml.tag! 'ADDRESS', address[:address1].to_s
xml.tag! 'CITY', address[:city].to_s
@@ -159,12 +159,22 @@
xml.tag!("CUSTOMER_SHIP") do
xml.tag! 'ADDRESS', address[:address1].to_s
xml.tag! 'CITY', address[:city].to_s
xml.tag! 'COMPANY', address[:company].to_s
xml.tag! 'COUNTRY', address[:country].to_s
- xml.tag! 'FIRSTNAME', address[:first_name].to_s
- xml.tag! 'LASTNAME', address[:last_name].to_s
+
+ if address[:name]
+ names = address[:name].split
+ last_name = names.pop
+ first_name = names.join(" ")
+ xml.tag! 'FIRSTNAME', first_name
+ xml.tag! 'LASTNAME', last_name
+ else
+ xml.tag! 'FIRSTNAME', address[:first_name].to_s
+ xml.tag! 'LASTNAME', address[:last_name].to_s
+ end
+
xml.tag! 'STATE', address[:state].blank? ? 'n/a' : address[:state]
xml.tag! 'ZIP', address[:zip].to_s
end
else
xml.tag!('CUSTOMER_SHIP', NIL_ATTRIBUTE) do
@@ -180,12 +190,13 @@
xml.tag! 'SECURENETID', @options[:login]
end
end
# SecureNet requires some of the xml params to be in a certain order. http://cl.ly/image/3K260E0p0a0n/content.png
- def add_params_in_required_order(xml, action, options)
+ def add_params_in_required_order(xml, action, creditcard, options)
xml.tag! 'CODE', TRANSACTIONS[action]
add_customer_data(xml, options)
+ add_address(xml, creditcard, options)
xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
xml.tag! 'INVOICEDESC', options[:invoice_description] if options[:invoice_description]
xml.tag! 'INVOICENUM', options[:invoice_number] if options[:invoice_number]
add_merchant_key(xml, options)