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

- old
+ new

@@ -8,28 +8,33 @@ self.homepage_url = 'https://www.mercadopago.com/' self.display_name = 'Mercado Pago' self.money_format = :dollars + CARD_BRAND = { + "american_express" => "amex", + "diners_club" => "diners" + } + def initialize(options={}) requires!(options, :access_token) super end def purchase(money, payment, options={}) MultiResponse.run do |r| r.process { commit("tokenize", "card_tokens", card_token_request(money, payment, options)) } - options.merge!(card_brand: payment.brand) + options.merge!(card_brand: (CARD_BRAND[payment.brand] || payment.brand)) options.merge!(card_token: r.authorization.split("|").first) r.process { commit("purchase", "payments", purchase_request(money, payment, options) ) } end end def authorize(money, payment, options={}) MultiResponse.run do |r| r.process { commit("tokenize", "card_tokens", card_token_request(money, payment, options)) } - options.merge!(card_brand: payment.brand) + options.merge!(card_brand: (CARD_BRAND[payment.brand] || payment.brand)) options.merge!(card_token: r.authorization.split("|").first) r.process { commit("authorize", "payments", authorize_request(money, payment, options) ) } end end @@ -78,11 +83,17 @@ post = {} post[:card_number] = payment.number post[:security_code] = payment.verification_value post[:expiration_month] = payment.month post[:expiration_year] = payment.year - post[:cardholder] = { name: payment.name } + post[:cardholder] = { + name: payment.name, + identification: { + type: options[:cardholder_identification_type], + number: options[:cardholder_identification_number] + } + } post end def purchase_request(money, payment, options = {}) post = {} @@ -124,12 +135,11 @@ post[:additional_info].merge!({ payer: { address: { zip_code: address[:zip], - street_number: split_street_address(address[:address1]).first, - street_name: split_street_address(address[:address1]).last + street_name: "#{address[:address1]} #{address[:address2]}" } } }) end end @@ -139,13 +149,11 @@ 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] + street_name: "#{address[:address1]} #{address[:address2]}" } } }) end end @@ -165,19 +173,16 @@ 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] - post[:order] = { - type: options[:order_type] || "mercadopago", - id: options[:order_id] || generate_integer_only_order_id - } + post[:external_reference] = options[:order_id] || SecureRandom.hex(16) end def add_payment(post, options) post[:token] = options[:card_token] - post[:payment_method_id] = options[:card_brand] == "american_express" ? "amex" : options[:card_brand] + post[:payment_method_id] = options[:card_brand] end def parse(body) JSON.parse(body) end @@ -245,13 +250,9 @@ when 200..499 response.body else raise ResponseError.new(response) end - end - - def generate_integer_only_order_id - Time.now.to_i + rand(0..1000) end end end end