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::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

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

Methods included from Versionable

#fetch_version, included

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm, #strftime_yyyymmdd_last_day

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.



15
16
17
18
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 15

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

Instance Method Details

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



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

def authorize(money, payment, options = {})
  MultiResponse.run do |r|
    r.process { commit('tokenize', 'card_tokens', card_token_request(money, payment, options)) }
    options[: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

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



67
68
69
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 67

def inquire(authorization, options = {})
  commit('inquire', inquire_path(authorization, options), {})
end

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



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

def purchase(money, payment, options = {})
  MultiResponse.run do |r|
    r.process { commit('tokenize', 'card_tokens', card_token_request(money, payment, options)) }
    options[: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
50
# 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
  add_idempotency_key(post, options)
  commit('refund', "payments/#{authorization}/refunds", post)
end

#scrub(transcript) ⇒ Object



75
76
77
78
79
80
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 75

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)


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

def supports_scrubbing?
  true
end

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



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

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

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



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

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