Class: PuntoPagos::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/puntopagos/notification.rb

Overview

Public: Manages the notification process.

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Notification

Returns a new instance of Notification.



4
5
6
7
8
# File 'lib/puntopagos/notification.rb', line 4

def initialize env = nil
  @env = env
  @@config ||= PuntoPagos::Config.new(@env)
  @@function = "transaccion/notificacion"
end

Instance Method Details

#valid?(headers, params) ⇒ Boolean

Public: Validates the message sent by PuntoPagos in the notification process.

headers - The headers of the request as a Hash. params - The params Hash.

Returns true or false.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
# File 'lib/puntopagos/notification.rb', line 17

def valid? headers, params
  timestamp = get_timestamp headers

  message = create_message params["token"], params["trx_id"], params["monto"].to_s, timestamp
  authorization = Authorization.new(@env)
  signature = authorization.sign(message)
  verification = PuntoPagos::Verification.new(@env)
  (signature == pp_signature(headers)) and (verification.verify(params["token"], params["trx_id"], params["monto"].to_i.to_s + ".00"))

end