amazon_flex_pay 0.9.2
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/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +23 -0
- data/lib/amazon_flex_pay/api/base.rb +86 -0
- data/lib/amazon_flex_pay/api/cancel.rb +11 -0
- data/lib/amazon_flex_pay/api/cancel_token.rb +9 -0
- data/lib/amazon_flex_pay/api/get_account_activity.rb +21 -0
- data/lib/amazon_flex_pay/api/get_account_balance.rb +8 -0
- data/lib/amazon_flex_pay/api/get_recipient_verification_status.rb +9 -0
- data/lib/amazon_flex_pay/api/get_token_by_caller.rb +10 -0
- data/lib/amazon_flex_pay/api/get_token_usage.rb +9 -0
- data/lib/amazon_flex_pay/api/get_tokens.rb +13 -0
- data/lib/amazon_flex_pay/api/get_transaction.rb +9 -0
- data/lib/amazon_flex_pay/api/get_transaction_status.rb +13 -0
- data/lib/amazon_flex_pay/api/pay.rb +20 -0
- data/lib/amazon_flex_pay/api/refund.rb +14 -0
- data/lib/amazon_flex_pay/api/reserve.rb +20 -0
- data/lib/amazon_flex_pay/api/settle.rb +11 -0
- data/lib/amazon_flex_pay/api/verify_signature.rb +14 -0
- data/lib/amazon_flex_pay/api.rb +162 -0
- data/lib/amazon_flex_pay/data_types.rb +138 -0
- data/lib/amazon_flex_pay/enumerations.rb +23 -0
- data/lib/amazon_flex_pay/model.rb +130 -0
- data/lib/amazon_flex_pay/pipelines/base.rb +40 -0
- data/lib/amazon_flex_pay/pipelines/edit_token.rb +6 -0
- data/lib/amazon_flex_pay/pipelines/multi_use.rb +28 -0
- data/lib/amazon_flex_pay/pipelines/recipient.rb +10 -0
- data/lib/amazon_flex_pay/pipelines/single_use.rb +24 -0
- data/lib/amazon_flex_pay/pipelines.rb +41 -0
- data/lib/amazon_flex_pay/signing.rb +42 -0
- data/lib/amazon_flex_pay.rb +53 -0
- data/test/amazon_flex_pay_test.rb +117 -0
- data/test/api_test.rb +310 -0
- data/test/pipelines_test.rb +46 -0
- data/test/response_samples.rb +588 -0
- data/test/test_helper.rb +22 -0
- metadata +167 -0
data/test/api_test.rb
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPayTest < AmazonFlexPay::Test
|
4
|
+
include ResponseSamples
|
5
|
+
|
6
|
+
## Cancel
|
7
|
+
|
8
|
+
should "construct a Cancel request" do
|
9
|
+
AmazonFlexPay::API::Cancel.any_instance.expects(:submit)
|
10
|
+
assert_nothing_raised do
|
11
|
+
AmazonFlexPay.cancel('txid', {:description => 'test'})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
should "parse a Cancel response" do
|
16
|
+
response = nil
|
17
|
+
assert_nothing_raised do
|
18
|
+
response = AmazonFlexPay::API::Cancel::Response.from_xml(cancel_response)
|
19
|
+
end
|
20
|
+
assert !response.error?
|
21
|
+
assert response.request_id
|
22
|
+
assert response.transaction_id
|
23
|
+
assert response.transaction_status
|
24
|
+
end
|
25
|
+
|
26
|
+
## CancelToken
|
27
|
+
|
28
|
+
should "construct a CancelToken request" do
|
29
|
+
AmazonFlexPay::API::CancelToken.any_instance.expects(:submit)
|
30
|
+
assert_nothing_raised do
|
31
|
+
AmazonFlexPay.cancel_token('token', {:reason_text => 'test'})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
should "parse a CancelToken response" do
|
36
|
+
response = nil
|
37
|
+
assert_nothing_raised do
|
38
|
+
response = AmazonFlexPay::API::CancelToken::Response.from_xml(cancel_token_response)
|
39
|
+
end
|
40
|
+
assert !response.error?
|
41
|
+
assert response.request_id
|
42
|
+
end
|
43
|
+
|
44
|
+
## GetAccountActivity
|
45
|
+
|
46
|
+
should "construct a GetAccountActivity request" do
|
47
|
+
AmazonFlexPay::API::GetAccountActivity.any_instance.expects(:submit)
|
48
|
+
since = Time.now - 60*60*24 # 1.day
|
49
|
+
to = Time.now
|
50
|
+
assert_nothing_raised do
|
51
|
+
AmazonFlexPay.get_account_activity(since, to)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
should "parse a GetAccountActivity response" do
|
56
|
+
response = nil
|
57
|
+
assert_nothing_raised do
|
58
|
+
response = AmazonFlexPay::API::GetAccountActivity::Response.from_xml(get_account_activity_response)
|
59
|
+
end
|
60
|
+
assert !response.error?
|
61
|
+
assert response.request_id
|
62
|
+
assert_equal 5, response.transactions.count
|
63
|
+
end
|
64
|
+
|
65
|
+
## GetAccountBalance
|
66
|
+
|
67
|
+
should "construct a GetAccountBalance request" do
|
68
|
+
AmazonFlexPay::API::GetAccountBalance.any_instance.expects(:submit)
|
69
|
+
assert_nothing_raised do
|
70
|
+
AmazonFlexPay.get_account_balance
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
should "parse a GetAccountBalance response" do
|
75
|
+
response = nil
|
76
|
+
assert_nothing_raised do
|
77
|
+
response = AmazonFlexPay::API::GetAccountBalance::Response.from_xml(get_account_balance_response)
|
78
|
+
end
|
79
|
+
assert !response.error?
|
80
|
+
assert response.request_id
|
81
|
+
assert_equal '7.400000', response.account_balance.total_balance.value
|
82
|
+
end
|
83
|
+
|
84
|
+
## GetRecipientVerificationStatus
|
85
|
+
|
86
|
+
should "construct a GetRecipientVerificationStatus request" do
|
87
|
+
AmazonFlexPay::API::GetRecipientVerificationStatus.any_instance.expects(:submit)
|
88
|
+
assert_nothing_raised do
|
89
|
+
AmazonFlexPay.get_recipient_verification_status('token')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
should "parse a GetRecipientVerificationStatus response" do
|
94
|
+
response = nil
|
95
|
+
assert_nothing_raised do
|
96
|
+
response = AmazonFlexPay::API::GetRecipientVerificationStatus::Response.from_xml(get_recipient_verification_status_response)
|
97
|
+
end
|
98
|
+
assert !response.error?
|
99
|
+
assert response.request_id
|
100
|
+
assert response.recipient_verification_status
|
101
|
+
end
|
102
|
+
|
103
|
+
## GetTokenByCaller
|
104
|
+
|
105
|
+
should "construct a GetTokenByCaller request by reference" do
|
106
|
+
AmazonFlexPay::API::GetTokenByCaller.any_instance.expects(:submit)
|
107
|
+
assert_nothing_raised do
|
108
|
+
AmazonFlexPay.get_token_by_caller_reference('reference')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
should "construct a GetTokenByCaller request by token id" do
|
113
|
+
AmazonFlexPay::API::GetTokenByCaller.any_instance.expects(:submit)
|
114
|
+
assert_nothing_raised do
|
115
|
+
AmazonFlexPay.get_token_by_id('token')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
should "parse a GetTokenByCaller response" do
|
120
|
+
response = nil
|
121
|
+
assert_nothing_raised do
|
122
|
+
response = AmazonFlexPay::API::GetTokenByCaller::Response.from_xml(get_token_by_caller_response)
|
123
|
+
end
|
124
|
+
assert !response.error?
|
125
|
+
assert response.request_id
|
126
|
+
assert response.token.token_id
|
127
|
+
assert response.token.token_status
|
128
|
+
end
|
129
|
+
|
130
|
+
## GetTokenUsage
|
131
|
+
|
132
|
+
should "construct a GetTokenUsage request" do
|
133
|
+
AmazonFlexPay::API::GetTokenUsage.any_instance.expects(:submit)
|
134
|
+
assert_nothing_raised do
|
135
|
+
AmazonFlexPay.get_token_usage('token')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
should "parse a GetTokenUsage response" do
|
140
|
+
response = nil
|
141
|
+
assert_nothing_raised do
|
142
|
+
response = AmazonFlexPay::API::GetTokenUsage::Response.from_xml(get_token_usage_response)
|
143
|
+
end
|
144
|
+
assert 2, response.token_usage_limits.count
|
145
|
+
assert_equal '10.000000', response.token_usage_limits.first.amount.value
|
146
|
+
assert_equal '1', response.token_usage_limits.last.count
|
147
|
+
end
|
148
|
+
|
149
|
+
## GetTokens
|
150
|
+
|
151
|
+
should "construct a GetTokens request" do
|
152
|
+
AmazonFlexPay::API::GetTokens.any_instance.expects(:submit)
|
153
|
+
assert_nothing_raised do
|
154
|
+
AmazonFlexPay.get_tokens
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
should "parse a GetTokens response" do
|
159
|
+
response = nil
|
160
|
+
assert_nothing_raised do
|
161
|
+
response = AmazonFlexPay::API::GetTokens::Response.from_xml(get_tokens_response)
|
162
|
+
end
|
163
|
+
assert 1, response.tokens.count
|
164
|
+
end
|
165
|
+
|
166
|
+
## GetTransaction
|
167
|
+
|
168
|
+
should "construct a GetTransaction request" do
|
169
|
+
AmazonFlexPay::API::GetTransaction.any_instance.expects(:submit)
|
170
|
+
assert_nothing_raised do
|
171
|
+
AmazonFlexPay.get_transaction('txid')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
should "parse a GetTransaction response" do
|
176
|
+
response = nil
|
177
|
+
assert_nothing_raised do
|
178
|
+
response = AmazonFlexPay::API::GetTransaction::Response.from_xml(get_transaction_response)
|
179
|
+
end
|
180
|
+
assert !response.error?
|
181
|
+
assert response.request_id
|
182
|
+
assert response.transaction.caller_reference
|
183
|
+
assert response.transaction.payment_method
|
184
|
+
end
|
185
|
+
|
186
|
+
## GetTransactionStatus
|
187
|
+
|
188
|
+
should "construct a GetTransactionStatus request" do
|
189
|
+
AmazonFlexPay::API::GetTransactionStatus.any_instance.expects(:submit)
|
190
|
+
assert_nothing_raised do
|
191
|
+
AmazonFlexPay.get_transaction_status('txid')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
should "parse a GetTransactionStatus response" do
|
196
|
+
response = nil
|
197
|
+
assert_nothing_raised do
|
198
|
+
response = AmazonFlexPay::API::GetTransactionStatus::Response.from_xml(get_transaction_status_response)
|
199
|
+
end
|
200
|
+
assert !response.error?
|
201
|
+
assert response.request_id
|
202
|
+
assert response.transaction_id
|
203
|
+
assert_equal 'Success', response.transaction_status
|
204
|
+
end
|
205
|
+
|
206
|
+
## Pay
|
207
|
+
|
208
|
+
should "construct a Pay request" do
|
209
|
+
request = nil
|
210
|
+
assert_nothing_raised do
|
211
|
+
request = AmazonFlexPay::API::Pay.new(:transaction_amount => {:currency_code => 'USD', :value => '1.00'}, :caller_reference => 'myid')
|
212
|
+
end
|
213
|
+
assert_equal '1.00', request.transaction_amount.value
|
214
|
+
end
|
215
|
+
|
216
|
+
should "parse a Pay response" do
|
217
|
+
response = nil
|
218
|
+
assert_nothing_raised do
|
219
|
+
response = AmazonFlexPay::API::Pay::Response.from_xml(reserve_response)
|
220
|
+
end
|
221
|
+
assert !response.error?
|
222
|
+
assert response.request_id
|
223
|
+
assert response.transaction_id
|
224
|
+
assert response.transaction_status
|
225
|
+
end
|
226
|
+
|
227
|
+
## Refund
|
228
|
+
|
229
|
+
should "construct a Refund request" do
|
230
|
+
request = nil
|
231
|
+
assert_nothing_raised do
|
232
|
+
request = AmazonFlexPay::API::Refund.new(:transaction_id => 'txid', :caller_reference => 'myid', :refund_amount => {:currency_code => 'USD', :value => '1.00'})
|
233
|
+
end
|
234
|
+
assert_equal '1.00', request.refund_amount.value
|
235
|
+
end
|
236
|
+
|
237
|
+
should "parse a Refund response" do
|
238
|
+
response = nil
|
239
|
+
assert_nothing_raised do
|
240
|
+
response = AmazonFlexPay::API::Refund::Response.from_xml(refund_response)
|
241
|
+
end
|
242
|
+
assert !response.error?
|
243
|
+
assert response.request_id
|
244
|
+
assert response.transaction_id
|
245
|
+
assert response.transaction_status
|
246
|
+
end
|
247
|
+
|
248
|
+
## Reserve
|
249
|
+
|
250
|
+
should "construct a Reserve request" do
|
251
|
+
request = nil
|
252
|
+
assert_nothing_raised do
|
253
|
+
request = AmazonFlexPay::API::Reserve.new(:sender_token_id => 'token', :transaction_amount => {:currency_code => 'USD', :value => '1.00'}, :caller_reference => 'myid', :descriptor_policy => {:cs_owner => 'Caller', :soft_descriptor_type => 'Static'})
|
254
|
+
end
|
255
|
+
assert_equal 'Caller', request.descriptor_policy.cs_owner
|
256
|
+
assert request.to_params['DescriptorPolicy'].has_key?('CSOwner') # funky casing
|
257
|
+
end
|
258
|
+
|
259
|
+
should "parse a Reserve response" do
|
260
|
+
response = nil
|
261
|
+
assert_nothing_raised do
|
262
|
+
response = AmazonFlexPay::API::Reserve::Response.from_xml(reserve_response)
|
263
|
+
end
|
264
|
+
assert !response.error?
|
265
|
+
assert response.request_id
|
266
|
+
assert response.transaction_id
|
267
|
+
assert response.transaction_status
|
268
|
+
end
|
269
|
+
|
270
|
+
## Settle
|
271
|
+
|
272
|
+
should "construct a Settle request" do
|
273
|
+
request = nil
|
274
|
+
assert_nothing_raised do
|
275
|
+
request = AmazonFlexPay::API::Settle.new(:reserve_transaction_id => 'txid', :transaction_amount => {:currency_code => 'USD', :value => '3.14'})
|
276
|
+
end
|
277
|
+
assert_equal 'USD', request.transaction_amount.currency_code
|
278
|
+
assert_equal '3.14', request.transaction_amount.value
|
279
|
+
end
|
280
|
+
|
281
|
+
should "parse a Settle response" do
|
282
|
+
response = nil
|
283
|
+
assert_nothing_raised do
|
284
|
+
response = AmazonFlexPay::API::Settle::Response.from_xml(settle_response)
|
285
|
+
end
|
286
|
+
assert !response.error?
|
287
|
+
assert response.request_id
|
288
|
+
assert response.transaction_id
|
289
|
+
assert response.transaction_status
|
290
|
+
end
|
291
|
+
|
292
|
+
## VerifySignature
|
293
|
+
|
294
|
+
should "construct a VerifySignature request" do
|
295
|
+
AmazonFlexPay::API::VerifySignature.any_instance.expects(:submit)
|
296
|
+
assert_nothing_raised do
|
297
|
+
AmazonFlexPay.verify_signature('http://example.com/api', 'foo=bar')
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
should "parse a VerifySignature response" do
|
302
|
+
response = nil
|
303
|
+
assert_nothing_raised do
|
304
|
+
response = AmazonFlexPay::API::VerifySignature::Response.from_xml(verify_signature_response)
|
305
|
+
end
|
306
|
+
assert !response.error?
|
307
|
+
assert response.request_id
|
308
|
+
assert response.verification_status
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class AmazonFlexPayPipelinesTest < AmazonFlexPay::Test
|
4
|
+
should "build a edit token pipeline" do
|
5
|
+
params = nil
|
6
|
+
assert_nothing_raised do
|
7
|
+
params = AmazonFlexPay.edit_token_pipeline('pipe1', :token_id => 'token').to_params('http://example.com/return')
|
8
|
+
end
|
9
|
+
assert_equal 'pipe1', params['callerReference']
|
10
|
+
end
|
11
|
+
|
12
|
+
should "build a multi use pipeline" do
|
13
|
+
params = nil
|
14
|
+
assert_nothing_raised do
|
15
|
+
params = AmazonFlexPay.multi_use_pipeline('pipe2',
|
16
|
+
:global_amount_limit => "50.00",
|
17
|
+
:usage_limit_type1 => 'Count',
|
18
|
+
:usage_limit_value1 => '2'
|
19
|
+
).to_params('http://example.com/return')
|
20
|
+
end
|
21
|
+
assert_equal 'pipe2', params['callerReference']
|
22
|
+
assert_equal '50.00', params['globalAmountLimit']
|
23
|
+
assert_equal 'Count', params['usageLimitType1']
|
24
|
+
assert_equal '2', params['usageLimitValue1']
|
25
|
+
end
|
26
|
+
|
27
|
+
should "build a recipient pipeline" do
|
28
|
+
params = nil
|
29
|
+
assert_nothing_raised do
|
30
|
+
params = AmazonFlexPay::recipient_pipeline('pipe3', :recipient_pays_fee => true).to_params('http://example.com/return')
|
31
|
+
end
|
32
|
+
assert_equal 'pipe3', params['callerReference']
|
33
|
+
end
|
34
|
+
|
35
|
+
should "build a single use pipeline" do
|
36
|
+
params = nil
|
37
|
+
assert_nothing_raised do
|
38
|
+
params = AmazonFlexPay.single_use_pipeline('pipe4',
|
39
|
+
:recipient_token => 'token',
|
40
|
+
:transaction_amount => '25.00'
|
41
|
+
).to_params('http://example.com/return')
|
42
|
+
end
|
43
|
+
assert_equal 'pipe4', params['callerReference']
|
44
|
+
assert_equal '25.00', params['transactionAmount']
|
45
|
+
end
|
46
|
+
end
|