Module: DirectPostMac

Defined in:
lib/citypay_api_client/utils/direct_post_mac.rb

Class Method Summary collapse

Class Method Details

.create(licence_key, nonce, amount, identifier) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/citypay_api_client/utils/direct_post_mac.rb', line 11

def create(licence_key, nonce, amount, identifier)
  nonce_s = nonce.pack('c*').upcase

  value = []
  value.push(*nonce_s.bytes)
  value.push(*amount.bytes)
  value.push(*identifier.bytes)

  OpenSSL::HMAC.hexdigest('sha256', licence_key, value.pack("c*")).upcase
end

.validate(licence_key, nonce, amount, identifier, mac_to_validate) ⇒ Object



6
7
8
9
# File 'lib/citypay_api_client/utils/direct_post_mac.rb', line 6

def validate(licence_key, nonce, amount, identifier, mac_to_validate)
  mac = create(licence_key, nonce, amount, identifier)
  mac === mac_to_validate
end