LitleOnline 8.16.0 → 8.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/DESCRIPTION +1 -1
  3. data/README.md +2 -2
  4. data/Rakefile +6 -3
  5. data/bin/Setup.rb +14 -0
  6. data/bin/sample_batch_driver.rb +122 -0
  7. data/lib/LitleBatchRequest.rb +466 -0
  8. data/lib/LitleListeners.rb +142 -0
  9. data/lib/LitleOnline.rb +4 -0
  10. data/lib/LitleOnlineRequest.rb +25 -144
  11. data/lib/LitleRequest.rb +513 -0
  12. data/lib/LitleTransaction.rb +295 -0
  13. data/lib/XMLFields.rb +114 -4
  14. data/test/certification/certTest_batchAll.rb +337 -0
  15. data/test/certification/ts_all.rb +2 -0
  16. data/test/functional/test_batch.rb +164 -0
  17. data/test/functional/test_credit.rb +0 -18
  18. data/test/functional/test_litle_requests.rb +355 -0
  19. data/test/functional/test_updateCardValidationNumOnToken.rb +1 -1
  20. data/test/functional/test_xmlfields.rb +0 -19
  21. data/test/functional/ts_all.rb +2 -0
  22. data/test/unit/test_LitleAUBatch.rb +217 -0
  23. data/test/unit/test_LitleBatchRequest.rb +599 -0
  24. data/test/unit/test_LitleOnlineRequest.rb +9 -57
  25. data/test/unit/test_LitleRequest.rb +320 -0
  26. data/test/unit/test_LitleTransaction.rb +398 -0
  27. data/test/unit/test_auth.rb +25 -2
  28. data/test/unit/test_authReversal.rb +28 -5
  29. data/test/unit/test_capture.rb +24 -1
  30. data/test/unit/test_captureGivenAuth.rb +23 -1
  31. data/test/unit/test_credit.rb +92 -19
  32. data/test/unit/test_echeckCredit.rb +1 -1
  33. data/test/unit/test_echeckRedeposit.rb +1 -1
  34. data/test/unit/test_echeckSale.rb +1 -1
  35. data/test/unit/test_echeckVerification.rb +1 -1
  36. data/test/unit/test_echeckVoid.rb +1 -1
  37. data/test/unit/test_forceCapture.rb +24 -1
  38. data/test/unit/test_sale.rb +25 -2
  39. data/test/unit/test_token.rb +1 -1
  40. data/test/unit/test_updateCardValidationNumOnToken.rb +1 -1
  41. data/test/unit/test_xmlfields.rb +1 -1
  42. data/test/unit/ts_unit.rb +4 -0
  43. metadata +59 -14
