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',
  'maestro' => 'MASTERCARD',
  'american_express' => 'AMEX',
  'diners_club' => 'DINERS',
  'naranja' => 'NARANJA',
  'cabal' => 'CABAL'
}
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

#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, #strftime_yyyymm

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.



34
35
36
37
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 34

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



45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 45

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



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

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



39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 39

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 76

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

  add_credentials(post, 'SUBMIT_TRANSACTION', options)

  if options[:partial_refund]
    add_transaction_elements(post, 'PARTIAL_REFUND', options)
    post[:transaction][:additionalValues] ||= {}
    post[:transaction][:additionalValues][:TX_VALUE] = invoice_for(amount, options)[:TX_VALUE]
  else
    add_transaction_elements(post, 'REFUND', options)
  end

  add_reference(post, authorization)
  commit('refund', post)
end

#scrub(transcript) ⇒ Object



123
124
125
126
127
128
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 123

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



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

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

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

  commit('store', post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 119

def supports_scrubbing?
  true
end

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



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

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



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

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

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



66
67
68
69
70
71
72
73
74
# File 'lib/active_merchant/billing/gateways/payu_latam.rb', line 66

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