Class: ActiveMerchant::Billing::MercadoPagoGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/mercado_pago.rb

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ MercadoPagoGateway

Returns a new instance of MercadoPagoGateway.



13
14
15
16
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 13

def initialize(options={})
  requires!(options, :access_token)
  super
end

Instance Method Details

#authorize(money, payment, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 27

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_token: r.authorization.split("|").first)
    r.process { commit("authorize", "payments", authorize_request(money, payment, options) ) }
  end
end

#capture(money, authorization, options = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 36

def capture(money, authorization, options={})
  post = {}
  authorization, _ = authorization.split("|")
  post[:capture] = true
  post[:transaction_amount] = amount(money).to_f
  commit("capture", "payments/#{authorization}", post)
end

#purchase(money, payment, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 18

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_token: r.authorization.split("|").first)
    r.process { commit("purchase", "payments", purchase_request(money, payment, options) ) }
  end
end

#refund(money, authorization, options = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 44

def refund(money, authorization, options={})
  post = {}
  authorization, original_amount = authorization.split("|")
  post[:amount] = amount(money).to_f if original_amount && original_amount.to_f > amount(money).to_f
  commit("refund", "payments/#{authorization}/refunds", post)
end

#scrub(transcript) ⇒ Object



68
69
70
71
72
73
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 68

def scrub(transcript)
  transcript.
    gsub(%r((access_token=).*?([^\s]+)), '\1[FILTERED]').
    gsub(%r((\"card_number\\\":\\\")\d+), '\1[FILTERED]').
    gsub(%r((\"security_code\\\":\\\")\d+), '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 64

def supports_scrubbing?
  true
end

#verify(credit_card, options = {}) ⇒ Object



57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 57

def verify(credit_card, options={})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#void(authorization, options = {}) ⇒ Object



51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 51

def void(authorization, options={})
  authorization, _ = authorization.split("|")
  post = { status: "cancelled" }
  commit("void", "payments/#{authorization}", post)
end