remit2 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,6 +46,7 @@ require 'remit2/operations/reserve'
46
46
  require 'remit2/operations/retry_transaction'
47
47
  require 'remit2/operations/settle'
48
48
  require 'remit2/operations/settle_debt'
49
+ require 'remit2/operations/verify_signature'
49
50
  require 'remit2/operations/write_off_debt'
50
51
 
51
52
  module Remit
@@ -78,6 +79,7 @@ module Remit
78
79
  include RetryTransaction
79
80
  include Settle
80
81
  include SettleDebt
82
+ include VerifySignature
81
83
  include WriteOffDebt
82
84
 
83
85
  API_ENDPOINT = 'https://fps.amazonaws.com/'
@@ -3,21 +3,33 @@ module Remit
3
3
  #
4
4
  # This should probably be updated to support the VerifySignature function now provided.
5
5
  class IpnRequest
6
- # Signature key name used by AmazonFPS IPNs
7
- SIGNATURE_KEY = 'signature'
8
-
9
6
  # +params+ should be your controllers request parameters.
10
- def initialize(params, secret_key)
7
+ # +url_endpoint+ should be the URL where you received the IPN
8
+ # +remit_api+ should be a Remit::API object, initialized with your credentials
9
+ def initialize(params, url_endpoint, remit_api)
11
10
  raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
12
11
  @params = strip_keys_from(params, 'action', 'controller')
13
- @supplied_signature = @params.delete(SIGNATURE_KEY)
14
- @secret_key = secret_key
12
+ @url_endpoint = url_endpoint
13
+ @remit_api = remit_api
15
14
  end
16
-
15
+
17
16
  def valid?
18
- return false unless @supplied_signature
19
- generate_signature_for(@params) == @supplied_signature
17
+ resp = verify_signature
18
+ resp.successful? && resp.verification_status == "Success"
19
+ end
20
+
21
+ def verify_signature
22
+ req = Remit::VerifySignature::Request.new(
23
+ :url_end_point => @url_endpoint,
24
+ :http_parameters => @params.collect {|k,v| "#{k}=#{v}"}.join("&")
25
+ )
26
+
27
+ puts "=== REQ ==="
28
+ puts req.inspect
29
+
30
+ @remit_api.verify_signature(req)
20
31
  end
32
+
21
33
 
22
34
  def method_missing(method, *args) #:nodoc:
23
35
  if @params.has_key?(method.to_s)
@@ -26,20 +38,13 @@ module Remit
26
38
  super(method, *args)
27
39
  end
28
40
  end
29
-
30
- def generate_signature_for(params)
31
- query = params.sort_by { |k,v| k.downcase }
32
- digest = OpenSSL::Digest::Digest.new('sha1')
33
- hmac = OpenSSL::HMAC.digest(digest, @secret_key, query.to_s)
34
- encoded = Base64.encode64(hmac).chomp
35
- end
36
- private :generate_signature_for
37
-
41
+
38
42
  def strip_keys_from(params, *ignore_keys)
39
43
  parsed = params.dup
40
44
  ignore_keys.each { |key| parsed.delete(key) }
41
45
  parsed
42
46
  end
43
47
  private :strip_keys_from
48
+
44
49
  end
45
50
  end
@@ -0,0 +1,23 @@
1
+ # Updated for API Version 2008-09-17
2
+ module Remit
3
+ module VerifySignature
4
+ class Request < Remit::Request
5
+ action :VerifySignature
6
+ parameter :url_end_point, :required => true
7
+ parameter :http_parameters, :require => true
8
+ end
9
+
10
+ class InnerResponse < Remit::BaseResponse
11
+ parameter :verification_status
12
+ end
13
+
14
+ class Response < Remit::Response
15
+ parameter :inner, :element => "VerifySignatureResult", :type => InnerResponse
16
+ inner_parameters :verification_status
17
+ end
18
+
19
+ def verify_signature(request = Request.new)
20
+ call(request, Response)
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Micah Wedemeyer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-06 00:00:00 -04:00
18
+ date: 2011-01-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,7 @@ files:
72
72
  - lib/remit2/operations/retry_transaction.rb
73
73
  - lib/remit2/operations/settle.rb
74
74
  - lib/remit2/operations/settle_debt.rb
75
+ - lib/remit2/operations/verify_signature.rb
75
76
  - lib/remit2/operations/write_off_debt.rb
76
77
  - lib/remit2/pipeline_response.rb
77
78
  - lib/remit2/request.rb