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

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
# File 'lib/active_merchant/billing/gateways/pagarme.rb', line 46

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

  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



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

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

  void(authorization, options)
end

#scrub(transcript) ⇒ Object



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

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)


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

def supports_scrubbing?
  true
end

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



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

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



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

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

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