lib/securetrading/site_security.rb in securetrading-0.3.2 vs lib/securetrading/site_security.rb in securetrading-0.4.0

- old
+ new

@@ -1,20 +1,26 @@ module Securetrading class SiteSecurity - def self.hash(fields) - Digest::SHA256.hexdigest(str_to_encode(fields)) + def self.hash(fields, config_options = nil) + Digest::SHA256.hexdigest(str_to_encode(fields, config_options)) end - def self.str_to_encode(fields) + def self.str_to_encode(fields, config_options = nil) + config = configuration(config_options) str = '' - fields.reverse_merge!(authmethod: Securetrading.config.auth_method) - [:currencyiso3a, :mainamount, :sitereference, :settlestatus, - :settleduedate, :authmethod, :paypaladdressoverride, - :strequiredfields, :version, :stprofile, :ruleidentifier, - :successfulurlredirect, :declinedurlredirect].each do |field| + fields.reverse_merge!(authmethod: config.auth_method) + %i(currencyiso3a mainamount sitereference settlestatus authmethod + settleduedate paypaladdressoverride strequiredfields version + stprofile ruleidentifier successfulurlredirect + declinedurlredirect).each do |field| str << fields[field].to_s end - str << Securetrading.config.site_security_password + str << config.site_security_password end - private_class_method :str_to_encode + + def self.configuration(config_options) + return Securetrading.config unless config_options.present? + Configuration.new(config_options) + end + private_class_method :str_to_encode, :configuration end end