Module: Bluepay::TamperProofSeal

Included in:
Base
Defined in:
lib/bluepay/tamper_proof_seal.rb

Instance Method Summary collapse

Instance Method Details

#hash(type, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bluepay/tamper_proof_seal.rb', line 11

def hash(type, *args)
  _args = args.insert(0, Bluepay.).map(&:to_s).join

  case type
  when HMAC_SHA512, nil
    OpenSSL::HMAC.hexdigest('sha512', Bluepay.secret_key, _args)
  when HMAC_SHA256
    OpenSSL::HMAC.hexdigest('sha256', Bluepay.secret_key, _args)
  when SHA512
    Digest::SHA512.hexdigest([
      Bluepay.secret_key,
      _args,
      type
    ].join)
  when SHA256
    then Digest::SHA256.hexdigest([
      Bluepay.secret_key,
      _args,
      type
    ].join)
  when MD5
    Digest::MD5.hexdigest([
      Bluepay.secret_key,
      _args,
      type
    ].join)
  else
    raise "Please set Bluepay.hash=."
  end
end

#tps(*keys) ⇒ Object



4
5
6
7
8
9
# File 'lib/bluepay/tamper_proof_seal.rb', line 4

def tps(*keys)
  type = self.params[:tps_hash_type]
  _params = self.converted_params
  args = keys.map {|k| _params[k] }
  { 'TAMPER_PROOF_SEAL' => hash(type, *args) }
end