Module: Tamara::Hmac

Defined in:
lib/tamara/hmac.rb

Constant Summary collapse

FILTERED_TRANSACTION_KEYS =
%w[amount_cents created_at currency error_occured has_parent_transaction id
integration_id is_3d_secure is_auth is_capture is_refunded is_standalone_payment
is_voided order.id owner pending
source_data.pansource_data.sub_type source_data.type success].freeze

Class Method Summary collapse

Class Method Details

.valid_signature?(tamara_response) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/tamara/hmac.rb', line 9

def valid_signature?(tamara_response)
  digest = ::OpenSSL::Digest.new("sha512")

  concatenated_str = FILTERED_TRANSACTION_KEYS.map do |element|
    tamara_response.dig("obj", *element.split("."))
  end.join
  secure_hash = ::OpenSSL::HMAC.hexdigest(digest, Tamara.hmac_key, concatenated_str)
  secure_hash == tamara_response["hmac"]
end