Class: ActiveMerchant::Billing::PagarmeGateway

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

Constant Summary collapse

STANDARD_ERROR_CODE_MAPPING =
{
  'refused' => STANDARD_ERROR_CODE[:card_declined],
  'processing_error' => STANDARD_ERROR_CODE[:processing_error],
}

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?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ PagarmeGateway

Returns a new instance of PagarmeGateway.



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

def initialize(options={})
  requires!(options, :api_key)
  @api_key = options[:api_key]

  super
end

Instance Method Details

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



35
36
37
38
39
40
41
42
43
44
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 35

def authorize(money, payment_method, options={})
  post = {}
  add_amount(post, money)
  add_payment_method(post, payment_method)
  (post, options)

  post[:capture] = false

  commit(:post, 'transactions', post)
end

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



46
47
48
49
50
51
52
53
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 46

def capture(money, authorization, options={})
  if authorization.nil?
    return Response.new(false, 'Não é possível capturar uma transação sem uma prévia autorização.')
  end

  post = {}
  commit(:post, "transactions/#{authorization}/capture", post)
end

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



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

def purchase(money, payment_method, options={})
  post = {}
  add_amount(post, money)
  add_payment_method(post, payment_method)
  (post, options)

  commit(:post, 'transactions', post)
end

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



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

def refund(money, authorization, options={})
  if authorization.nil?
    return Response.new(false, 'Não é possível estornar uma transação sem uma prévia captura.')
  end

  void(authorization, options)
end

#scrub(transcript) ⇒ Object



83
84
85
86
87
88
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 83

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((card_number=)\d+), '\1[FILTERED]').
    gsub(%r((card_cvv=)\d+), '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 79

def supports_scrubbing?
  true
end

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



72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 72

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

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



63
64
65
66
67
68
69
70
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 63

def void(authorization, options={})
  if authorization.nil?
    return Response.new(false, 'Não é possível estornar uma transação autorizada sem uma prévia autorização.')
  end

  post = {}
  commit(:post, "transactions/#{authorization}/refund", post)
end