Sha256: 8b167171db7015afaafef8b9dba7b4fc644d8a2c3a1c301f7b25b192e28180f5

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module PagarMe
  class Postback < PagarMeObject
    def valid?
      signature == self.class.signature(payload)
    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

1 entries across 1 versions & 1 rubygems

Version Path
pagarme-2.1.1 lib/pagarme/resources/postback.rb