remit2 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/remit2/ipn_request.rb +24 -19
- metadata +2 -2
data/lib/remit2/ipn_request.rb
CHANGED
@@ -3,12 +3,30 @@ module Remit
|
|
3
3
|
#
|
4
4
|
# This should probably be updated to support the VerifySignature function now provided.
|
5
5
|
class IpnRequest
|
6
|
-
|
7
|
-
#
|
6
|
+
|
7
|
+
# Handy helper for frameworks (like Rails) that use Rack
|
8
|
+
# Just pass it the request object and it will infer the http parameters and URL endpoint
|
9
|
+
# +request+ should be the Rack request
|
10
|
+
# +remit_api+ should be a Remit::API object, initialized with your credentials
|
11
|
+
def self.from_rack_request(request, remit_api)
|
12
|
+
http_parameters = request.post? ? request.body.read : request.query_string
|
13
|
+
url_endpoint = "#{request.protocol}#{request.host_with_port}#{request.path}"
|
14
|
+
self.new(http_parameters, url_endpoint, remit_api)
|
15
|
+
end
|
16
|
+
|
17
|
+
# +http_parameters+ should be the HttpParameters string, as specified in the VerifySignature docs
|
18
|
+
# +url_endpoint+ should be the UrlEndPoint string, as specificed in the VerifySignature docs
|
8
19
|
# +remit_api+ should be a Remit::API object, initialized with your credentials
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
|
20
|
+
def initialize(http_parameters, url_endpoint, remit_api)
|
21
|
+
@http_parameters = http_parameters
|
22
|
+
|
23
|
+
# Build the params hash from the http_params
|
24
|
+
@params = {}
|
25
|
+
@http_parameters.split("&").each do |kv_pair|
|
26
|
+
k,v = kv_pair.split("=")
|
27
|
+
@params[k]=v
|
28
|
+
end
|
29
|
+
|
12
30
|
@url_endpoint = url_endpoint
|
13
31
|
@remit_api = remit_api
|
14
32
|
end
|
@@ -21,15 +39,10 @@ module Remit
|
|
21
39
|
def verify_signature
|
22
40
|
req = Remit::VerifySignature::Request.new(
|
23
41
|
:url_end_point => @url_endpoint,
|
24
|
-
:http_parameters => @
|
42
|
+
:http_parameters => @http_parameters
|
25
43
|
)
|
26
|
-
|
27
|
-
puts "=== REQ ==="
|
28
|
-
puts req.inspect
|
29
|
-
|
30
44
|
@remit_api.verify_signature(req)
|
31
45
|
end
|
32
|
-
|
33
46
|
|
34
47
|
def method_missing(method, *args) #:nodoc:
|
35
48
|
if @params.has_key?(method.to_s)
|
@@ -38,13 +51,5 @@ module Remit
|
|
38
51
|
super(method, *args)
|
39
52
|
end
|
40
53
|
end
|
41
|
-
|
42
|
-
def strip_keys_from(params, *ignore_keys)
|
43
|
-
parsed = params.dup
|
44
|
-
ignore_keys.each { |key| parsed.delete(key) }
|
45
|
-
parsed
|
46
|
-
end
|
47
|
-
private :strip_keys_from
|
48
|
-
|
49
54
|
end
|
50
55
|
end
|