Class: Lucid::Shopify::VerifyCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid/shopify/verify_callback.rb

Constant Summary collapse

Error =
Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#call(params) ⇒ Object

Verify that the callback request originated from Shopify.

Parameters:

  • params (Hash)

    the request params

Raises:

  • (Error)

    if signature is invalid



17
18
19
20
21
22
23
# File 'lib/lucid/shopify/verify_callback.rb', line 17

def call(params)
  params = params.to_h.transform_keys(&:to_s)
  digest = OpenSSL::Digest::SHA256.new
  digest = OpenSSL::HMAC.hexdigest(digest, Shopify.config.shared_secret, encoded_params(params))

  raise Error, 'invalid signature' unless digest == params['hmac']
end