Class: PagarMe::Postback

Inherits:
PagarMeObject show all
Defined in:
lib/pagarme/resources/postback.rb

Constant Summary

Constants inherited from PagarMeObject

PagarMe::PagarMeObject::RESOURCES

Instance Attribute Summary

Attributes inherited from PagarMeObject

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PagarMeObject

#==, #[]=, convert, #empty?, #initialize, #respond_to?, #to_hash, #to_s, #unsaved_attributes

Constructor Details

This class inherits a constructor from PagarMe::PagarMeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PagarMe::PagarMeObject

Class Method Details

.fingerprint_for(id) ⇒ Object

TODO: Remove deprecated Postback.fingerprint_for



31
32
33
34
# File 'lib/pagarme/resources/postback.rb', line 31

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

.signature(payload, hash_method = 'sha1') ⇒ Object



20
21
22
# File 'lib/pagarme/resources/postback.rb', line 20

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

.valid_request_signature?(payload, signature) ⇒ Boolean Also known as: validate_request_signature

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/pagarme/resources/postback.rb', line 13

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

.validate(id, fingerprint) ⇒ Object

TODO: Remove deprecated Postback.validate



25
26
27
28
# File 'lib/pagarme/resources/postback.rb', line 25

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

Instance Method Details

#redirect(url = 'http://localhost:3000/pagarme/postback') ⇒ Object



7
8
9
10
# File 'lib/pagarme/resources/postback.rb', line 7

def redirect(url = 'http://localhost:3000/pagarme/postback')
  uri = URI(url)
  Net::HTTP.new(uri.host, uri.port).post uri.path, payload, JSON.parse(headers)
end

#valid?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/pagarme/resources/postback.rb', line 3

def valid?
  self.class.valid_request_signature? payload, signature
end