lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.62.0 vs lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.63.0

- old
+ new

@@ -157,11 +157,10 @@ xml.amount(amount(amount)) add_payment_source(xml, payment) add_invoice(xml, options) add_customer_data(xml, payment, options) - add_line_items(xml, options) add_settings(xml, payment, options) add_user_fields(xml, amount, options) end end end @@ -179,10 +178,16 @@ else create_customer_profile(credit_card, options) end end + def unstore(authorization) + customer_profile_id, _, _ = split_authorization(authorization) + + delete_customer_profile(customer_profile_id) + end + def verify_credentials response = commit(:verify_credentials) { } response.success? end @@ -231,11 +236,10 @@ xml.amount(amount(amount)) add_payment_source(xml, payment) add_invoice(xml, options) add_customer_data(xml, payment, options) add_market_type_device_type(xml, payment, options) - add_line_items(xml, options) add_settings(xml, payment, options) add_user_fields(xml, amount, options) end end @@ -345,23 +349,10 @@ else add_credit_card(xml, source) end end - def add_line_items(xml, options) - return unless options[:line_items] - xml.lineItems do - options[:line_items].each do |line_item| - xml.lineItem do - line_item.each do |key, value| - xml.send(camel_case_lower(key), value) - end - end - end - end - end - def camel_case_lower(key) String(key).split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join end def add_settings(xml, source, options) @@ -573,10 +564,23 @@ def add_invoice(xml, options) xml.order do xml.invoiceNumber(truncate(options[:order_id], 20)) xml.description(truncate(options[:description], 255)) end + + # Authorize.net API requires lineItems to be placed directly after order tag + if options[:line_items] + xml.lineItems do + options[:line_items].each do |line_item| + xml.lineItem do + line_item.each do |key, value| + xml.send(camel_case_lower(key), value) + end + end + end + end + end end def create_customer_payment_profile(credit_card, options) commit(:cim_store_update) do |xml| xml.customerProfileId options[:customer_profile_id] @@ -614,10 +618,16 @@ end end end end + def delete_customer_profile(customer_profile_id) + commit(:cim_store_delete_customer) do |xml| + xml.customerProfileId(customer_profile_id) + end + end + def names_from(payment_source, address, options) if payment_source && !payment_source.is_a?(PaymentToken) && !payment_source.is_a?(String) first_name, last_name = split_names(address[:name]) [(payment_source.first_name || first_name), (payment_source.last_name || last_name)] else @@ -681,10 +691,12 @@ def root_for(action) if action == :cim_store "createCustomerProfileRequest" elsif action == :cim_store_update "createCustomerPaymentProfileRequest" + elsif action == :cim_store_delete_customer + "deleteCustomerProfileRequest" elsif action == :verify_credentials "authenticateTestRequest" elsif is_cim_action?(action) "createCustomerProfileTransactionRequest" else @@ -825,10 +837,10 @@ def split_authorization(authorization) authorization.split("#") end def cim?(action) - (action == :cim_store) || (action == :cim_store_update) + (action == :cim_store) || (action == :cim_store_update) || (action == :cim_store_delete_customer) end def transaction_id_from(authorization) transaction_id, _, _ = split_authorization(authorization) transaction_id