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 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


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

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


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

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
# 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[:card_token] = r.authorization.split('|').first
    r.process { commit('purchase', 'payments', purchase_request(money, payment, options)) }
  end
end

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


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

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


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

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)

62
63
64
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 62

def supports_scrubbing?
  true
end

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


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

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


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

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