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

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



35
36
37
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 35

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

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



39
40
41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 39

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



49
50
51
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 49

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

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



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

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb', line 65

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



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

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