Class: TBK::Webpay::Confirmation

Inherits:
Object
  • Object
show all
Defined in:
lib/tbk/webpay/confirmation.rb

Constant Summary collapse

RESPONSE_CODES =
{
  '0' => 'Transacción aprobada.',
  '-1' => 'Rechazo de tx. en B24, No autorizada',
  '-2' => 'Transacción debe reintentarse.',
  '-3' => 'Error en tx.',
  '-4' => 'Rechazo de tx. En B24, No autorizada',
  '-5' => 'Rechazo por error de tasa.',
  '-6' => 'Excede cupo máximo mensual.',
  '-7' => 'Excede límite diario por transacción.',
  '-8' => 'Rubro no autorizado.'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Confirmation

Returns a new instance of Confirmation.



22
23
24
25
26
27
28
# File 'lib/tbk/webpay/confirmation.rb', line 22

def initialize(options)
  options = { :body => options } if options.is_a?(String)

  self.commerce = options[:commerce] || TBK::Commerce.default_commerce
  self.request_ip = options[:request_ip]
  self.parse(options[:body])
end

Instance Attribute Details

#commerceObject

Returns the value of attribute commerce.



17
18
19
# File 'lib/tbk/webpay/confirmation.rb', line 17

def commerce
  @commerce
end

#paramsObject (readonly)

Returns the value of attribute params.



20
21
22
# File 'lib/tbk/webpay/confirmation.rb', line 20

def params
  @params
end

#rawObject (readonly)

Returns the value of attribute raw.



19
20
21
# File 'lib/tbk/webpay/confirmation.rb', line 19

def raw
  @raw
end

#request_ipObject

Returns the value of attribute request_ip.



18
19
20
# File 'lib/tbk/webpay/confirmation.rb', line 18

def request_ip
  @request_ip
end

Instance Method Details

#acknowledgeObject



30
31
32
# File 'lib/tbk/webpay/confirmation.rb', line 30

def acknowledge
  self.commerce.webpay_encrypt('ACK')
end

#amountObject



54
55
56
# File 'lib/tbk/webpay/confirmation.rb', line 54

def amount
  self.params[:TBK_MONTO].to_f/100
end

#authorizationObject



58
59
60
# File 'lib/tbk/webpay/confirmation.rb', line 58

def authorization
  self.params[:TBK_CODIGO_AUTORIZACION]
end

#card_display_numberObject



66
67
68
# File 'lib/tbk/webpay/confirmation.rb', line 66

def card_display_number
  "XXXX-XXXX-XXXX-#{ card_last_numbers }"
end

#card_last_numbersObject



70
71
72
# File 'lib/tbk/webpay/confirmation.rb', line 70

def card_last_numbers
  self.params[:TBK_FINAL_NUMERO_TARJETA]
end

#messageObject



74
75
76
# File 'lib/tbk/webpay/confirmation.rb', line 74

def message
  RESPONSE_CODES[self.params[:TBK_RESPUESTA]]
end

#order_idObject



42
43
44
# File 'lib/tbk/webpay/confirmation.rb', line 42

def order_id
  self.params[:TBK_ORDEN_COMPRA]
end


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/tbk/webpay/confirmation.rb', line 78

def paid_at
  @paid_at ||= begin
    year = Time.now.year
    month = self.params[:TBK_FECHA_TRANSACCION][0...2].to_i
    day = self.params[:TBK_FECHA_TRANSACCION][2...4].to_i
    hour = self.params[:TBK_HORA_TRANSACCION][0...2].to_i
    minutes = self.params[:TBK_HORA_TRANSACCION][2...4].to_i
    seconds = self.params[:TBK_HORA_TRANSACCION][4...6].to_i

    offset = if defined? TZInfo::Timezone
      # Use tzinfo gem if available
      TZInfo::Timezone.get('America/Santiago').period_for_utc(DateTime.new(year,month,day,hour,minutes,0)).utc_offset
    else
      -14400
    end

    Time.new(year, month, day, hour, minutes, seconds, offset)
  end
end

#rejectObject



34
35
36
# File 'lib/tbk/webpay/confirmation.rb', line 34

def reject
  self.commerce.webpay_encrypt('ERR')
end

#session_idObject



46
47
48
# File 'lib/tbk/webpay/confirmation.rb', line 46

def session_id
  self.params[:TBK_ID_SESION]
end

#signatureObject



62
63
64
# File 'lib/tbk/webpay/confirmation.rb', line 62

def signature
  self.params[:TBK_MAC]
end

#success?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tbk/webpay/confirmation.rb', line 38

def success?
  self.params[:TBK_RESPUESTA] == "0"
end

#transaction_idObject



50
51
52
# File 'lib/tbk/webpay/confirmation.rb', line 50

def transaction_id
  self.params[:TBK_ID_TRANSACCION]
end