@@ -0,0 +1,337 @@
1
+ =begin
2
+ Copyright (c) 2012 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
+
26
+ require 'lib/LitleOnline'
27
+ require 'test/unit'
28
+ require 'fileutils'
29
+
30
+ module LitleOnline
31
+ class LitleBatchCertTest < Test::Unit::TestCase
32
+ def setup
33
+ path = "/tmp/litle-sdk-for-ruby"
34
+ FileUtils.rm_rf path
35
+ if(!File.directory?(path))
36
+ Dir.mkdir(path)
37
+ end
38
+ path = "/tmp/litle-sdk-for-ruby/cert/"
39
+ if(!File.directory?(path))
40
+ Dir.mkdir(path)
41
+ end
42
+ end
43
+
44
+ def test_MEGA_batch
45
+ authHash = {
46
+ 'reportGroup'=>'Planets',
47
+ 'orderId'=>'12344',
48
+ 'amount'=>'106',
49
+ 'orderSource'=>'ecommerce',
50
+ 'card'=>{
51
+ 'type'=>'VI',
52
+ 'number' =>'4100000000000001',
53
+ 'expDate' =>'1210'
54
+ }}
55
+
56
+ saleHash = {
57
+ 'reportGroup'=>'Planets',
58
+ 'id' => '006',
59
+ 'orderId'=>'12344',
60
+ 'amount'=>'6000',
61
+ 'orderSource'=>'ecommerce',
62
+ 'card'=>{
63
+ 'type'=>'VI',
64
+ 'number' =>'4100000000000001',
65
+ 'expDate' =>'1210'
66
+ }}
67
+
68
+ creditHash = {
69
+ 'merchantId' => '101',
70
+ 'version'=>'8.8',
71
+ 'reportGroup'=>'Planets',
72
+ 'orderId'=>'12344',
73
+ 'amount'=>'106',
74
+ 'orderSource'=>'ecommerce',
75
+ 'card'=>{
76
+ 'type'=>'VI',
77
+ 'number' =>'4100000000000001',
78
+ 'expDate' =>'1210'
79
+ }}
80
+
81
+ authReversalHash = {
82
+ 'merchantId' => '101',
83
+ 'version'=>'8.8',
84
+ 'reportGroup'=>'Planets',
85
+ 'litleTxnId'=>'12345678000',
86
+ 'amount'=>'106',
87
+ 'payPalNotes'=>'Notes'
88
+ }
89
+
90
+ registerTokenHash = {
91
+ 'merchantId' => '101',
92
+ 'version'=>'8.8',
93
+ 'reportGroup'=>'Planets',
94
+ 'orderId'=>'12344',
95
+ 'accountNumber'=>'1233456789103801'
96
+ }
97
+
98
+ updateCardHash = {
99
+ 'merchantId' => '101',
100
+ 'version'=>'8.8',
101
+ 'reportGroup'=>'Planets',
102
+ 'id'=>'12345',
103
+ 'customerId'=>'0987',
104
+ 'orderId'=>'12344',
105
+ 'litleToken'=>'1233456789103801',
106
+ 'cardValidationNum'=>'123'
107
+ }
108
+
109
+ forceCaptHash = {
110
+ 'merchantId' => '101',
111
+ 'version'=>'8.8',
112
+ 'reportGroup'=>'Planets',
113
+ 'litleTxnId'=>'123456',
114
+ 'orderId'=>'12344',
115
+ 'amount'=>'106',
116
+ 'orderSource'=>'ecommerce',
117
+ 'card'=>{
118
+ 'type'=>'VI',
119
+ 'number' =>'4100000000000001',
120
+ 'expDate' =>'1210'
121
+ }}
122
+
123
+ captHash = {
124
+ 'merchantId' => '101',
125
+ 'version'=>'8.8',
126
+ 'reportGroup'=>'Planets',
127
+ 'litleTxnId'=>'123456000',
128
+ 'amount'=>'106',
129
+ }
130
+
131
+ captGivenAuthHash = {
132
+ 'merchantId' => '101',
133
+ 'version'=>'8.8',
134
+ 'reportGroup'=>'Planets',
135
+ 'orderId'=>'12344',
136
+ 'amount'=>'106',
137
+ 'authInformation' => {
138
+ 'authDate'=>'2002-10-09','authCode'=>'543216',
139
+ 'authAmount'=>'12345'
140
+ },
141
+ 'orderSource'=>'ecommerce',
142
+ 'card'=>{
143
+ 'type'=>'VI',
144
+ 'number' =>'4100000000000000',
145
+ 'expDate' =>'1210'
146
+ }}
147
+
148
+ echeckVerificationHash = {
149
+ 'merchantId' => '101',
150
+ 'version'=>'8.8',
151
+ 'reportGroup'=>'Planets',
152
+ 'amount'=>'123456',
153
+ 'orderId'=>'12345',
154
+ 'orderSource'=>'ecommerce',
155
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
156
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
157
+ }
158
+
159
+ echeckCreditHash = {
160
+ 'merchantId' => '101',
161
+ 'version'=>'8.8',
162
+ 'reportGroup'=>'Planets',
163
+ 'litleTxnId'=>'123456789101112',
164
+ 'amount'=>'12'
165
+ }
166
+
167
+ echeckRedeopsitHash = {
168
+ 'merchantId' => '101',
169
+ 'version'=>'8.8',
170
+ 'reportGroup'=>'Planets',
171
+ 'litleTxnId'=>'123456'
172
+ }
173
+
174
+ echeckSaleHash = {
175
+ 'merchantId' => '101',
176
+ 'version'=>'8.8',
177
+ 'reportGroup'=>'Planets',
178
+ 'amount'=>'123456',
179
+ 'verify'=>'true',
180
+ 'orderId'=>'12345',
181
+ 'orderSource'=>'ecommerce',
182
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
183
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
184
+ }
185
+
186
+ accountUpdateHash = {
187
+ 'reportGroup'=>'Planets',
188
+ 'id'=>'12345',
189
+ 'customerId'=>'0987',
190
+ 'orderId'=>'1234',
191
+ 'card'=>{
192
+ 'type'=>'VI',
193
+ 'number' =>'4100000000000001',
194
+ 'expDate' =>'1210'
195
+ }}
196
+
197
+ path = "/tmp/litle-sdk-for-ruby/cert/"
198
+
199
+ request = LitleRequest.new({'sessionId'=>'8675309'})
200
+
201
+ request.create_new_litle_request(path)
202
+ batch = LitleBatchRequest.new
203
+ batch.create_new_batch(path)
204
+
205
+ batch.account_update(accountUpdateHash)
206
+ batch.auth_reversal(authReversalHash)
207
+ batch.authorization(authHash)
208
+ batch.capture(captHash)
209
+ batch.capture_given_auth(captGivenAuthHash)
210
+ batch.credit(creditHash)
211
+ batch.echeck_credit(echeckCreditHash)
212
+ batch.echeck_redeposit(echeckRedeopsitHash)
213
+ batch.echeck_sale(echeckSaleHash)
214
+ batch.echeck_verification(echeckVerificationHash)
215
+ batch.force_capture(forceCaptHash)
216
+ batch.register_token_request(registerTokenHash)
217
+ batch.sale(saleHash)
218
+ batch.update_card_validation_num_on_token(updateCardHash)
219
+
220
+ #close the batch, indicating we plan to add no more transactions
221
+ batch.close_batch()
222
+ #add the batch to the LitleRequest
223
+ request.commit_batch(batch)
224
+ #finish the Litle Request, indicating we plan to add no more batches
225
+ request.finish_request
226
+
227
+ #send the batch files at the given directory over sFTP
228
+ request.send_to_litle
229
+
230
+ #grab the expected number of responses from the sFTP server and save them to the given path
231
+ request.get_responses_from_server()
232
+
233
+ count = 0
234
+ #process the responses from the server with a listener which applies the given block
235
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction|
236
+ assert_not_nil transaction["litleTxnId"] =~ /\d+/
237
+ assert_not_nil transaction["response"] =~ /\d+/
238
+ assert_not_nil transaction["message"]
239
+ count+=1
240
+ end})
241
+ assert_equal count, 14
242
+ end
243
+
244
+ def test_mini_batch_borked_counts
245
+ echeckSaleHash = {
246
+ 'merchantId' => '101',
247
+ 'version'=>'8.8',
248
+ 'reportGroup'=>'Planets',
249
+ 'amount'=>'123456',
250
+ 'verify'=>'true',
251
+ 'orderId'=>'12345',
252
+ 'orderSource'=>'ecommerce',
253
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
254
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
255
+ }
256
+
257
+ path = "/tmp/litle-sdk-for-ruby/cert/"
258
+
259
+ request = LitleRequest.new({'sessionId'=>'8675309'})
260
+
261
+ request.create_new_litle_request(path)
262
+ batch = LitleBatchRequest.new
263
+ batch.create_new_batch(path)
264
+
265
+ batch.echeck_sale(echeckSaleHash)
266
+
267
+ #make this a bad batch
268
+ batch.get_counts_and_amounts[:sale][:numSales] += 1
269
+ #close the batch, indicating we plan to add no more transactions
270
+ batch.close_batch()
271
+ #add the batch to the LitleRequest
272
+ request.commit_batch(batch)
273
+
274
+ #finish the Litle Request, indicating we plan to add no more batches
275
+ request.finish_request
276
+
277
+ #send the batch files at the given directory over sFTP
278
+ request.send_to_litle
279
+
280
+ #grab the expected number of responses from the sFTP server and save them to the given path
281
+ request.get_responses_from_server()
282
+
283
+ assert_raise RuntimeError do
284
+ #process the responses from the server with a listener which applies the given block
285
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction|
286
+ end})
287
+ end
288
+ end
289
+
290
+ def test_mini_batch_borked_amounts
291
+ echeckSaleHash = {
292
+ 'merchantId' => '101',
293
+ 'version'=>'8.8',
294
+ 'reportGroup'=>'Planets',
295
+ 'amount'=>'123456',
296
+ 'verify'=>'true',
297
+ 'orderId'=>'12345',
298
+ 'orderSource'=>'ecommerce',
299
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
300
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
301
+ }
302
+
303
+ path = "/tmp/litle-sdk-for-ruby/cert/"
304
+
305
+ request = LitleRequest.new({'sessionId'=>'8675309'})
306
+
307
+ request.create_new_litle_request(path)
308
+ batch = LitleBatchRequest.new
309
+ batch.create_new_batch(path)
310
+
311
+ batch.echeck_sale(echeckSaleHash)
312
+
313
+ #make this a bad batch
314
+ batch.get_counts_and_amounts[:sale][:saleAmount] += 1
315
+ #close the batch, indicating we plan to add no more transactions
316
+ batch.close_batch()
317
+ #add the batch to the LitleRequest
318
+ request.commit_batch(batch)
319
+
320
+ #finish the Litle Request, indicating we plan to add no more batches
321
+ request.finish_request
322
+
323
+ #send the batch files at the given directory over sFTP
324
+ request.send_to_litle
325
+
326
+ #grab the expected number of responses from the sFTP server and save them to the given path
327
+ request.get_responses_from_server()
328
+
329
+ # we are checking the litleResponse header for a filed response code and raising it as an error
330
+ assert_raise RuntimeError do
331
+ #process the responses from the server with a listener which applies the given block
332
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction|
333
+ end})
334
+ end
335
+ end
336
+ end
337
+ end
@@ -22,6 +22,8 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
22
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
23
  OTHER DEALINGS IN THE SOFTWARE.
