lib/active_merchant/billing/gateways/mercado_pago.rb in activemerchant-1.70.0 vs lib/active_merchant/billing/gateways/mercado_pago.rb in activemerchant-1.71.0

- old
+ new

@@ -89,26 +89,28 @@ add_invoice(post, money, options) add_payment(post, options) add_additional_data(post, options) add_customer_data(post, payment, options) add_address(post, options) + post[:binary_mode] = true post end def authorize_request(money, payment, options = {}) post = purchase_request(money, payment, options) post.merge!(capture: false) post end def add_additional_data(post, options) - post[:sponsor_id] = options["sponsor_id"] + post[:sponsor_id] = options[:sponsor_id] post[:additional_info] = { ip_address: options[:ip_address] } add_address(post, options) + add_shipping_address(post, options) end def add_customer_data(post, payment, options) post[:payer] = { email: options[:email], @@ -117,25 +119,51 @@ } end def add_address(post, options) if address = (options[:billing_address] || options[:address]) - street_number = address[:address1].split(" ").first - street_name = address[:address1].split(" ")[1..-1].join(" ") - post[:additional_info] = { + post[:additional_info].merge!({ payer: { address: { zip_code: address[:zip], - street_number: street_number, - street_name: street_name, + street_number: split_street_address(address[:address1]).first, + street_name: split_street_address(address[:address1]).last } } - } + }) end end + def add_shipping_address(post, options) + if address = options[:shipping_address] + + post[:additional_info].merge!({ + shipments: { + receiver_address: { + zip_code: address[:zip], + street_number: split_street_address(address[:address1]).first, + street_name: split_street_address(address[:address1]).last, + apartment: address[:address2] + } + } + }) + end + end + + def split_street_address(address1) + street_number = address1.split(" ").first + + if street_name = address1.split(" ")[1..-1] + street_name = street_name.join(" ") + else + nil + end + + [street_number, street_name] + end + def add_invoice(post, money, options) post[:transaction_amount] = amount(money).to_f post[:description] = options[:description] post[:installments] = options[:installments] ? options[:installments].to_i : 1 post[:statement_descriptor] = options[:statement_descriptor] if options[:statement_descriptor] @@ -145,10 +173,10 @@ } end def add_payment(post, options) post[:token] = options[:card_token] - post[:payment_method_id] = options[:card_brand] + post[:payment_method_id] = options[:card_brand] == "american_express" ? "amex" : options[:card_brand] end def parse(body) JSON.parse(body) end