Class: ActiveMerchant::Billing::MercadoPagoGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::MercadoPagoGateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/mercado_pago.rb
Constant Summary
collapse
- CARD_BRAND =
{
"american_express" => "amex",
"diners_club" => "diners"
}
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
-
#authorize(money, payment, options = {}) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MercadoPagoGateway
constructor
A new instance of MercadoPagoGateway.
-
#purchase(money, payment, options = {}) ⇒ Object
-
#refund(money, authorization, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#supports_scrubbing? ⇒ Boolean
-
#verify(credit_card, options = {}) ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?
#expdate, #format
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Returns a new instance of MercadoPagoGateway.
18
19
20
21
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 18
def initialize(options={})
requires!(options, :access_token)
super
end
|
Instance Method Details
#authorize(money, payment, options = {}) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 32
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: (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
|
#capture(money, authorization, options = {}) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 41
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
23
24
25
26
27
28
29
30
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 23
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: (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
|
#refund(money, authorization, options = {}) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 49
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
73
74
75
76
77
78
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 73
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
69
70
71
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 69
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 62
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
56
57
58
59
60
|
# File 'lib/active_merchant/billing/gateways/mercado_pago.rb', line 56
def void(authorization, options={})
authorization, _ = authorization.split("|")
post = { status: "cancelled" }
commit("void", "payments/#{authorization}", post)
end
|