Class: SermepaWebTpv::Signature

Inherits:
Object
  • Object
show all
Includes:
Persistence::ActiveRecord
Defined in:
lib/sermepa_web_tpv/signature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistence::ActiveRecord

#generate_transaction_number!, #transaction_amount, #transaction_number

Constructor Details

#initialize(action) ⇒ Signature

Returns a new instance of Signature.



30
31
32
# File 'lib/sermepa_web_tpv/signature.rb', line 30

def initialize(action)
  @action = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/sermepa_web_tpv/signature.rb', line 9

def action
  @action
end

Class Method Details

.cipherObject



21
22
23
# File 'lib/sermepa_web_tpv/signature.rb', line 21

def cipher
  Mcrypt.new(:tripledes, :cbc, merchant_key, iv, :zeros)
end

.digestorObject



25
26
27
# File 'lib/sermepa_web_tpv/signature.rb', line 25

def digestor
  @digestor ||= OpenSSL::Digest.new('sha256')
end

.ivObject



12
13
14
15
# File 'lib/sermepa_web_tpv/signature.rb', line 12

def iv
  # "\x00\x00\x00\x00\x00\x00\x00\x00"
  0.chr * 8
end

.merchant_keyObject



17
18
19
# File 'lib/sermepa_web_tpv/signature.rb', line 17

def merchant_key
  Base64.decode64(SermepaWebTpv.merchant_secret_key)
end

Instance Method Details

#keyObject



41
42
43
# File 'lib/sermepa_web_tpv/signature.rb', line 41

def key
  self.class.cipher.encrypt(action.transaction_number)
end

#signatureObject



34
35
36
37
38
39
# File 'lib/sermepa_web_tpv/signature.rb', line 34

def signature
  Base64.encode64(
    OpenSSL::HMAC.digest(self.class.digestor, key,
                         action.merchant_parameters))
    .strip
end