Sha256: 2deee6f61c45de02150b5c70e30e3a8a7cf41787ed3377f5aee68da0e5cece5a

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module PagarMe
  class Postback < PagarMeObject
    def valid?
      self.class.valid_request_signature? payload, signature
    end

    class << self
      def valid_request_signature?(payload, signature)
        kind, raw_signature = signature.split '=', 2
        return false if kind.blank? || raw_signature.blank?
        signature(payload, kind) == raw_signature
      end
      alias :validate_request_signature :valid_request_signature?

      def signature(payload, hash_method = 'sha1')
        OpenSSL::HMAC.hexdigest hash_method, PagarMe.api_key, payload
      end

      # TODO: Remove deprecated Postback.validate
      def validate(id, fingerprint)
        $stderr.puts '[DEPRECATION WARNING] PagarMe.validate method is deprecated, use PagarMe.validate_request_signature instead'
        valid_request_signature? id, fingerprint
      end

      # TODO: Remove deprecated Postback.fingerprint_for
      def fingerprint_for(id)
        $stderr.puts '[DEPRECATION WARNING] PagarMe.fingerprint_for method is deprecated, use PagarMe.signature instead'
        signature id
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagarme-2.1.3 lib/pagarme/resources/postback.rb
pagarme-2.1.2 lib/pagarme/resources/postback.rb