Module: PaymobRuby::Hmac

Defined in:
lib/paymob_ruby/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?(paymob_response) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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