module AdyenHppHmacCalculator::MerchantStringGenerator

Public Class Methods

generate(params) click to toggle source

Generates concatenated key/value paris

@param params [Hash] key/value pairs to generate the signing string @return [String] concatenated key/value pairs

# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 6
def self.generate params
  pairs = create_pairs params
  remove_unnecessary_keys pairs
  sort_key_value_pairs_by_key pairs
  delimit_pairs pairs
  concatenate_pairs pairs
end

Private Class Methods

concatenate_pairs(pairs) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 44
def self.concatenate_pairs pairs
  keys = pairs.collect(&:first)
  values = pairs.collect(&:last)
  (keys + values).join(':')
end
create_pairs(params) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 16
def self.create_pairs params
  params.map{ |key, value| [key.to_s.dup, value.to_s.dup] }
end
delimit_pairs(pairs) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 32
def self.delimit_pairs pairs
  pairs.each do |key, value|
    escape! key
    escape! value
  end
end
escape!(string) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 39
def self.escape! string
  string.gsub!('\\'){ '\\\\' }
  string.gsub!(':'){ '\:' }
end
ignored_key?(key) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 24
def self.ignored_key? key
  key == 'sig' or key == 'merchantSig' or key.start_with? 'ignore.' 
end
remove_unnecessary_keys(pairs) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 20
def self.remove_unnecessary_keys pairs
  pairs.reject! { |key, _| ignored_key? key }
end
sort_key_value_pairs_by_key(pairs) click to toggle source
# File lib/adyen_hpp_hmac_calculator/merchant_string_generator.rb, line 28
def self.sort_key_value_pairs_by_key pairs
  pairs.sort_by!{ |key, _| key }
end