Class: PuntoPagos::Verification

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

Overview

Public: This class manage the signing of a message using the secret and api-key defined in puntopagos.yml

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Verification

Returns a new instance of Verification.



6
7
8
9
10
11
12
# File 'lib/puntopagos/verification.rb', line 6

def initialize env = nil
  @env = env
  @@config ||= PuntoPagos::Config.new(env)
  @@function = "transaccion/traer"
  @@path = "transaccion"
  @response = {}
end

Instance Method Details

#errorObject



37
38
39
# File 'lib/puntopagos/verification.rb', line 37

def error
  @response
end

#valid?(response) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/puntopagos/verification.rb', line 33

def valid? response
  response["respuesta"] == "00"
end

#verify(token, trx_id, amount) ⇒ Object

Public: Signs a string using the secret and api-key defined in puntopagos.yml

string - The String to be signed Returns the signed String.



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

def verify token, trx_id, amount
  executioner = PuntoPagos::Executioner.new(@env)
  timestamp = get_timestamp
  message = create_message token, trx_id, amount, timestamp
  authorization = PuntoPagos::Authorization.new(@env)
  signature = authorization.sign(message)

  puts "SIGNATURE: #{signature} TIMESTAMP: #{timestamp} TOKEN: #{token} TRX: #{trx_id}"
  puts "MESSAGE: #{message}"

  @response = executioner.call_api(token, @@path, :get, signature, timestamp)

  valid?(@response)
end