Class: Vpago::AcledaMobile::CallbackValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/vpago/acleda_mobile/callback_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CallbackValidator

{

"TransactionId": "REF0361472663",
"PaymentTokenId": "16de81d4-b5ef-ef59-16de-81d4b5efef59",
"TxnAmount": "30",
"SenderName": "Test User",
"SignedHash": "c5b9be690bde7dc8a0abebb1a45c0850359540a4977aecd4cdf13e15a2edfe79",
}


11
12
13
# File 'lib/vpago/acleda_mobile/callback_validator.rb', line 11

def initialize(options)
  @options = options
end

Instance Method Details

#callObject



15
16
17
# File 'lib/vpago/acleda_mobile/callback_validator.rb', line 15

def call
  valid?
end

#hmac_hashObject



29
30
31
32
33
34
35
# File 'lib/vpago/acleda_mobile/callback_validator.rb', line 29

def hmac_hash
  key = secret_key

  message = "#{@options[:TransactionId]} #{@options[:PaymentTokenId]} #{@options[:TxnAmount]}"

  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, message)
end

#secret_keyObject



19
20
21
# File 'lib/vpago/acleda_mobile/callback_validator.rb', line 19

def secret_key
  ENV.fetch('ACLEDA_MOBILE_SECRET_HASH_KEY', nil)
end

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/vpago/acleda_mobile/callback_validator.rb', line 23

def valid?
  return false if secret_key.blank?

  hmac_hash == @options[:SignedHash]
end