amazon_flex_pay 0.9.14 → 0.10.0
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/Rakefile +0 -1
- data/lib/amazon_flex_pay.rb +32 -11
- data/lib/amazon_flex_pay/api.rb +49 -22
- data/lib/amazon_flex_pay/api/base_request.rb +18 -40
- data/lib/amazon_flex_pay/pipelines.rb +17 -11
- data/lib/amazon_flex_pay/pipelines/base.rb +15 -12
- data/lib/amazon_flex_pay/signature.rb +24 -0
- data/lib/amazon_flex_pay/{signing.rb → util.rb} +4 -16
- data/test/amazon_flex_pay/api/base_request_test.rb +67 -0
- data/test/amazon_flex_pay/api_test.rb +418 -0
- data/test/{data_types_test.rb → amazon_flex_pay/data_types_test.rb} +3 -3
- data/test/amazon_flex_pay/pipelines/base_test.rb +35 -0
- data/test/amazon_flex_pay/pipelines_test.rb +55 -0
- data/test/amazon_flex_pay/signature_test.rb +11 -0
- data/test/amazon_flex_pay/util_test.rb +15 -0
- data/test/test_helper.rb +2 -4
- metadata +47 -20
- data/test/amazon_flex_pay_test.rb +0 -179
- data/test/api_test.rb +0 -303
- data/test/pipelines_test.rb +0 -48
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative '../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AmazonFlexPay::DataTypesTest < AmazonFlexPay::Test
|
4
4
|
include AmazonFlexPay::DataTypes
|
5
5
|
include ResponseSamples
|
6
6
|
|
@@ -27,4 +27,4 @@ class AmazonFlexPayTest < AmazonFlexPay::Test
|
|
27
27
|
|
28
28
|
assert_equal 'abc123', related.full.transaction_id
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPay::Pipelines::BaseTest < AmazonFlexPay::Test
|
4
|
+
|
5
|
+
class TestPipeline < AmazonFlexPay::Pipelines::Base
|
6
|
+
attribute :foo
|
7
|
+
end
|
8
|
+
|
9
|
+
should "hash pipelines" do
|
10
|
+
pipeline = TestPipeline.new(:foo => 'bar', :return_url => 'http://example.com/return')
|
11
|
+
hash = pipeline.to_hash
|
12
|
+
|
13
|
+
assert_equal 'TestPipeline', hash['pipelineName']
|
14
|
+
assert_equal '2009-01-09', hash['version']
|
15
|
+
assert_equal 'http://example.com/return', hash['returnURL']
|
16
|
+
end
|
17
|
+
|
18
|
+
should "parameterize signed pipelines" do
|
19
|
+
Time.stubs(:now).returns(Time.parse('Jan 1 2011')) # so the signature remains constant
|
20
|
+
|
21
|
+
pipeline = TestPipeline.new(:foo => 'bar', :return_url => 'http://example.com/return')
|
22
|
+
param = pipeline.to_param
|
23
|
+
|
24
|
+
{
|
25
|
+
'foo' => 'bar',
|
26
|
+
'callerKey' => 'foo',
|
27
|
+
'signatureVersion' => 2,
|
28
|
+
'signatureMethod' => 'HmacSHA256',
|
29
|
+
'signature' => 'OuUJQqFBJhezmcWOAhDGcsD%2F6OXpOLVlcbF3XMIZO3U%3D'
|
30
|
+
}.each do |key, value|
|
31
|
+
assert param.match(/#{key}=#{value}/), "#{param} should contain #{key}=#{value}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPay::PipelinesTest < AmazonFlexPay::Test
|
4
|
+
should "build a edit token pipeline" do
|
5
|
+
AmazonFlexPay.expects(:cbui).with do |pipeline|
|
6
|
+
assert pipeline.is_a? AmazonFlexPay::Pipelines::EditToken
|
7
|
+
assert_equal 'pipe1', pipeline.caller_reference
|
8
|
+
assert_equal 'token', pipeline.token_id
|
9
|
+
end
|
10
|
+
AmazonFlexPay.edit_token_pipeline('pipe1', 'http://example.com/return',
|
11
|
+
:token_id => 'token'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "build a multi use pipeline" do
|
16
|
+
AmazonFlexPay.expects(:cbui).with do |pipeline|
|
17
|
+
assert pipeline.is_a? AmazonFlexPay::Pipelines::MultiUse
|
18
|
+
assert_equal 'pipe2', pipeline.caller_reference
|
19
|
+
assert_equal '50.00', pipeline.global_amount_limit
|
20
|
+
assert_equal 'Count', pipeline.usage_limit_type1
|
21
|
+
assert_equal '2', pipeline.usage_limit_value1
|
22
|
+
end
|
23
|
+
AmazonFlexPay.multi_use_pipeline('pipe2', 'http://example.com/return',
|
24
|
+
:global_amount_limit => "50.00",
|
25
|
+
:usage_limit_type1 => 'Count',
|
26
|
+
:usage_limit_value1 => '2'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "build a recipient pipeline" do
|
31
|
+
AmazonFlexPay.expects(:cbui).with do |pipeline|
|
32
|
+
assert pipeline.is_a? AmazonFlexPay::Pipelines::Recipient
|
33
|
+
assert_equal 'pipe3', pipeline.caller_reference
|
34
|
+
assert_equal true, pipeline.recipient_pays_fee
|
35
|
+
end
|
36
|
+
AmazonFlexPay::recipient_pipeline('pipe3', 'http://example.com/return',
|
37
|
+
:recipient_pays_fee => true
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "build a single use pipeline" do
|
42
|
+
AmazonFlexPay.expects(:cbui).with do |pipeline|
|
43
|
+
assert pipeline.is_a? AmazonFlexPay::Pipelines::SingleUse
|
44
|
+
assert_equal 'pipe4', pipeline.caller_reference
|
45
|
+
assert_equal 'token', pipeline.recipient_token
|
46
|
+
assert_equal '25.00', pipeline.transaction_amount
|
47
|
+
assert_equal true, pipeline.disable_guest
|
48
|
+
end
|
49
|
+
AmazonFlexPay.single_use_pipeline('pipe4', 'http://example.com/return',
|
50
|
+
:recipient_token => 'token',
|
51
|
+
:transaction_amount => '25.00',
|
52
|
+
:disable_guest => true
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPay::SignatureTest < AmazonFlexPay::Test
|
4
|
+
should "generate a valid v2 signature" do
|
5
|
+
# NOTE: I'm not sure of a supplied signature example that I can copy, so
|
6
|
+
# I set this one up by making sure signatures were being accepted by
|
7
|
+
# Amazon and then generating and saving my own example. Kinda backwards
|
8
|
+
# but good enough for regression testing.
|
9
|
+
assert_equal "Ro7iH0M+1hIR/SXGvT1kmF6Tg5uUKRSUd1AWaJHOcpE=", AmazonFlexPay::Signature.new('bar', 'http://example.com/api', :hello => 'world').generate
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPay::UtilTest < AmazonFlexPay::Test
|
4
|
+
should "create a sorted query string" do
|
5
|
+
assert_equal "a=1&b=2&c=3&d=4&e=5", AmazonFlexPay.query_string(:a => 1, :b => 2, :c => 3, :d => 4, :e => 5)
|
6
|
+
end
|
7
|
+
|
8
|
+
should "flatten nested hashes into a query string using periods" do
|
9
|
+
assert_equal "a.a=1&a.b=2&b=3", AmazonFlexPay.query_string(:b => 3, :a => {:a => 1, :b => 2})
|
10
|
+
end
|
11
|
+
|
12
|
+
should "percent-encode spaces and other characters for a query string" do
|
13
|
+
assert_equal 'a=hello%20world%21', AmazonFlexPay.query_string(:a => 'hello world!')
|
14
|
+
end
|
15
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -5,11 +5,9 @@ gem 'rails', '3.2.5'
|
|
5
5
|
require 'mocha'
|
6
6
|
|
7
7
|
# load the gem
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift root
|
10
|
-
require root + '/amazon_flex_pay'
|
8
|
+
require_relative '../lib/amazon_flex_pay'
|
11
9
|
|
12
|
-
|
10
|
+
require_relative 'response_samples'
|
13
11
|
|
14
12
|
class AmazonFlexPay::Test < Test::Unit::TestCase
|
15
13
|
def default_test; end # quiet Test::Unit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon_flex_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.6.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.1
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: multi_xml
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.5.2
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.5.2
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: activesupport
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 3.0.14
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.14
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: mocha
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
description: A straight-forward REST API for Amazon's Flexible Payments Services.
|
59
79
|
email: lance@kickstarter.com
|
60
80
|
executables: []
|
@@ -88,15 +108,19 @@ files:
|
|
88
108
|
- lib/amazon_flex_pay/pipelines/recipient.rb
|
89
109
|
- lib/amazon_flex_pay/pipelines/single_use.rb
|
90
110
|
- lib/amazon_flex_pay/pipelines.rb
|
91
|
-
- lib/amazon_flex_pay/
|
111
|
+
- lib/amazon_flex_pay/signature.rb
|
112
|
+
- lib/amazon_flex_pay/util.rb
|
92
113
|
- lib/amazon_flex_pay.rb
|
93
114
|
- LICENSE
|
94
115
|
- README.rdoc
|
95
116
|
- Rakefile
|
96
|
-
- test/
|
97
|
-
- test/api_test.rb
|
98
|
-
- test/data_types_test.rb
|
99
|
-
- test/
|
117
|
+
- test/amazon_flex_pay/api/base_request_test.rb
|
118
|
+
- test/amazon_flex_pay/api_test.rb
|
119
|
+
- test/amazon_flex_pay/data_types_test.rb
|
120
|
+
- test/amazon_flex_pay/pipelines/base_test.rb
|
121
|
+
- test/amazon_flex_pay/pipelines_test.rb
|
122
|
+
- test/amazon_flex_pay/signature_test.rb
|
123
|
+
- test/amazon_flex_pay/util_test.rb
|
100
124
|
- test/response_samples.rb
|
101
125
|
- test/test_helper.rb
|
102
126
|
homepage: http://github.com/kickstarter/amazon_flex_pay
|
@@ -119,15 +143,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
143
|
version: '0'
|
120
144
|
requirements: []
|
121
145
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.8.
|
146
|
+
rubygems_version: 1.8.24
|
123
147
|
signing_key:
|
124
148
|
specification_version: 3
|
125
149
|
summary: API layer for Amazon FPS
|
126
150
|
test_files:
|
127
|
-
- test/
|
128
|
-
- test/api_test.rb
|
129
|
-
- test/data_types_test.rb
|
130
|
-
- test/
|
151
|
+
- test/amazon_flex_pay/api/base_request_test.rb
|
152
|
+
- test/amazon_flex_pay/api_test.rb
|
153
|
+
- test/amazon_flex_pay/data_types_test.rb
|
154
|
+
- test/amazon_flex_pay/pipelines/base_test.rb
|
155
|
+
- test/amazon_flex_pay/pipelines_test.rb
|
156
|
+
- test/amazon_flex_pay/signature_test.rb
|
157
|
+
- test/amazon_flex_pay/util_test.rb
|
131
158
|
- test/response_samples.rb
|
132
159
|
- test/test_helper.rb
|
133
160
|
has_rdoc:
|
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class AmazonFlexPayTest < AmazonFlexPay::Test
|
4
|
-
## signing
|
5
|
-
|
6
|
-
should "generate a valid v2 signature" do
|
7
|
-
# NOTE: I'm not sure of a supplied signature example that I can copy, so
|
8
|
-
# I set this one up by making sure signatures were being accepted by
|
9
|
-
# Amazon and then generating and saving my own example. Kinda backwards
|
10
|
-
# but good enough for regression testing.
|
11
|
-
assert_equal "Ro7iH0M+1hIR/SXGvT1kmF6Tg5uUKRSUd1AWaJHOcpE=", AmazonFlexPay.signature('http://example.com/api', {:hello => 'world'})
|
12
|
-
end
|
13
|
-
|
14
|
-
## query strings
|
15
|
-
|
16
|
-
should "create a sorted query string" do
|
17
|
-
assert_equal "a=1&b=2&c=3&d=4&e=5", AmazonFlexPay.query_string(:a => 1, :b => 2, :c => 3, :d => 4, :e => 5)
|
18
|
-
end
|
19
|
-
|
20
|
-
should "flatten nested hashes into a query string using periods" do
|
21
|
-
assert_equal "a.a=1&a.b=2&b=3", AmazonFlexPay.query_string(:b => 3, :a => {:a => 1, :b => 2})
|
22
|
-
end
|
23
|
-
|
24
|
-
should "percent-encode spaces and other characters for a query string" do
|
25
|
-
assert_equal 'a=hello%20world%21', AmazonFlexPay.query_string(:a => 'hello world!')
|
26
|
-
end
|
27
|
-
|
28
|
-
## verifying a request
|
29
|
-
|
30
|
-
should "verify a GET request" do
|
31
|
-
request = stub(:get? => true, :protocol => 'http://', :host_with_port => 'example.com', :path => '/foo/bar', :query_string => 'a=1&b=2')
|
32
|
-
AmazonFlexPay.expects(:verify_signature).with('http://example.com/foo/bar', 'a=1&b=2').returns(true)
|
33
|
-
assert AmazonFlexPay.verify_request(request)
|
34
|
-
end
|
35
|
-
|
36
|
-
should "verify a POST request" do
|
37
|
-
request = stub(:get? => false, :protocol => 'http://', :host_with_port => 'example.com', :path => '/foo/bar', :raw_post => 'a=1&b=2')
|
38
|
-
AmazonFlexPay.expects(:verify_signature).with('http://example.com/foo/bar', 'a=1&b=2').returns(true)
|
39
|
-
assert AmazonFlexPay.verify_request(request)
|
40
|
-
end
|
41
|
-
|
42
|
-
# api basics
|
43
|
-
|
44
|
-
class TestRequest < AmazonFlexPay::API::BaseRequest
|
45
|
-
attribute :foo
|
46
|
-
attribute :amount, :type => :amount
|
47
|
-
attribute :stuffs, :collection => :amount
|
48
|
-
attribute :method, :enumeration => :payment_method
|
49
|
-
|
50
|
-
class Response < AmazonFlexPay::API::BaseRequest::BaseResponse; end
|
51
|
-
end
|
52
|
-
|
53
|
-
should "respond with data structures even when models are empty" do
|
54
|
-
tr = TestRequest.new
|
55
|
-
assert tr.stuffs.is_a?(Array)
|
56
|
-
assert tr.amount.respond_to?(:value)
|
57
|
-
assert !tr.to_hash.has_key?('Stuffs')
|
58
|
-
assert !tr.to_hash.has_key?('Amount')
|
59
|
-
end
|
60
|
-
|
61
|
-
should "add necessary fields and sign api requests" do
|
62
|
-
Time.stubs(:now).returns(Time.parse('Jan 1 2011')) # so the signature remains constant
|
63
|
-
|
64
|
-
request = TestRequest.new(:foo => 'bar', :amount => {:value => '3.14', :currency_code => 'USD'})
|
65
|
-
params = request.to_params
|
66
|
-
|
67
|
-
# simple attributes
|
68
|
-
assert_equal 'bar', params['Foo']
|
69
|
-
|
70
|
-
# complex attributes
|
71
|
-
assert_equal '3.14', params['Amount']['Value']
|
72
|
-
assert_equal 'USD', params['Amount']['CurrencyCode']
|
73
|
-
|
74
|
-
# standard additions
|
75
|
-
assert_equal 'foo', params['AWSAccessKeyId']
|
76
|
-
assert_equal 'TestRequest', params['Action']
|
77
|
-
assert_equal '2011-09-20', params['Version']
|
78
|
-
|
79
|
-
# the signature is backwards-calculated for regression testing
|
80
|
-
assert_equal 'WVrkmK7qt/T+gtHWcdzqtkLRH8c06l/mPv3ZfxyvNyg=', params['Signature']
|
81
|
-
assert_equal 'HmacSHA256', params['SignatureMethod']
|
82
|
-
assert_equal 2, params['SignatureVersion']
|
83
|
-
end
|
84
|
-
|
85
|
-
should "store the request in the response" do
|
86
|
-
RestClient.expects(:get).returns(stub(:body => cancel_token_response, :code => 200))
|
87
|
-
response = TestRequest.new(:foo => 'bar').submit
|
88
|
-
assert_equal 'bar', response.request.foo
|
89
|
-
end
|
90
|
-
|
91
|
-
should "instrument successful responses" do
|
92
|
-
events = []
|
93
|
-
callback = proc{ |*args| events << ActiveSupport::Notifications::Event.new(*args) }
|
94
|
-
|
95
|
-
ActiveSupport::Notifications.subscribed(callback, "amazon_flex_pay.api") do
|
96
|
-
RestClient.expects(:get).returns(stub(:body => cancel_token_response, :code => 200))
|
97
|
-
TestRequest.new(:foo => 'bar').submit
|
98
|
-
end
|
99
|
-
|
100
|
-
assert_equal 1, events.size
|
101
|
-
assert_equal 'TestRequest', events.first.payload[:action]
|
102
|
-
assert_equal 200, events.first.payload[:code]
|
103
|
-
assert events.first.payload.has_key?(:request)
|
104
|
-
assert events.first.payload.has_key?(:response)
|
105
|
-
assert events.first.duration > 0.1, events.first.duration.to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
should "catch and parse errors" do
|
109
|
-
net_http_res = stub(:code => 400)
|
110
|
-
http_response = RestClient::Response.create(error_response, net_http_res, nil)
|
111
|
-
RestClient.expects(:get).raises(RestClient::BadRequest.new(http_response))
|
112
|
-
|
113
|
-
error = nil
|
114
|
-
begin
|
115
|
-
TestRequest.new(:foo => 'bar').submit
|
116
|
-
rescue AmazonFlexPay::API::InvalidParams => e
|
117
|
-
error = e
|
118
|
-
end
|
119
|
-
assert error.request_id
|
120
|
-
assert_equal 'InvalidParams', error.code
|
121
|
-
assert error.message.match(/has to be a valid/)
|
122
|
-
end
|
123
|
-
|
124
|
-
should "instrument error responses" do
|
125
|
-
events = []
|
126
|
-
callback = proc{ |*args| events << ActiveSupport::Notifications::Event.new(*args) }
|
127
|
-
|
128
|
-
ActiveSupport::Notifications.subscribed(callback, "amazon_flex_pay.api") do
|
129
|
-
net_http_res = stub(:code => 400)
|
130
|
-
http_response = RestClient::Response.create(error_response, net_http_res, nil)
|
131
|
-
RestClient.expects(:get).raises(RestClient::BadRequest.new(http_response))
|
132
|
-
|
133
|
-
TestRequest.new(:foo => 'bar').submit rescue AmazonFlexPay::API::Error
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_equal 1, events.size
|
137
|
-
assert_equal 'TestRequest', events.first.payload[:action]
|
138
|
-
assert_equal 400, events.first.payload[:code]
|
139
|
-
assert events.first.payload.has_key?(:request)
|
140
|
-
assert events.first.payload.has_key?(:response)
|
141
|
-
assert events.first.duration > 0.1, events.first.duration.to_s
|
142
|
-
end
|
143
|
-
|
144
|
-
should "not allow unknown values for enumerated attributes" do
|
145
|
-
assert_raises ArgumentError do TestRequest.new(:method => 'UNKOWN') end
|
146
|
-
end
|
147
|
-
|
148
|
-
should "allow value sets for enumerated attributes" do
|
149
|
-
assert_nothing_raised do
|
150
|
-
TestRequest.new(:method => ['CC', 'ACH'])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
should "convert value sets into comma-separated lists" do
|
155
|
-
assert_equal 'a,b', TestRequest.new(:foo => ['a', 'b']).to_hash['Foo']
|
156
|
-
end
|
157
|
-
|
158
|
-
# pipeline basics
|
159
|
-
|
160
|
-
class TestPipeline < AmazonFlexPay::Pipelines::Base
|
161
|
-
attribute :foo
|
162
|
-
end
|
163
|
-
|
164
|
-
should "add necessary fields and sign pipeline urls" do
|
165
|
-
Time.stubs(:now).returns(Time.parse('Jan 1 2011')) # so the signature remains constant
|
166
|
-
|
167
|
-
pipeline = TestPipeline.new(:foo => 'bar')
|
168
|
-
params = pipeline.to_params('http://example.com/return')
|
169
|
-
|
170
|
-
assert_equal 'TestPipeline', params['pipelineName']
|
171
|
-
assert_equal 'foo', params['callerKey']
|
172
|
-
assert_equal '2009-01-09', params['version']
|
173
|
-
assert_equal 'http://example.com/return', params['returnURL']
|
174
|
-
|
175
|
-
assert_equal 2, params['signatureVersion']
|
176
|
-
assert_equal 'HmacSHA256', params['signatureMethod']
|
177
|
-
assert_equal 'OuUJQqFBJhezmcWOAhDGcsD/6OXpOLVlcbF3XMIZO3U=', params['signature']
|
178
|
-
end
|
179
|
-
end
|