Class: ActiveMerchant::Billing::Integrations::Webpay::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/webpay/notification.rb

Constant Summary collapse

SUCCESS_RESPONSE =
'ACEPTADO'
FAILURE_RESPONSE =
'RECHAZADO'
VALID_MAC_RESPONSE =
'CORRECTO'
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 Method Summary collapse

Constructor Details

#initialize(raw_post) ⇒ Notification

Returns a new instance of Notification.



25
26
27
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 25

def initialize(raw_post)
  super(CGI.unescape(raw_post))
end

Instance Method Details

#acknowledgeObject



125
126
127
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 125

def acknowledge
  @error ? FAILURE_RESPONSE : SUCCESS_RESPONSE
end

#amountObject

The money in float format



59
60
61
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 59

def amount
  params['TBK_MONTO'].to_f / 100
end

#authorizationObject



93
94
95
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 93

def authorization
  params['TBK_CODIGO_AUTORIZACION']
end

#card_numberObject



76
77
78
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 76

def card_number
  params['TBK_FINAL_NUMERO_TARJETA']
end

#complete?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 29

def complete?
  valid?
end

#fail!(message = nil) ⇒ Object



84
85
86
87
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 84

def fail!(message=nil)
  @error = true
  @message = message
end

#grossObject

the money amount we received in X.2 decimal.



54
55
56
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 54

def gross
  params['TBK_MONTO'][0..-3] + '.' + params['TBK_MONTO'][-2..-1]
end

#messageObject



97
98
99
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 97

def message
  @message || RESPONSE_CODES[params['TBK_RESPUESTA']]
end

#order_idObject



80
81
82
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 80

def order_id
  params['TBK_ORDEN_COMPRA']
end

#received_atObject

When was this payment received by the client.



38
39
40
41
42
43
44
45
46
47
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 38

def received_at
  Time.new(
    Time.now.year, 
    params['TBK_FECHA_TRANSACCION'][0..1].to_i, 
    params['TBK_FECHA_TRANSACCION'][2..3].to_i,
    params['TBK_HORA_TRANSACCION'][0..1].to_i,
    params['TBK_HORA_TRANSACCION'][2..3].to_i,
    params['TBK_HORA_TRANSACCION'][4..5].to_i
  )
end

#security_keyObject



49
50
51
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 49

def security_key
  params['TBK_MAC']
end

#session_idObject



72
73
74
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 72

def session_id
  params['TBK_ID_SESION']
end

#statusObject



68
69
70
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 68

def status
  params['TBK_RESPUESTA']
end

#success?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 89

def success?
  valid? && !@error
end

#test?Boolean

Was this a test transaction?

Returns:

  • (Boolean)


64
65
66
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 64

def test?
  params[''] == 'test'
end

#transaction_idObject



33
34
35
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 33

def transaction_id
  params['TBK_ID_TRANSACCION']
end

#valid?Boolean

Check the transaction’s validity. This method has to be called after a new apc arrives to verify it using your private key.

Example:

def notify
  notify = Webpay::Notification.new(request.raw_post)

  if notify.valid? 
    if check order & ammount
      # Process Order
    else
      notify.fail!
    end
  else
    ... log possible hacking attempt ...
  end

  render :text => notify.acknowledge
end

Returns:

  • (Boolean)


121
122
123
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 121

def valid? 
  valid_mac && params['TBK_RESPUESTA'] == '0'
end