Class: ActiveMerchant::Billing::Integrations::Webpay::Notification
- Inherits:
-
Notification
- Object
- Notification
- ActiveMerchant::Billing::Integrations::Webpay::Notification
- 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
- #acknowledge ⇒ Object
-
#amount ⇒ Object
The money in float format.
- #authorization ⇒ Object
- #card_number ⇒ Object
- #complete? ⇒ Boolean
- #fail!(message = nil) ⇒ Object
-
#gross ⇒ Object
the money amount we received in X.2 decimal.
-
#initialize(raw_post) ⇒ Notification
constructor
A new instance of Notification.
- #message ⇒ Object
- #order_id ⇒ Object
-
#received_at ⇒ Object
When was this payment received by the client.
- #security_key ⇒ Object
- #session_id ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
-
#test? ⇒ Boolean
Was this a test transaction?.
- #transaction_id ⇒ Object
-
#valid? ⇒ Boolean
Check the transaction’s validity.
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
#acknowledge ⇒ Object
125 126 127 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 125 def acknowledge @error ? FAILURE_RESPONSE : SUCCESS_RESPONSE end |
#amount ⇒ Object
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 |
#authorization ⇒ Object
93 94 95 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 93 def params['TBK_CODIGO_AUTORIZACION'] end |
#card_number ⇒ Object
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
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!(=nil) @error = true @message = end |
#gross ⇒ Object
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 |
#message ⇒ Object
97 98 99 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 97 def @message || RESPONSE_CODES[params['TBK_RESPUESTA']] end |
#order_id ⇒ Object
80 81 82 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 80 def order_id params['TBK_ORDEN_COMPRA'] end |
#received_at ⇒ Object
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_key ⇒ Object
49 50 51 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 49 def security_key params['TBK_MAC'] end |
#session_id ⇒ Object
72 73 74 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 72 def session_id params['TBK_ID_SESION'] end |
#status ⇒ Object
68 69 70 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 68 def status params['TBK_RESPUESTA'] end |
#success? ⇒ 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?
64 65 66 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 64 def test? params[''] == 'test' end |
#transaction_id ⇒ Object
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
121 122 123 |
# File 'lib/active_merchant/billing/integrations/webpay/notification.rb', line 121 def valid? valid_mac && params['TBK_RESPUESTA'] == '0' end |