Class: FoxycartHelpers::ProductVerification

Inherits:
Object
  • Object
show all
Defined in:
lib/foxycart_helpers/product_verification.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name, value) ⇒ ProductVerification

Returns a new instance of ProductVerification.



30
31
32
33
34
# File 'lib/foxycart_helpers/product_verification.rb', line 30

def initialize(code, name, value)
  @code = code
  @name = name
  @value = value
end

Class Method Details

.encode(*args) ⇒ Object



6
7
8
# File 'lib/foxycart_helpers/product_verification.rb', line 6

def self.encode(*args)
  new(*args).encode
end

.encoded_name(*args) ⇒ Object



10
11
12
# File 'lib/foxycart_helpers/product_verification.rb', line 10

def self.encoded_name(*args)
  new(*args).encoded_name
end

Instance Method Details

#configObject



26
27
28
# File 'lib/foxycart_helpers/product_verification.rb', line 26

def config
  FoxycartHelpers.configuration
end

#encodeObject



14
15
16
17
18
19
20
# File 'lib/foxycart_helpers/product_verification.rb', line 14

def encode
  digest = OpenSSL::Digest.new 'sha256'
  key = config.api_key
  data = @code + @name + @value

  OpenSSL::HMAC.hexdigest digest, key, data
end

#encoded_nameObject



22
23
24
# File 'lib/foxycart_helpers/product_verification.rb', line 22

def encoded_name
  @value + '||' + encode
end