lib/active_merchant/billing/gateways/safe_charge.rb in activemerchant-1.75.0 vs lib/active_merchant/billing/gateways/safe_charge.rb in activemerchant-1.76.0

- old
+ new

@@ -20,11 +20,13 @@ super end def purchase(money, payment, options={}) post = {} - add_transaction_data("Sale", post, money, options) + post[:sg_APIType] = 1 if options[:three_d_secure] + trans_type = options[:three_d_secure] ? "Sale3D" : "Sale" + add_transaction_data(trans_type, post, money, options) add_payment(post, payment) add_customer_details(post, payment, options) commit(post) end @@ -118,10 +120,13 @@ post[:sg_Version] = VERSION post[:sg_ClientUniqueID] = options[:order_id] if options[:order_id] post[:sg_UserID] = options[:user_id] if options[:user_id] post[:sg_AuthType] = options[:auth_type] if options[:auth_type] post[:sg_ExpectedFulfillmentCount] = options[:expected_fulfillment_count] if options[:expected_fulfillment_count] + post[:sg_WebsiteID] = options[:website_id] if options[:website_id] + post[:sg_IPAddress] = options[:ip] if options[:ip] + post[:sg_VendorID] = options[:vendor_id] if options[:vendor_id] end def add_payment(post, payment) post[:sg_NameOnCard] = payment.name post[:sg_CardNumber] = payment.number @@ -148,22 +153,33 @@ def parse(xml) response = {} doc = Nokogiri::XML(xml) doc.root.xpath('*').each do |node| - response[node.name.underscore.downcase.to_sym] = node.text + if node.elements.size == 0 + response[node.name.underscore.downcase.to_sym] = node.text + else + node.traverse do |childnode| + childnode_to_response(response, childnode) + end + end end - response end - def childnode_to_response(response, node, childnode) - name = "#{node.name.downcase}_#{childnode.name.downcase}" - if name == 'payment_method_data' && !childnode.elements.empty? - response[name.to_sym] = Hash.from_xml(childnode.to_s).values.first + def childnode_to_response(response, childnode) + if childnode.elements.size == 0 + element_name_to_symbol(response, childnode) else - response[name.to_sym] = childnode.text + childnode.traverse do |childnode| + element_name_to_symbol(response, childnode) + end end + end + + def element_name_to_symbol(response, childnode) + name = "#{childnode.name.downcase}" + response[name.to_sym] = childnode.text end def commit(parameters) url = (test? ? test_url : live_url) response = parse(ssl_post(url, post_data(parameters)))