remit 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,16 +11,18 @@ module Remit
11
11
  SIGNATURE_KEY = 'signature'
12
12
 
13
13
  # +params+ should be your controllers request parameters.
14
- def initialize(params, secret_key)
14
+ def initialize(params, uri, access_key, secret_key)
15
15
  raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
16
16
  @params = strip_keys_from(params, 'action', 'controller')
17
- @supplied_signature = @params.delete(SIGNATURE_KEY)
18
- @secret_key = secret_key
17
+ @uri = URI.parse(uri)
18
+ @url_end_point = @uri.scheme + '://' + @uri.host + @uri.path
19
+ @access_key = access_key
20
+ @secret_key = secret_key
19
21
  end
20
22
 
21
23
  def valid?
22
- return false unless @supplied_signature
23
- generate_signature_for(@params) == @supplied_signature
24
+ utils = Amazon::FPS::SignatureUtilsForOutbound.new(@access_key, @secret_key);
25
+ utils.validate_request(:parameters => @params, :url_end_point => @url_end_point, :http_method => "GET")
24
26
  end
25
27
 
26
28
  def method_missing(method, *args) #:nodoc:
@@ -31,14 +33,6 @@ module Remit
31
33
  end
32
34
  end
33
35
 
34
- def generate_signature_for(params)
35
- query = params.sort_by { |k,v| k.downcase }
36
- digest = OpenSSL::Digest::Digest.new('sha1')
37
- hmac = OpenSSL::HMAC.digest(digest, @secret_key, query.to_s)
38
- encoded = Base64.encode64(hmac).chomp
39
- end
40
- private :generate_signature_for
41
-
42
36
  def strip_keys_from(params, *ignore_keys)
43
37
  parsed = params.dup
44
38
  ignore_keys.each { |key| parsed.delete(key) }
@@ -1,7 +1,10 @@
1
1
  module Remit
2
2
  class PipelineResponse
3
- def initialize(uri, secret_key)
4
- @uri = URI.parse(uri)
3
+ def initialize(params, uri, access_key, secret_key)
4
+ @params = strip_keys_from(params, 'action', 'controller', 'id')
5
+ @uri = URI.parse(uri)
6
+ @url_end_point = @uri.scheme + '://' + @uri.host + @uri.path
7
+ @access_key = access_key
5
8
  @secret_key = secret_key
6
9
  end
7
10
 
@@ -12,8 +15,8 @@ module Remit
12
15
  # pulled from the request is filtered through the same method.
13
16
  #++
14
17
  def valid?
15
- return false unless given_signature
16
- Relax::Query.unescape_value(correct_signature) == given_signature
18
+ utils = Amazon::FPS::SignatureUtilsForOutbound.new(@access_key, @secret_key);
19
+ utils.validate_request(:parameters => @params, :url_end_point => @url_end_point, :http_method => "GET")
17
20
  end
18
21
 
19
22
  # Returns +true+ if the response returns a successful state.
@@ -39,14 +42,12 @@ module Remit
39
42
  end
40
43
  private :request_query
41
44
 
42
- def given_signature
43
- request_query[:awsSignature]
45
+ def strip_keys_from(params, *ignore_keys)
46
+ parsed = params.dup
47
+ ignore_keys.each { |key| parsed.delete(key) }
48
+ parsed
44
49
  end
45
- private :given_signature
50
+ private :strip_keys_from
46
51
 
47
- def correct_signature
48
- Remit::SignedQuery.new(@uri.path, @secret_key, request_query).sign
49
- end
50
- private :correct_signature
51
52
  end
52
53
  end
@@ -21,8 +21,8 @@ describe 'a GetAccountActivity call' do
21
21
  transaction.date_completed.should_not be_nil
22
22
  transaction.date_received.should_not be_nil
23
23
  transaction.error_code.should be_empty
24
- transaction.error_detail.should be_nil
25
- transaction.error_message.should be_nil
24
+ transaction.error_detail.should be_empty
25
+ transaction.error_message.should be_empty
26
26
  transaction.fees.should_not be_nil
27
27
  transaction.operation.should_not be_empty
28
28
  transaction.recipient_name.should_not be_empty
@@ -21,7 +21,6 @@ describe 'a GetTokens call' do
21
21
  token.caller_reference.should_not be_empty
22
22
  token.token_type.should_not be_empty
23
23
  token.old_token_id.should_not be_empty
24
- token.payment_reason.should_not be_empty
25
24
  end
26
25
 