24
24
  =end
25
+ require 'lib/LitleOnline'
26
+
25
27
 
26
28
  #test driver for running all tests
27
29
  require_relative 'certTest1_base'
@@ -0,0 +1,164 @@
1
+ =begin
2
+ Copyright (c) 2012 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 'lib/LitleOnline'
26
+ require 'test/unit'
27
+ require 'fileutils'
28
+
29
+ #test Authorization Transaction
30
+ module LitleOnline
31
+ class TestBatch < Test::Unit::TestCase
32
+
33
+ def setup
34
+ dir = '/tmp/litle-sdk-for-ruby-test'
35
+ FileUtils.rm_rf dir
36
+ Dir.mkdir dir
37
+ end
38
+
39
+ def test_batch_file_creation
40
+ dir = '/tmp'
41
+
42
+ batch = LitleBatchRequest.new
43
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
44
+
45
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
46
+
47
+ assert_equal entries.length, 4
48
+ entries.sort!
49
+ assert_not_nil entries[2] =~ /batch_\d+\z/
50
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
51
+ end
52
+
53
+ def test_batch_file_creation_account_update
54
+ dir = '/tmp'
55
+
56
+ batch = LitleBatchRequest.new
57
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
58
+
59
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
60
+
61
+ assert_equal entries.length, 4
62
+ entries.sort!
63
+ assert_not_nil entries[2] =~ /batch_\d+\z/
64
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
65
+
66
+ accountUpdateHash = {
67
+ 'reportGroup'=>'Planets',
68
+ 'id'=>'12345',
69
+ 'customerId'=>'0987',
70
+ 'card'=>{
71
+ 'type'=>'VI',
72
+ 'number' =>'4100000000000001',
73
+ 'expDate' =>'1210'
74
+ }}
75
+ batch.account_update(accountUpdateHash)
76
+
77
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
78
+ assert_equal entries.length, 6
79
+ entries.sort!
80
+ assert_not_nil entries[2] =~ /batch_\d+\z/
81
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
82
+ assert_not_nil entries[4] =~ /batch_\d+\z/
83
+ assert_not_nil entries[5] =~ /batch_\d+_txns\z/
84
+ end
85
+
86
+ def test_batch_file_creation_on_file
87
+ dir = '/tmp'
88
+
89
+ File.open(dir + '/litle-sdk-for-ruby-test/test_batch_file_creation_on_file', 'a+') do |file|
90
+ file.puts("")
91
+ end
92
+
93
+ assert_raise ArgumentError do
94
+ batch = LitleBatchRequest.new
95
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test/test_batch_file_creation_on_file')
96
+ end
97
+ end
98
+
99
+ def test_batch_file_rename_and_remove
100
+ dir = '/tmp'
101
+
102
+ batch = LitleBatchRequest.new
103
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
104
+ assert_equal Dir.entries(dir+'/litle-sdk-for-ruby-test').size, 4
105
+ batch.close_batch
106
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
107
+ assert_equal entries.size, 3
108
+ entries.sort!
109
+ assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
110
+ end
111
+
112
+ def test_batch_file_create_new_dir
113
+ dir = '/tmp'
114
+ batch = LitleBatchRequest.new
115
+ assert !File.directory?(dir + '/litle-sdk-for-ruby-test/test_batch_file_create_new_dir')
116
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test/test_batch_file_create_new_dir')
117
+ assert File.directory?(dir + '/litle-sdk-for-ruby-test/test_batch_file_create_new_dir')
118
+ end
119
+
120
+ def test_batch_open_existing
121
+ dir = '/tmp'
122
+ batch = LitleBatchRequest.new
123
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
124
+
125
+ hash = {
126
+ 'merchantId' => '101',
127
+ 'version'=>'8.8',
128
+ 'reportGroup'=>'Planets',
129
+ 'litleTxnId'=>'123456',
130
+ 'orderId'=>'12344',
131
+ 'amount'=>'106',
132
+ 'orderSource'=>'ecommerce',
133
+ 'card'=>{
134
+ 'type'=>'VI',
135
+ 'number' =>'4100000000000002',
136
+ 'expDate' =>'1210'
137
+ }}
138
+
139
+ batch.sale(hash)
140
+
141
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
142
+ entries.sort!
143
+
144
+ batch2 = LitleBatchRequest.new
145
+ batch2.open_existing_batch(dir + '/litle-sdk-for-ruby-test/' + entries[2])
146
+ assert_equal batch.get_counts_and_amounts, batch2.get_counts_and_amounts
147
+ end
148
+
149
+ def test_batch_open_existing_closed
150
+ dir = '/tmp'
151
+ batch = LitleBatchRequest.new
152
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
153
+ batch.close_batch
154
+
155
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
156
+ entries.sort!
157
+
158
+ batch2 = LitleBatchRequest.new
159
+ assert_raise ArgumentError do
160
+ batch2.open_existing_batch(dir + '/litle-sdk-for-ruby-test/' + entries[2])
161
+ end
162
+ end
163
+ end
164
+ end