class SolidusPaybright::SigningHelper
Constants
- SIGNATURE_PARAM_KEY
Public Class Methods
new(hmac_key)
click to toggle source
@param hmac_key [String] The HMAC secret key used for signing
# File lib/solidus_paybright/signing_helper.rb, line 8 def initialize(hmac_key) @hmac_key = hmac_key end
Public Instance Methods
params_signature(params)
click to toggle source
@param params [Hash] The parameters to be signed @return [String] The signature of the parameters
# File lib/solidus_paybright/signing_helper.rb, line 14 def params_signature(params) message = params.select do |key, _| key != SIGNATURE_PARAM_KEY && key.start_with?("x_") end.sort.join OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), @hmac_key, message) end
valid_params?(params)
click to toggle source
@param params [Hash] The parameters to be validated, including the “x_signature” key @return [Boolean] The validation result
# File lib/solidus_paybright/signing_helper.rb, line 24 def valid_params?(params) expected_signature = params[SIGNATURE_PARAM_KEY].to_s signature = params_signature(params) expected_signature.casecmp(signature.downcase).zero? end