Class: TBK::Webpay::Logger::OfficialLogger

Inherits:
BaseLogger
  • Object
show all
Defined in:
lib/tbk/webpay/logger/official_logger.rb

Instance Method Summary collapse

Methods inherited from BaseLogger

#initialize

Constructor Details

This class inherits a constructor from TBK::Webpay::Logger::BaseLogger

Instance Method Details

#confirmation(confirmation) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tbk/webpay/logger/official_logger.rb', line 47

def confirmation(confirmation)
  events_log_file do |file|
    file.write CONFIRMATION_FORMAT % {
      date: now.strftime(LOG_DATE_FORMAT),
      time: now.strftime(LOG_TIME_FORMAT),
      pid: Process.pid,
      commerce_id: confirmation.commerce.id,
      transaction_id: confirmation.transaction_id,
      request_ip: confirmation.request_ip,
      order_id: confirmation.order_id,
    }
  end

  bitacora_log_file do |file|
    file.write BITACORA_FORMAT % {'TBK_VCI' => ''}.merge(confirmation.params).merge({
      commerce_id: confirmation.commerce.id
    })
  end
end

#directory(directory = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/tbk/webpay/logger/official_logger.rb', line 8

def directory(directory=nil)
  if directory
    @directory = Pathname(directory)

    # Create the directory if needed
    Dir.mkdir(@directory) unless Dir.exists?(@directory)
  end

  @directory
end

#payment(payment) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tbk/webpay/logger/official_logger.rb', line 19

def payment(payment)
  events_log_file do |file|
    file.write PAYMENT_FORMAT % {
      date: now.strftime(LOG_DATE_FORMAT),
      time: now.strftime(LOG_TIME_FORMAT),
      pid: Process.pid,
      commerce_id: payment.commerce.id,
      transaction_id: payment.transaction_id,
      request_ip: payment.request_ip,
      token: payment.token,
      webpay_server: (payment.commerce.test? ? 'https://certificacion.webpay.cl' : 'https://webpay.transbank.cl')
    }
  end

  configuration_log_file do |file|
    response_uri = URI.parse(payment.confirmation_url)

    file.write CONFIGURATION_FORMAT % {
      commerce_id: payment.commerce.id,
      server_ip: response_uri.host,
      server_port: response_uri.port,
      response_path: response_uri.path,
      webpay_server: (payment.commerce.test? ? 'https://certificacion.webpay.cl' : 'https://webpay.transbank.cl'),
      webpay_server_port: (payment.commerce.test? ? '6433' : '433')
    }
  end
end