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
9
# File 'lib/puntopagos/notification.rb', line 4

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

Instance Method Details

#errorObject



31
32
33
# File 'lib/puntopagos/notification.rb', line 31

def error
  @verification.error
end

#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)


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

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)
  Rails.logger.info "Generated Message: #{message}"
  Rails.logger.info "Generated Signature #{signature}"
  @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