Class: ActiveMerchant::Billing::PayuLatamGateway

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

Constant Summary collapse

BRAND_MAP =
{
  'visa' => 'VISA',
  'master' => 'MASTERCARD',
  'american_express' => 'AMEX',
  'diners_club' => 'DINERS'
}
MINIMUMS =
{
  'ARS' => 1700,
  'BRL' => 600,
  'MXN' => 3900,
  'PEN' => 500
}

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

#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 = {}) ⇒ PayuLatamGateway

Returns a new instance of PayuLatamGateway.



31
32
33
34
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 31

def initialize(options={})
  requires!(options, :merchant_id, :account_id, :api_login, :api_key, :payment_country)
  super
end

Instance Method Details

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



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

def authorize(amount, payment_method, options={})
  post = {}
  auth_or_sale(post, 'AUTHORIZATION', amount, payment_method, options)
  commit('auth', post)
end

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 48

def capture(amount, authorization, options={})
  post = {}

  add_credentials(post, 'SUBMIT_TRANSACTION', options)
  add_transaction_elements(post, 'CAPTURE', options)
  add_reference(post, authorization)

  if !amount.nil? && amount.to_f != 0.0
    post[:transaction][:additionalValues] ||= {}
    post[:transaction][:additionalValues][:TX_VALUE] = invoice_for(amount, options)[:TX_VALUE]
  end

  commit('capture', post)
end

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



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

def purchase(amount, payment_method, options={})
  post = {}
  auth_or_sale(post, 'AUTHORIZATION_AND_CAPTURE', amount, payment_method, options)
  commit('purchase', post)
end

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



73
74
75
76
77
78
79
80
81
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 73

def refund(amount, authorization, options={})
  post = {}

  add_credentials(post, 'SUBMIT_TRANSACTION', options)
  add_transaction_elements(post, 'REFUND', options)
  add_reference(post, authorization)

  commit('refund', post)
end

#scrub(transcript) ⇒ Object



113
114
115
116
117
118
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 113

def scrub(transcript)
  transcript.
    gsub(%r((\"creditCard\\\":{\\\"number\\\":\\\")\d+), '\1[FILTERED]').
    gsub(%r((\"securityCode\\\":\\\")\d+), '\1[FILTERED]').
    gsub(%r((\"apiKey\\\":\\\")\w+), '\1[FILTERED]')
end

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



93
94
95
96
97
98
99
100
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 93

def store(payment_method, options = {})
  post = {}

  add_credentials(post, 'CREATE_TOKEN')
  add_payment_method_to_be_tokenized(post, payment_method)

  commit('store', post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 109

def supports_scrubbing?
  true
end

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



83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 83

def verify(credit_card, options={})
  minimum = MINIMUMS[options[:currency].upcase] if options[:currency]
  amount = options[:verify_amount] || minimum || 100

  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(amount, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#verify_credentialsObject



102
103
104
105
106
107
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 102

def verify_credentials
  post = {}
  add_credentials(post, 'GET_PAYMENT_METHODS')
  response = commit('verify_credentials', post)
  response.success?
end

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



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

def void(authorization, options={})
  post = {}

  add_credentials(post, 'SUBMIT_TRANSACTION', options)
  add_transaction_elements(post, 'VOID', options)
  add_reference(post, authorization)

  commit('void', post)
end