Class: ActiveMerchant::Billing::CecabankJsonGateway

Inherits:
Gateway
  • Object
show all
Includes:
CecabankCommon
Defined in:
lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb

Constant Summary collapse

CECA_ACTIONS_DICTIONARY =
{
  purchase: :REST_AUTORIZACION,
  authorize: :REST_PREAUTORIZACION,
  capture: :REST_COBRO_PREAUTORIZACION,
  refund: :REST_DEVOLUCION,
  void: :REST_ANULACION
}.freeze
CECA_REASON_TYPES =
{
  installment: :I,
  recurring: :R,
  unscheduled: :C
}.freeze
CECA_INITIATOR =
{
  merchant: :N,
  cardholder: :S
}.freeze
CECA_SCA_TYPES =
{
  low_value_exemption: :LOW,
  transaction_risk_analysis_exemption: :TRA
}.freeze
WALLET_PAYMENT_METHODS =
{
  apple_pay: 'A',
  google_pay: 'G'
}

Constants included from CecabankCommon

CecabankCommon::CECA_CURRENCIES_DICTIONARY, CecabankCommon::CECA_ENCRIPTION

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 included from CecabankCommon

included, #initialize, #supports_scrubbing?

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #initialize, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm

Methods included from PostsData

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

Instance Method Details

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



40
41
42
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 40

def authorize(money, creditcard, options = {})
  handle_purchase(:authorize, money, creditcard, options)
end

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



44
45
46
47
48
49
50
51
52
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 44

def capture(money, identification, options = {})
  authorization, operation_number, _money = identification.split('#')

  post = {}
  options[:operation_number] = operation_number
  add_auth_invoice_data(:capture, post, money, authorization, options)

  commit('compra', post)
end

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



54
55
56
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 54

def purchase(money, creditcard, options = {})
  handle_purchase(:purchase, money, creditcard, options)
end

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



64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 64

def refund(money, identification, options = {})
  authorization, operation_number, _money = identification.split('#')
  options[:operation_number] = operation_number
  handle_cancellation(:refund, money, authorization, options)
end

#scrub(transcript) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 70

def scrub(transcript)
  return '' if transcript.blank?

  before_message = transcript.gsub(%r(\\\")i, "'").scan(/{[^>]*}/).first.gsub("'", '"')
  request_data = JSON.parse(before_message)

  if @options[:encryption_key]
    params = parse(request_data['parametros'])
    sensitive_fields = decrypt_sensitive_fields(params['encryptedData'])
    filtered_params = filter_params(sensitive_fields)
    params['encryptedData'] = encrypt_sensitive_fields(filtered_params)
  else
    params = filter_params(decode_params(request_data['parametros']))
  end

  request_data['parametros'] = encode_params(params)
  before_message = before_message.gsub(%r(\")i, '\\\"')
  after_message = request_data.to_json.gsub(%r(\")i, '\\\"')
  transcript.sub(before_message, after_message)
end

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



58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 58

def void(identification, options = {})
  authorization, operation_number, money = identification.split('#')
  options[:operation_number] = operation_number
  handle_cancellation(:void, money.to_i, authorization, options)
end