Class: Remit::IpnRequest
- Inherits:
-
Object
- Object
- Remit::IpnRequest
- Defined in:
- lib/remit2/ipn_request.rb
Overview
Encapsulates the logic for IPN request validation and attribute retrieval.
This should probably be updated to support the VerifySignature function now provided.
Class Method Summary collapse
-
.from_rack_request(request, remit_api) ⇒ Object
Handy helper for frameworks (like Rails) that use Rack Just pass it the request object and it will infer the http parameters and URL endpoint
request
should be the Rack requestremit_api
should be a Remit::API object, initialized with your credentials.
Instance Method Summary collapse
-
#initialize(http_parameters, url_endpoint, remit_api) ⇒ IpnRequest
constructor
http_parameters
should be the HttpParameters string, as specified in the VerifySignature docsurl_endpoint
should be the UrlEndPoint string, as specificed in the VerifySignature docsremit_api
should be a Remit::API object, initialized with your credentials. -
#method_missing(method, *args) ⇒ Object
:nodoc:.
- #valid? ⇒ Boolean
- #verify_signature ⇒ Object
Constructor Details
#initialize(http_parameters, url_endpoint, remit_api) ⇒ IpnRequest
http_parameters
should be the HttpParameters string, as specified in the VerifySignature docs url_endpoint
should be the UrlEndPoint string, as specificed in the VerifySignature docs remit_api
should be a Remit::API object, initialized with your credentials
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/remit2/ipn_request.rb', line 20 def initialize(http_parameters, url_endpoint, remit_api) @http_parameters = http_parameters # Build the params hash from the http_params @params = {} @http_parameters.split("&").each do |kv_pair| k,v = kv_pair.split("=") @params[k]=v end @url_endpoint = url_endpoint @remit_api = remit_api end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
:nodoc:
47 48 49 50 51 52 53 |
# File 'lib/remit2/ipn_request.rb', line 47 def method_missing(method, *args) #:nodoc: if @params.has_key?(method.to_s) @params[method.to_s] else super(method, *args) end end |
Class Method Details
.from_rack_request(request, remit_api) ⇒ Object
Handy helper for frameworks (like Rails) that use Rack Just pass it the request object and it will infer the http parameters and URL endpoint request
should be the Rack request remit_api
should be a Remit::API object, initialized with your credentials
11 12 13 14 15 |
# File 'lib/remit2/ipn_request.rb', line 11 def self.from_rack_request(request, remit_api) http_parameters = request.post? ? request.body.read : request.query_string url_endpoint = "#{request.protocol}#{request.host_with_port}#{request.path}" self.new(http_parameters, url_endpoint, remit_api) end |
Instance Method Details
#valid? ⇒ Boolean
34 35 36 37 |
# File 'lib/remit2/ipn_request.rb', line 34 def valid? resp = verify_signature resp.successful? && resp.verification_status == "Success" end |
#verify_signature ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/remit2/ipn_request.rb', line 39 def verify_signature req = Remit::VerifySignature::Request.new( :url_end_point => @url_endpoint, :http_parameters => @http_parameters ) @remit_api.verify_signature(req) end |