VantivCnp 8.31.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.
- checksums.yaml +7 -0
- data/CHANGELOG +139 -0
- data/CONTRIBUTORS +2 -0
- data/DESCRIPTION +5 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +89 -0
- data/SETUP.md +46 -0
- data/bin/Setup.rb +124 -0
- data/bin/sample_batch_driver.rb +123 -0
- data/bin/sample_driver.rb +49 -0
- data/lib/Communications.rb +85 -0
- data/lib/Configuration.rb +67 -0
- data/lib/EnvironmentVariables.rb +22 -0
- data/lib/LitleBatchRequest.rb +562 -0
- data/lib/LitleListeners.rb +142 -0
- data/lib/LitleOnline.rb +62 -0
- data/lib/LitleOnlineRequest.rb +297 -0
- data/lib/LitleRequest.rb +494 -0
- data/lib/LitleTransaction.rb +463 -0
- data/lib/LitleXmlMapper.rb +64 -0
- data/lib/XMLFields.rb +1869 -0
- data/lib/cacert.pem +3331 -0
- data/samples/Auth/LitleAuthReversalTransaction.rb +15 -0
- data/samples/Auth/LitleAuthorizationTransaction.rb +31 -0
- data/samples/Auth/LitlePaymentFullLifeCycle.rb +47 -0
- data/samples/Batch/AccountUpdate.rb +64 -0
- data/samples/Batch/SampleBatchDriver.rb +94 -0
- data/samples/Capture/LitleCaptureGivenAuthTransaction.rb +30 -0
- data/samples/Capture/LitleCaptureTransaction.rb +14 -0
- data/samples/Capture/LitleForceCaptureTransaction.rb +26 -0
- data/samples/Capture/LitlePartialCapture.rb +16 -0
- data/samples/Credit/LitleCreditTransaction.rb +16 -0
- data/samples/Credit/LitleRefundTransaction.rb +29 -0
- data/samples/Other/LitleAvsTransaction.rb +34 -0
- data/samples/Other/LitleVoidTransaction.rb +18 -0
- data/samples/Paypage/FullPaypageLifeCycle.rb +74 -0
- data/samples/Run_all.rb +17 -0
- data/samples/Sale/LitleSaleTransaction.rb +29 -0
- data/samples/Sale/SampleSaleTransaction.rb +24 -0
- data/test/certification/certTest1_base.rb +945 -0
- data/test/certification/certTest2_authenhanced.rb +573 -0
- data/test/certification/certTest3_authreversal.rb +185 -0
- data/test/certification/certTest4_echeck.rb +278 -0
- data/test/certification/certTest5_token.rb +204 -0
- data/test/certification/certTest_batchAll.rb +337 -0
- data/test/certification/ts_all.rb +33 -0
- data/test/functional/test_activate.rb +100 -0
- data/test/functional/test_activateReversal.rb +56 -0
- data/test/functional/test_auth.rb +298 -0
- data/test/functional/test_authReversal.rb +69 -0
- data/test/functional/test_balanceInquiry.rb +80 -0
- data/test/functional/test_batch.rb +164 -0
- data/test/functional/test_batchStream.rb +145 -0
- data/test/functional/test_cancelSubscription.rb +55 -0
- data/test/functional/test_capture.rb +84 -0
- data/test/functional/test_captureGivenAuth.rb +235 -0
- data/test/functional/test_configuration.rb +89 -0
- data/test/functional/test_createPlan.rb +85 -0
- data/test/functional/test_credit.rb +174 -0
- data/test/functional/test_deactivate.rb +80 -0
- data/test/functional/test_deactivateReversal.rb +56 -0
- data/test/functional/test_depositReversal.rb +56 -0
- data/test/functional/test_echeckCredit.rb +134 -0
- data/test/functional/test_echeckRedeposit.rb +88 -0
- data/test/functional/test_echeckSale.rb +177 -0
- data/test/functional/test_echeckVerification.rb +127 -0
- data/test/functional/test_echeckVoid.rb +41 -0
- data/test/functional/test_forceCapture.rb +183 -0
- data/test/functional/test_litle_requests.rb +356 -0
- data/test/functional/test_load.rb +82 -0
- data/test/functional/test_loadReversal.rb +56 -0
- data/test/functional/test_override.rb +64 -0
- data/test/functional/test_refundReversal.rb +56 -0
- data/test/functional/test_sale.rb +259 -0
- data/test/functional/test_token.rb +115 -0
- data/test/functional/test_unload.rb +82 -0
- data/test/functional/test_unloadReversal.rb +56 -0
- data/test/functional/test_updateCardValidationNumOnToken.rb +43 -0
- data/test/functional/test_updatePlan.rb +58 -0
- data/test/functional/test_updateSubscription.rb +76 -0
- data/test/functional/test_xmlfields.rb +427 -0
- data/test/functional/ts_all.rb +66 -0
- data/test/unit/test_LitleAUBatch.rb +216 -0
- data/test/unit/test_LitleBatchRequest.rb +643 -0
- data/test/unit/test_LitleOnlineRequest.rb +295 -0
- data/test/unit/test_LitleRequest.rb +316 -0
- data/test/unit/test_LitleTransaction.rb +397 -0
- data/test/unit/test_activate.rb +92 -0
- data/test/unit/test_activateReversal.rb +44 -0
- data/test/unit/test_auth.rb +421 -0
- data/test/unit/test_authReversal.rb +82 -0
- data/test/unit/test_balanceInquiry.rb +52 -0
- data/test/unit/test_cancelSubscription.rb +43 -0
- data/test/unit/test_capture.rb +73 -0
- data/test/unit/test_captureGivenAuth.rb +188 -0
- data/test/unit/test_createPlan.rb +52 -0
- data/test/unit/test_credit.rb +342 -0
- data/test/unit/test_deactivate.rb +52 -0
- data/test/unit/test_deactivateReversal.rb +44 -0
- data/test/unit/test_depositReversal.rb +44 -0
- data/test/unit/test_echeckCredit.rb +71 -0
- data/test/unit/test_echeckRedeposit.rb +94 -0
- data/test/unit/test_echeckSale.rb +71 -0
- data/test/unit/test_echeckVerification.rb +71 -0
- data/test/unit/test_echeckVoid.rb +54 -0
- data/test/unit/test_forceCapture.rb +145 -0
- data/test/unit/test_load.rb +53 -0
- data/test/unit/test_loadReversal.rb +44 -0
- data/test/unit/test_refundReversal.rb +44 -0
- data/test/unit/test_sale.rb +465 -0
- data/test/unit/test_token.rb +144 -0
- data/test/unit/test_unload.rb +53 -0
- data/test/unit/test_unloadReversal.rb +44 -0
- data/test/unit/test_updateCardValidationNumOnToken.rb +80 -0
- data/test/unit/test_updatePlan.rb +45 -0
- data/test/unit/test_updateSubscription.rb +172 -0
- data/test/unit/test_xmlfields.rb +2930 -0
- data/test/unit/ts_unit.rb +65 -0
- metadata +224 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
Copyright (c) 2011 Litle & Co.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
|
5
|
+
obtaining a copy of this software and associated documentation
|
|
6
|
+
files (the "Software"), to deal in the Software without
|
|
7
|
+
restriction, including without limitation the rights to use,
|
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the
|
|
10
|
+
Software is furnished to do so, subject to the following
|
|
11
|
+
conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
=end
|
|
25
|
+
require File.expand_path("../../../lib/LitleOnline",__FILE__)
|
|
26
|
+
require 'test/unit'
|
|
27
|
+
require 'mocha/setup'
|
|
28
|
+
|
|
29
|
+
module LitleOnline
|
|
30
|
+
|
|
31
|
+
class TestLitleOnlineRequest < Test::Unit::TestCase
|
|
32
|
+
def test_set_merchant_id
|
|
33
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}})
|
|
34
|
+
litle = LitleOnlineRequest.new
|
|
35
|
+
assert_equal '2', litle.send(:get_merchant_id, {'merchantId'=>'2'})
|
|
36
|
+
assert_equal '1', litle.send(:get_merchant_id, {'NotMerchantId'=>'2'})
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_simple
|
|
40
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
41
|
+
hash = {
|
|
42
|
+
'reportGroup'=>'Planets',
|
|
43
|
+
'orderId'=>'12344',
|
|
44
|
+
'amount'=>'106',
|
|
45
|
+
'orderSource'=>'ecommerce',
|
|
46
|
+
'card'=>{
|
|
47
|
+
'type'=>'VI',
|
|
48
|
+
'number' =>'4100000000000001',
|
|
49
|
+
'expDate' =>'1210'
|
|
50
|
+
}}
|
|
51
|
+
|
|
52
|
+
Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest .*/m),kind_of(Hash))
|
|
53
|
+
XMLObject.expects(:new)
|
|
54
|
+
|
|
55
|
+
response = LitleOnlineRequest.new.authorization(hash)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_authorization_attributes
|
|
59
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
60
|
+
hash={
|
|
61
|
+
'reportGroup'=>'Planets',
|
|
62
|
+
'id' => '003',
|
|
63
|
+
'orderId'=>'12344',
|
|
64
|
+
'amount'=>'106',
|
|
65
|
+
'orderSource'=>'ecommerce',
|
|
66
|
+
'card'=>{
|
|
67
|
+
'type'=>'VI',
|
|
68
|
+
'number' =>'4100000000000001',
|
|
69
|
+
'expDate' =>'1210'
|
|
70
|
+
}}
|
|
71
|
+
|
|
72
|
+
Communications.expects(:http_post).with(regexp_matches(/.*<authorization ((reportGroup="Planets" id="003")|(id="003" reportGroup="Planets")).*/m),kind_of(Hash))
|
|
73
|
+
XMLObject.expects(:new)
|
|
74
|
+
|
|
75
|
+
response = LitleOnlineRequest.new.authorization(hash)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_authorization_elements
|
|
79
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
80
|
+
hash={
|
|
81
|
+
'reportGroup'=>'Planets',
|
|
82
|
+
'id' => '004',
|
|
83
|
+
'orderId'=>'12344',
|
|
84
|
+
'amount'=>'106',
|
|
85
|
+
'orderSource'=>'ecommerce',
|
|
86
|
+
'card'=>{
|
|
87
|
+
'type'=>'VI',
|
|
88
|
+
'number' =>'4100000000000001',
|
|
89
|
+
'expDate' =>'1210'
|
|
90
|
+
}}
|
|
91
|
+
|
|
92
|
+
Communications.expects(:http_post).with(regexp_matches(/.*<authorization.*<orderId>12344.*<amount>106.*<orderSource>ecommerce.*/m),kind_of(Hash))
|
|
93
|
+
XMLObject.expects(:new)
|
|
94
|
+
|
|
95
|
+
response = LitleOnlineRequest.new.authorization(hash)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_authorization_card_field
|
|
99
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
100
|
+
hash={
|
|
101
|
+
'reportGroup'=>'Planets',
|
|
102
|
+
'id' => '005',
|
|
103
|
+
'orderId'=>'12344',
|
|
104
|
+
'amount'=>'106',
|
|
105
|
+
'orderSource'=>'ecommerce',
|
|
106
|
+
'card'=>{
|
|
107
|
+
'type'=>'VI',
|
|
108
|
+
'number' =>'4100000000000001',
|
|
109
|
+
'expDate' =>'1210'
|
|
110
|
+
}}
|
|
111
|
+
|
|
112
|
+
Communications.expects(:http_post).with(regexp_matches(/.*<authorization.*<card>.*<number>4100000000000001.*<expDate>1210.*/m),kind_of(Hash))
|
|
113
|
+
XMLObject.expects(:new)
|
|
114
|
+
|
|
115
|
+
response = LitleOnlineRequest.new.authorization(hash)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_sale_card_field
|
|
119
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
120
|
+
hash = {
|
|
121
|
+
'reportGroup'=>'Planets',
|
|
122
|
+
'id' => '006',
|
|
123
|
+
'orderId'=>'12344',
|
|
124
|
+
'amount'=>'106',
|
|
125
|
+
'orderSource'=>'ecommerce',
|
|
126
|
+
'card'=>{
|
|
127
|
+
'type'=>'VI',
|
|
128
|
+
'number' =>'4100000000000001',
|
|
129
|
+
'expDate' =>'1210'
|
|
130
|
+
}}
|
|
131
|
+
|
|
132
|
+
Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest.*<sale.*<card>.*<number>4100000000000001.*<expDate>1210.*/m),kind_of(Hash))
|
|
133
|
+
XMLObject.expects(:new)
|
|
134
|
+
|
|
135
|
+
response = LitleOnlineRequest.new.sale(hash)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_capture_amount_unset_should_not_be_in_xml
|
|
139
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
140
|
+
hash={
|
|
141
|
+
'id' => '006',
|
|
142
|
+
'reportGroup'=>'Planets',
|
|
143
|
+
'litleTxnId'=>'123456789012345678'
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
|
|
147
|
+
XMLObject.expects(:new)
|
|
148
|
+
|
|
149
|
+
response = LitleOnlineRequest.new.capture(hash)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_force_capture_amount_unset_should_not_be_in_xml
|
|
153
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
154
|
+
hash={
|
|
155
|
+
'id' => '006',
|
|
156
|
+
'orderId'=>'12344',
|
|
157
|
+
'reportGroup'=>'Planets',
|
|
158
|
+
'orderSource'=>'ecommerce',
|
|
159
|
+
'litleTxnId'=>'123456789012345678'
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
|
|
163
|
+
XMLObject.expects(:new)
|
|
164
|
+
|
|
165
|
+
response = LitleOnlineRequest.new.force_capture(hash)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_amount_is_not_required_in_echeck_credit
|
|
169
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
170
|
+
hash={
|
|
171
|
+
'id' => '006',
|
|
172
|
+
'orderId'=>'12344',
|
|
173
|
+
'reportGroup'=>'Planets',
|
|
174
|
+
'orderSource'=>'ecommerce',
|
|
175
|
+
'litleTxnId'=>'123456789012345678',
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
|
|
179
|
+
XMLObject.expects(:new)
|
|
180
|
+
|
|
181
|
+
response = LitleOnlineRequest.new.echeck_credit(hash)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def test_amount_is_not_required_in_echeck_sale
|
|
185
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
186
|
+
hash={
|
|
187
|
+
'id' => '006',
|
|
188
|
+
'orderId'=>'12344',
|
|
189
|
+
'reportGroup'=>'Planets',
|
|
190
|
+
'orderSource'=>'ecommerce',
|
|
191
|
+
'litleTxnId'=>'123456789012345678',
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
|
|
195
|
+
XMLObject.expects(:new)
|
|
196
|
+
|
|
197
|
+
response = LitleOnlineRequest.new.echeck_sale(hash)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def test_choice_between_card_token
|
|
201
|
+
start_hash = {
|
|
202
|
+
'orderId'=>'12344',
|
|
203
|
+
'merchantId'=>'101',
|
|
204
|
+
'reportGroup'=>'Planets',
|
|
205
|
+
'amount'=>'101',
|
|
206
|
+
'orderSource'=>'ecommerce'
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
card_only = {
|
|
210
|
+
'card' => {
|
|
211
|
+
'type' => 'VI',
|
|
212
|
+
'number' => '1111222233334444'
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
XMLObject.expects(:new)
|
|
217
|
+
Communications.expects(:http_post).with(regexp_matches(/.*card.*/m),kind_of(Hash))
|
|
218
|
+
LitleOnlineRequest.new.authorization(start_hash.merge(card_only))
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def test_choice_between_card_token2
|
|
222
|
+
start_hash = {
|
|
223
|
+
'orderId'=>'12344',
|
|
224
|
+
'merchantId'=>'101',
|
|
225
|
+
'reportGroup'=>'Planets',
|
|
226
|
+
'amount'=>'101',
|
|
227
|
+
'orderSource'=>'ecommerce'
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
token_only = {
|
|
231
|
+
'token'=> {
|
|
232
|
+
'litleToken' => '1111222233334444'
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
XMLObject.expects(:new)
|
|
237
|
+
Communications.expects(:http_post).with(regexp_matches(/.*token.*/m),kind_of(Hash))
|
|
238
|
+
LitleOnlineRequest.new.authorization(start_hash.merge(token_only))
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def test_set_merchant_sdk
|
|
242
|
+
litle = LitleOnlineRequest.new
|
|
243
|
+
#Explicit - used for integrations
|
|
244
|
+
assert_equal 'ActiveMerchant;3.2', litle.send(:get_merchant_sdk, {'merchantSdk'=>'ActiveMerchant;3.2'})
|
|
245
|
+
#Implicit - used raw when nothing is specified
|
|
246
|
+
assert_equal 'Ruby;8.31.0', litle.send(:get_merchant_sdk, {'NotMerchantSdk'=>'ActiveMerchant;3.2'})
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def test_sale_paypal_order_complete_typo
|
|
250
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
251
|
+
hash={
|
|
252
|
+
'reportGroup'=>'Planets',
|
|
253
|
+
'id' => '006',
|
|
254
|
+
'orderId'=>'12344',
|
|
255
|
+
'amount'=>'106',
|
|
256
|
+
'orderSource'=>'ecommerce',
|
|
257
|
+
'payPalOrderComplete'=>'true',
|
|
258
|
+
'card'=>{
|
|
259
|
+
'type'=>'VI',
|
|
260
|
+
'number' =>'4100000000000001',
|
|
261
|
+
'expDate' =>'1210'
|
|
262
|
+
}}
|
|
263
|
+
|
|
264
|
+
Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest.*<sale.*<payPalOrderComplete>true<\/payPalOrderComplete>.*/m),kind_of(Hash))
|
|
265
|
+
XMLObject.expects(:new)
|
|
266
|
+
|
|
267
|
+
response = LitleOnlineRequest.new.sale(hash)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def test_version_matches_sdk_major_and_minor_version_ignoring_config
|
|
271
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
272
|
+
hash={
|
|
273
|
+
'litleTxnId' => '006'
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest.*version="8\.31".*/m),kind_of(Hash))
|
|
277
|
+
XMLObject.expects(:new)
|
|
278
|
+
|
|
279
|
+
response = LitleOnlineRequest.new.void(hash)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def test_void_response_contains_recycling
|
|
283
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
|
|
284
|
+
hash={
|
|
285
|
+
'litleTxnId' => '123'
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
Communications.expects(:http_post).with(kind_of(String),kind_of(Hash)).returns('<litleOnlineResponse><voidResponse><recycling><creditLitleTxnId>65</creditLitleTxnId></recycling></voidResponse></litleOnlineResponse>')
|
|
289
|
+
|
|
290
|
+
response = LitleOnlineRequest.new.void(hash)
|
|
291
|
+
assert_equal '65', response.voidResponse.recycling.creditLitleTxnId
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
end
|
|
295
|
+
end
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
Copyright (c) 2011 Litle & Co.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
|
5
|
+
obtaining a copy of this software and associated documentation
|
|
6
|
+
files (the "Software"), to deal in the Software without
|
|
7
|
+
restriction, including without limitation the rights to use,
|
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the
|
|
10
|
+
Software is furnished to do so, subject to the following
|
|
11
|
+
conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
=end
|
|
25
|
+
require File.expand_path("../../../lib/LitleOnline",__FILE__)
|
|
26
|
+
require 'test/unit'
|
|
27
|
+
require 'mocha/setup'
|
|
28
|
+
|
|
29
|
+
module LitleOnline
|
|
30
|
+
|
|
31
|
+
class TestLitleRequest < Test::Unit::TestCase
|
|
32
|
+
|
|
33
|
+
def test_create_with_file
|
|
34
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
35
|
+
'user'=>'john',
|
|
36
|
+
'password'=>'tinkleberry'})
|
|
37
|
+
message = ""
|
|
38
|
+
File.expects(:file?).with('/durrrrrr').returns(true).once
|
|
39
|
+
request.create_new_litle_request('/durrrrrr')
|
|
40
|
+
|
|
41
|
+
rescue RuntimeError=> e
|
|
42
|
+
message = e.message
|
|
43
|
+
|
|
44
|
+
assert_equal message, "Entered a file not a path."
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_create_with_no_sep
|
|
48
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
49
|
+
'user'=>'john',
|
|
50
|
+
'password'=>'tinkleberry'})
|
|
51
|
+
File.expects(:open).twice
|
|
52
|
+
request.create_new_litle_request('/usr/local')
|
|
53
|
+
assert request.get_path_to_batches.include?('/usr/local/')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_create_name_collision
|
|
57
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
58
|
+
'user'=>'john',
|
|
59
|
+
'password'=>'tinkleberry'})
|
|
60
|
+
|
|
61
|
+
create_new = sequence('create_new')
|
|
62
|
+
File.expects(:file?).returns(false).in_sequence(create_new)
|
|
63
|
+
File.expects(:file?).returns(true).once.in_sequence(create_new) #yayay short circuiting
|
|
64
|
+
File.expects(:file?).returns(false).once.in_sequence(create_new)
|
|
65
|
+
File.expects(:file?).returns(false).twice.in_sequence(create_new) #or's don't quit
|
|
66
|
+
File.expects(:open).twice.in_sequence(create_new)
|
|
67
|
+
|
|
68
|
+
request.create_new_litle_request('/usr/local')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_create_normal
|
|
72
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
73
|
+
'user'=>'john',
|
|
74
|
+
'password'=>'tinkleberry'})
|
|
75
|
+
|
|
76
|
+
create_new = sequence('create_new')
|
|
77
|
+
File.expects(:file?).returns(false).once.in_sequence(create_new)
|
|
78
|
+
File.expects(:file?).returns(false).twice.in_sequence(create_new)
|
|
79
|
+
File.expects(:open).once.in_sequence(create_new)
|
|
80
|
+
File.expects(:open).once.in_sequence(create_new)
|
|
81
|
+
|
|
82
|
+
request.create_new_litle_request('/usr/local')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_add_rfr_request_litle_session
|
|
86
|
+
add_rfr = sequence('add_rfr')
|
|
87
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1).in_sequence(add_rfr)
|
|
88
|
+
|
|
89
|
+
File.expects(:file?).with('/usr/srv').returns(false).in_sequence(add_rfr)
|
|
90
|
+
File.expects(:directory?).with('/usr/srv/').returns(true).in_sequence(add_rfr)
|
|
91
|
+
File.expects(:open).with(regexp_matches(/request_\d+\z/), 'a+').in_sequence(add_rfr)
|
|
92
|
+
File.expects(:rename).with(regexp_matches(/request_\d+\z/), regexp_matches(/request_\d+.complete\z/)).in_sequence(add_rfr)
|
|
93
|
+
|
|
94
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
95
|
+
'user'=>'john',
|
|
96
|
+
'password'=>'tinkleberry'})
|
|
97
|
+
request.add_rfr_request({'litleSessionId' => '137813712'}, '/usr/srv')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_commit_batch_with_batch
|
|
101
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
|
|
102
|
+
|
|
103
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
104
|
+
'user'=>'john',
|
|
105
|
+
'password'=>'tinkleberry'})
|
|
106
|
+
File.expects(:file?).returns(false).once
|
|
107
|
+
File.expects(:file?).returns(false).twice #or's don't quit
|
|
108
|
+
File.expects(:open).twice
|
|
109
|
+
File.expects(:directory?).returns(true).once
|
|
110
|
+
request.create_new_litle_request("/usr/srv/batches")
|
|
111
|
+
|
|
112
|
+
batch = LitleBatchRequest.new
|
|
113
|
+
File.expects(:open).twice
|
|
114
|
+
File.expects(:file?).returns(false).twice
|
|
115
|
+
File.expects(:directory?).returns(true).once
|
|
116
|
+
batch.create_new_batch('/usr/srv/batches')
|
|
117
|
+
File.expects(:rename).once
|
|
118
|
+
File.expects(:open).once
|
|
119
|
+
File.expects(:delete).once
|
|
120
|
+
batch.close_batch()
|
|
121
|
+
|
|
122
|
+
File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
|
|
123
|
+
File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
|
|
124
|
+
request.commit_batch(batch)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_commit_batch_with_path
|
|
128
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
|
|
129
|
+
|
|
130
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
131
|
+
'user'=>'john',
|
|
132
|
+
'password'=>'tinkleberry'})
|
|
133
|
+
File.expects(:file?).returns(false).once
|
|
134
|
+
File.expects(:file?).returns(false).twice #or's don't quit
|
|
135
|
+
File.expects(:open).twice
|
|
136
|
+
File.expects(:directory?).returns(true).once
|
|
137
|
+
request.create_new_litle_request("/usr/srv/batches")
|
|
138
|
+
|
|
139
|
+
File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
|
|
140
|
+
File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
|
|
141
|
+
request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_add_bad_object
|
|
145
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
|
|
146
|
+
request = LitleRequest.new({})
|
|
147
|
+
request.commit_batch({:apple => "pear"})
|
|
148
|
+
test = ""
|
|
149
|
+
rescue RuntimeError => e
|
|
150
|
+
test = e.message
|
|
151
|
+
assert_equal test, "You entered neither a path nor a batch. Game over :("
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_add_open_batch
|
|
155
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
|
|
156
|
+
File.expects(:open).with(regexp_matches(/\/usr\/srv\/.*/), 'a+').times(2)
|
|
157
|
+
|
|
158
|
+
Dir.expects(:mkdir).with('/usr/srv/batches/').once
|
|
159
|
+
batch = LitleBatchRequest.new
|
|
160
|
+
batch.create_new_batch('/usr/srv/batches')
|
|
161
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
162
|
+
'user'=>'john',
|
|
163
|
+
'password'=>'tinkleberry'})
|
|
164
|
+
|
|
165
|
+
close_and_add = sequence('close_and_add')
|
|
166
|
+
batch.expects(:get_batch_name).returns("/usr/srv/batches/batch_123123131231").once.in_sequence(close_and_add)
|
|
167
|
+
batch.expects(:close_batch).once.in_sequence(close_and_add)
|
|
168
|
+
batch.expects(:get_batch_name).returns(str = "/usr/srv/batches/batch_123123131231.closed-1000").once.in_sequence(close_and_add)
|
|
169
|
+
str.expects(:index).returns(7).once.in_sequence(close_and_add)
|
|
170
|
+
File.expects(:open).once.in_sequence(close_and_add)
|
|
171
|
+
File.expects(:delete).once.in_sequence(close_and_add)
|
|
172
|
+
request.commit_batch(batch)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_batch_too_big
|
|
176
|
+
Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
|
|
177
|
+
|
|
178
|
+
request = LitleRequest.new({'sessionId'=>'8675309',
|
|
179
|
+
'user'=>'john',
|
|
180
|
+
'password'=>'tinkleberry'})
|
|
181
|
+
File.expects(:file?).returns(false).once
|
|
182
|
+
File.expects(:file?).returns(false).twice #or's don't quit
|
|
183
|
+
File.expects(:open).twice
|
|
184
|
+
File.expects(:directory?).returns(true).once
|
|
185
|
+
request.create_new_litle_request("/usr/srv/batches")
|
|
186
|
+
create_new = sequence('create_new')
|
|
187
|
+
|
|
188
|
+
File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+').times(5)
|
|
189
|
+
File.expects(:delete).with(regexp_matches(/.*\.closed.*/)).times(5)
|
|
190
|
+
5.times {
|
|
191
|
+
|
|
192
|
+
request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
request.expects(:finish_request).once
|
|
196
|
+
request.expects(:initialize).once
|
|
197
|
+
request.expects(:create_new_litle_request).once
|
|
198
|
+
request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
#TODO: see of we can get deeper with mocking the node returned
|
|
202
|
+
def test_process_response_success
|
|
203
|
+
xml = sequence("xml")
|
|
204
|
+
LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new).in_sequence(xml)
|
|
205
|
+
reader.expects(:read).once.in_sequence(xml)
|
|
206
|
+
reader.expects(:get_attribute).with('response').returns("0").in_sequence(xml)
|
|
207
|
+
reader.expects(:read).once.in_sequence(xml)
|
|
208
|
+
reader.expects(:node).returns(node = LibXML::XML::Node.new("litleResponse")).twice.in_sequence(xml)
|
|
209
|
+
|
|
210
|
+
request = LitleRequest.new({})
|
|
211
|
+
request.process_response(Dir.pwd + '/responses/good_xml.xml' ,
|
|
212
|
+
DefaultLitleListener.new{|txn| puts txn["type"]} ,
|
|
213
|
+
DefaultLitleListener.new{|batch| } )
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def test_process_response_xml_error
|
|
217
|
+
LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new)
|
|
218
|
+
reader.expects(:read).once
|
|
219
|
+
reader.expects(:get_attribute).with('response').twice.returns(4)
|
|
220
|
+
reader.expects(:get_attribute).with("message").returns("Error validating xml data against the schema")
|
|
221
|
+
|
|
222
|
+
request = LitleRequest.new({})
|
|
223
|
+
response = ''
|
|
224
|
+
begin
|
|
225
|
+
request.process_response(Dir.pwd + '/responses/bad_xml.xml' ,
|
|
226
|
+
DefaultLitleListener.new{|txn| puts txn["type"]} ,
|
|
227
|
+
DefaultLitleListener.new{|batch| } )
|
|
228
|
+
rescue Exception => e
|
|
229
|
+
response = e.message
|
|
230
|
+
end
|
|
231
|
+
assert_equal "Error parsing Litle Request: Error validating xml data against the schema", response.to_s
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_process_responses
|
|
235
|
+
request = LitleRequest.new({})
|
|
236
|
+
listener = DefaultLitleListener.new
|
|
237
|
+
args = {:transaction_listener=>listener,:path_to_responses=>"fake/path/"}
|
|
238
|
+
args.expects(:[]).with(:transaction_listener)
|
|
239
|
+
args.expects(:[]).with(:batch_listener).returns(nil)
|
|
240
|
+
args.expects(:[]).with(:path_to_responses).returns("fake/path/")
|
|
241
|
+
Dir.expects(:foreach).with("fake/path/")
|
|
242
|
+
|
|
243
|
+
request.process_responses(args)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def test_get_responses_from_server
|
|
247
|
+
request = LitleRequest.new({})
|
|
248
|
+
resp_seq = sequence("resp_seq")
|
|
249
|
+
args = {:responses_expected=>4, :response_path=>"new/path", :sftp_username=>"periwinkle",:sftp_password=>"password", :sftp_url=>"reddit.com"}
|
|
250
|
+
|
|
251
|
+
File.expects(:directory?).with("new/path/").returns(false).once.in_sequence(resp_seq)
|
|
252
|
+
Dir.expects(:mkdir).with("new/path/").once.in_sequence(resp_seq)
|
|
253
|
+
Net::SFTP.expects(:start).twice.with("reddit.com", "periwinkle", :password=>"password")
|
|
254
|
+
|
|
255
|
+
request.get_responses_from_server(args)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_send_over_stream
|
|
259
|
+
request = LitleRequest.new({})
|
|
260
|
+
req_seq = sequence('request')
|
|
261
|
+
|
|
262
|
+
File.expects(:directory?).with(regexp_matches(/responses\//)).once.returns(false).in_sequence(req_seq)
|
|
263
|
+
Dir.expects(:mkdir).with(regexp_matches(/responses\//)).once.in_sequence(req_seq)
|
|
264
|
+
Dir.expects(:foreach).once.in_sequence(req_seq)
|
|
265
|
+
|
|
266
|
+
request.send_to_litle_stream({:fast_url=>"www.redit.com", :fast_port=>"2313"})
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def test_send_over_stream_bad_crds
|
|
270
|
+
request = LitleRequest.new({})
|
|
271
|
+
|
|
272
|
+
assert_raise ArgumentError do
|
|
273
|
+
request.send_to_litle_stream({:fast_url=>"", :fast_port=>""})
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
#Outputs an example LitleRequest doc in the current directory
|
|
277
|
+
# def test_finish_request_xml! #that's why the name has a bang
|
|
278
|
+
# # see the bang up there ^^^ that means we ACTUALLY edit the file system
|
|
279
|
+
# # make sure to clear this; otherwise, you're gonna have a bad time.
|
|
280
|
+
# path = Dir.pwd
|
|
281
|
+
#
|
|
282
|
+
# saleHash = {
|
|
283
|
+
# 'reportGroup'=>'Planets',
|
|
284
|
+
# 'id' => '006',
|
|
285
|
+
# 'orderId'=>'12344',
|
|
286
|
+
# 'amount'=>'6000',
|
|
287
|
+
# 'orderSource'=>'ecommerce',
|
|
288
|
+
# 'card'=>{
|
|
289
|
+
# 'type'=>'VI',
|
|
290
|
+
# 'number' =>'4100000000000001',
|
|
291
|
+
# 'expDate' =>'1210'
|
|
292
|
+
# }}
|
|
293
|
+
#
|
|
294
|
+
# request = LitleRequest.new({'sessionId'=>'8675309',
|
|
295
|
+
# 'user'=>'john',
|
|
296
|
+
# 'password'=>'tinkleberry'})
|
|
297
|
+
# request.create_new_litle_request(path)
|
|
298
|
+
#
|
|
299
|
+
#
|
|
300
|
+
# #5.times{
|
|
301
|
+
# batch = LitleBatchRequest.new
|
|
302
|
+
# batch.create_new_batch(path)
|
|
303
|
+
# puts "Batch is at: " + batch.get_batch_name
|
|
304
|
+
#
|
|
305
|
+
# #10.times{
|
|
306
|
+
# batch.sale(saleHash)
|
|
307
|
+
# #batch.update_card_validation_num_on_token(options)
|
|
308
|
+
# #}
|
|
309
|
+
#
|
|
310
|
+
# batch.close_batch()
|
|
311
|
+
# request.commit_batch(batch)
|
|
312
|
+
# #}
|
|
313
|
+
# request.finish_request
|
|
314
|
+
# end
|
|
315
|
+
end
|
|
316
|
+
end
|