27
26
  it 'should have a token with a token ID' do
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/integrations_helper'
2
+
3
+ describe 'an IPN request' do
4
+ before(:each) do
5
+ @request_params = {
6
+ "expiry" => "10/2013",
7
+ "tokenID" => "Q5IG5ETFCEBU8KBLTI4JHINQVL6VAJVHICBRR49AKLPIEZH1KB1S8C7VHAJJMLJ3",
8
+ "status" => "SC",
9
+ "callerReference" => "1253247023946cMcrTRrjtLjNrZGNKchWfDtUEIGuJfiOBAAJYPjbytBV",
10
+ "signatureMethod" => "RSA-SHA1",
11
+ "signatureVersion" => "2",
12
+ "certificateUrl" => "https://fps.amazonaws.com/certs/090909/PKICert.pem",
13
+ "controller" => "amazon_fps", # controller and action get deleted
14
+ "action" => "index",
15
+ "signature" => "H4NTAsp3YwAEiyQ86j5B53lksv2hwwEaEFxtdWFpy9xX764AZy/Dm0RLEykUUyPVLgqCOlMopay5" \
16
+ + "Qxr/VDwhdYAzgQzA8VCV8x9Mn0caKsJT2HCU6tSLNa6bLwzg/ildCm2lHDho1Xt2yaBHMt+/Cn4q" \
17
+ + "I5B+6PDrb8csuAWxW/mbUhk7AzazZMfQciJNjS5k+INlcvOOtQqoA/gVeBLsXK5jNsTh09cNa7pb" \
18
+ + "gAvey+0DEjYnIRX+beJV6EMCPZxnXDGo0fA1PENLWXIHtAoIJAfLYEkVbT2lva2tZ0KBBWENnSjf" \
19
+ + "26lMZVokypIo4huoGaZMp1IVkImFi3qC6ipCrw=="
20
+ }
21
+ @request = Remit::IpnRequest.new(@request_params, 'http://www.mysite.com/call_pay.jsp', ACCESS_KEY, SECRET_KEY)
22
+ end
23
+
24
+ it 'should be a valid request' do
25
+ @request.should be_valid
26
+ end
27
+
28
+ it 'should pass through access to given parameters' do
29
+ @request.status.should == 'SC'
30
+ @request.callerReference.should == '1253247023946cMcrTRrjtLjNrZGNKchWfDtUEIGuJfiOBAAJYPjbytBV'
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
5
11
  platform: ruby
6
12
  authors:
7
13
  - Tyler Hunt
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-01-11 00:00:00 -05:00
18
+ date: 2010-12-03 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: relax
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ~>
22
28
  - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 7
23
34
  version: 0.0.7
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description:
26
38
  email: tyler@tylerhunt.com
27
39
  executables: []
@@ -32,6 +44,9 @@ extra_rdoc_files:
32
44
  - LICENSE
33
45
  - README.markdown
34
46
  files:
47
+ - lib/amazon/fps/ca-bundle.crt
48
+ - lib/amazon/fps/signatureutils.rb
49
+ - lib/amazon/fps/signatureutilsforoutbound.rb
35
50
  - lib/remit.rb
36
51
  - lib/remit/common.rb
37
52
  - lib/remit/data_types.rb
@@ -69,6 +84,15 @@ files:
69
84
  - lib/remit/pipeline_response.rb
70
85
  - LICENSE
71
86
  - README.markdown
87
+ - spec/integrations/get_account_activity_spec.rb
88
+ - spec/integrations/get_tokens_spec.rb
89
+ - spec/integrations/ipn_request_spec.rb
90
+ - spec/units/get_pipeline_spec.rb
91
+ - spec/units/get_results_spec.rb
92
+ - spec/units/pay_spec.rb
93
+ - spec/integrations/integrations_helper.rb
94
+ - spec/spec_helper.rb
95
+ - spec/units/units_helper.rb
72
96
  has_rdoc: true
73
97
  homepage: http://github.com/tylerhunt/remit
74
98
  licenses: []
@@ -79,30 +103,36 @@ rdoc_options:
79
103
  require_paths:
80
104
  - lib
81
105
  required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
82
107
  requirements:
83
108
  - - ">="
84
109
  - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
85
113
  version: "0"
86
- version:
87
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
88
116
  requirements:
89
117
  - - ">="
90
118
  - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
91
122
  version: "0"
92
- version:
93
123
  requirements: []
94
124
 
95
125
  rubyforge_project: remit
96
- rubygems_version: 1.3.5
126
+ rubygems_version: 1.3.7
97
127
  signing_key:
98
128
  specification_version: 3
99
129
  summary: An API for using the Amazon Flexible Payment Service (FPS).
100
130
  test_files:
101
131
  - spec/integrations/get_account_activity_spec.rb
102
132
  - spec/integrations/get_tokens_spec.rb
133
+ - spec/integrations/ipn_request_spec.rb
103
134
  - spec/units/get_pipeline_spec.rb
104
135
  - spec/units/get_results_spec.rb
105
- - spec/units/ipn_request_spec.rb
106
136
  - spec/units/pay_spec.rb
107
137
  - spec/integrations/integrations_helper.rb
108
138
  - spec/spec_helper.rb
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/units_helper'
2
-
3
- describe 'an IPN request' do
4
- before(:each) do
5
- @request_params = {
6
- "action" => "notice",
7
- "buyerName" => "Fps Buyer",
8
- "callerReference" => "4-8-1-3.5",
9
- "controller" => "amazon_fps/ipn",
10
- "operation" => "PAY",
11
- "paymentMethod" => "CC",
12
- "recipientEmail" => "recipient@email.url",
13
- "recipientName" => "Fps Business",
14
- "signature" => "DA7ZbuQaBDt2/+Mty9XweJyqI1E=",
15
- "status" => "SUCCESS",
16
- "transactionAmount" => "USD 3.50",
17
- "transactionDate" => "1224687134",
18
- "transactionId" => "13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO"
19
- }
20
- @request = Remit::IpnRequest.new(@request_params, 'THISISMYTESTKEY')
21
- end
22
-
23
- it 'should be a valid request' do
24
- @request.should be_valid
25
- end
26
-
27
- it 'should pass through access to given parameters' do
28
- @request.status.should == 'SUCCESS'
29
- @request.operation.should == 'PAY'
30
- @request.transactionId.should == '13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO'
31
- end
32
- end