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
@@ -25,11 +25,11 @@ OTHER DEALINGS IN THE SOFTWARE.
25
25
  require 'lib/LitleOnline'
26
26
  require 'lib/LitleOnlineRequest'
27
27
  require 'test/unit'
28
- require 'mocha'
28
+ require 'mocha/setup'
29
29
 
30
30
  module LitleOnline
31
31
 
32
- class Newtest < Test::Unit::TestCase
32
+ class TestLitleOnlineRequest < Test::Unit::TestCase
33
33
  def test_set_merchant_id
34
34
  Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}})
35
35
  litle = LitleOnlineRequest.new
@@ -118,7 +118,7 @@ module LitleOnline
118
118
 
119
119
  def test_sale_card_field
120
120
  Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
121
- hash={
121
+ hash = {
122
122
  'reportGroup'=>'Planets',
123
123
  'id' => '006',
124
124
  'orderId'=>'12344',
@@ -141,12 +141,12 @@ module LitleOnline
141
141
  hash={
142
142
  'id' => '006',
143
143
  'reportGroup'=>'Planets',
144
- 'litleTxnId'=>'123456789012345678',
144
+ 'litleTxnId'=>'123456789012345678'
145
145
  }
146
-
146
+
147
147
  Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
148
148
  XMLObject.expects(:new)
149
-
149
+
150
150
  response = LitleOnlineRequest.new.capture(hash)
151
151
  end
152
152
 
@@ -157,7 +157,7 @@ module LitleOnline
157
157
  'orderId'=>'12344',
158
158
  'reportGroup'=>'Planets',
159
159
  'orderSource'=>'ecommerce',
160
- 'litleTxnId'=>'123456789012345678',
160
+ 'litleTxnId'=>'123456789012345678'
161
161
  }
162
162
 
163
163
  Communications.expects(:http_post).with(Not(regexp_matches(/.*amount.*/m)),kind_of(Hash))
@@ -244,7 +244,7 @@ module LitleOnline
244
244
  #Explicit - used for integrations
245
245
  assert_equal 'ActiveMerchant;3.2', litle.send(:get_merchant_sdk, {'merchantSdk'=>'ActiveMerchant;3.2'})
246
246
  #Implicit - used raw when nothing is specified
247
- assert_equal 'Ruby;8.16.0', litle.send(:get_merchant_sdk, {'NotMerchantSdk'=>'ActiveMerchant;3.2'})
247
+ assert_equal 'Ruby;8.17.0', litle.send(:get_merchant_sdk, {'NotMerchantSdk'=>'ActiveMerchant;3.2'})
248
248
  end
249
249
 
250
250
  def test_sale_paypal_order_complete_typo
@@ -274,7 +274,7 @@ module LitleOnline
274
274
  'litleTxnId' => '006'
275
275
  }
276
276
 
277
- Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest.*version="8\.16".*/m),kind_of(Hash))
277
+ Communications.expects(:http_post).with(regexp_matches(/<litleOnlineRequest.*version="8\.17".*/m),kind_of(Hash))
278
278
  XMLObject.expects(:new)
279
279
 
280
280
  response = LitleOnlineRequest.new.void(hash)
@@ -292,53 +292,5 @@ module LitleOnline
292
292
  assert_equal '65', response.voidResponse.recycling.creditLitleTxnId
293
293
  end
294
294
 
295
- def test_printxml_can_be_turned_on_by_setting_value_to_true
296
- Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10','printxml'=>true})
297
- Communications.expects(:http_post).with(kind_of(String),kind_of(Hash)).returns('<litleOnlineResponse><voidResponse><recycling><creditLitleTxnId>65</creditLitleTxnId></recycling></voidResponse></litleOnlineResponse>')
298
- Logger.any_instance.expects(:debug).with(kind_of(String)).twice
299
- hash={
300
- 'litleTxnId' => '123'
301
- }
302
-
303
- response = LitleOnlineRequest.new.void(hash)
304
- logger = Logger.new(STDOUT)
305
- logger.level = Logger::DEBUG
306
- assert_equal logger.level, Configuration.logger.level
307
- assert_equal logger.sev_threshold, Configuration.logger.sev_threshold
308
- LitleOnline::Configuration.logger = nil
309
- end
310
-
311
- def test_printxml_can_be_turned_off_by_setting_value_to_false
312
- Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10','printxml'=>false})
313
- Communications.expects(:http_post).with(kind_of(String),kind_of(Hash)).returns('<litleOnlineResponse><voidResponse><recycling><creditLitleTxnId>65</creditLitleTxnId></recycling></voidResponse></litleOnlineResponse>')
314
- Logger.any_instance.expects(:debug).with(kind_of(String)).twice
315
- hash={
316
- 'litleTxnId' => '123'
317
- }
318
-
319
- response = LitleOnlineRequest.new.void(hash)
320
- logger = Logger.new(STDOUT)
321
- logger.level = Logger::INFO
322
- assert_equal logger.level, Configuration.logger.level
323
- assert_equal logger.sev_threshold, Configuration.logger.sev_threshold
324
- LitleOnline::Configuration.logger = nil
325
- end
326
-
327
- def test_printxml_can_be_turned_off_by_not_setting_value
328
- Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
329
- Communications.expects(:http_post).with(kind_of(String),kind_of(Hash)).returns('<litleOnlineResponse><voidResponse><recycling><creditLitleTxnId>65</creditLitleTxnId></recycling></voidResponse></litleOnlineResponse>')
330
- Logger.any_instance.expects(:debug).with(kind_of(String)).twice
331
- hash={
332
- 'litleTxnId' => '123'
333
- }
334
-
335
- response = LitleOnlineRequest.new.void(hash)
336
- logger = Logger.new(STDOUT)
337
- logger.level = Logger::INFO
338
- assert_equal logger.level, Configuration.logger.level
339
- assert_equal logger.sev_threshold, Configuration.logger.sev_threshold
340
- LitleOnline::Configuration.logger = nil
341
- end
342
-
343
295
  end
344
296
  end
@@ -0,0 +1,320 @@
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 'lib/LitleOnline'
26
+ require 'lib/LitleOnlineRequest'
27
+ require 'lib/LitleRequest'
28
+ require 'lib/LitleBatchRequest'
29
+ require 'lib/LitleListeners'
30
+ require 'test/unit'
31
+ require 'mocha/setup'
32
+
33
+ module LitleOnline
34
+
35
+ class TestLitleRequest < Test::Unit::TestCase
36
+
37
+ def test_create_with_file
38
+ request = LitleRequest.new({'sessionId'=>'8675309',
39
+ 'user'=>'john',
40
+ 'password'=>'tinkleberry'})
41
+ message = ""
42
+ File.expects(:file?).with('/durrrrrr').returns(true).once
43
+ request.create_new_litle_request('/durrrrrr')
44
+
45
+ rescue RuntimeError=> e
46
+ message = e.message
47
+
48
+ assert_equal message, "Entered a file not a path."
49
+ end
50
+
51
+ def test_create_with_no_sep
52
+ request = LitleRequest.new({'sessionId'=>'8675309',
53
+ 'user'=>'john',
54
+ 'password'=>'tinkleberry'})
55
+ File.expects(:open).twice
56
+ request.create_new_litle_request('/usr/local')
57
+ assert request.get_path_to_batches.include?('/usr/local/')
58
+ end
59
+
60
+ def test_create_name_collision
61
+ request = LitleRequest.new({'sessionId'=>'8675309',
62
+ 'user'=>'john',
63
+ 'password'=>'tinkleberry'})
64
+
65
+ create_new = sequence('create_new')
66
+ File.expects(:file?).returns(false).in_sequence(create_new)
67
+ File.expects(:file?).returns(true).once.in_sequence(create_new) #yayay short circuiting
68
+ File.expects(:file?).returns(false).once.in_sequence(create_new)
69
+ File.expects(:file?).returns(false).twice.in_sequence(create_new) #or's don't quit
70
+ File.expects(:open).twice.in_sequence(create_new)
71
+
72
+ request.create_new_litle_request('/usr/local')
73
+ end
74
+
75
+ def test_create_normal
76
+ request = LitleRequest.new({'sessionId'=>'8675309',
77
+ 'user'=>'john',
78
+ 'password'=>'tinkleberry'})
79
+
80
+ create_new = sequence('create_new')
81
+ File.expects(:file?).returns(false).once.in_sequence(create_new)
82
+ File.expects(:file?).returns(false).twice.in_sequence(create_new)
83
+ File.expects(:open).once.in_sequence(create_new)
84
+ File.expects(:open).once.in_sequence(create_new)
85
+
86
+ request.create_new_litle_request('/usr/local')
87
+ end
88
+
89
+ def test_add_rfr_request_litle_session
90
+ add_rfr = sequence('add_rfr')
91
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1).in_sequence(add_rfr)
92
+
93
+ File.expects(:file?).with('/usr/srv').returns(false).in_sequence(add_rfr)
94
+ File.expects(:directory?).with('/usr/srv/').returns(true).in_sequence(add_rfr)
95
+ File.expects(:open).with(regexp_matches(/request_\d+\z/), 'a+').in_sequence(add_rfr)
96
+ File.expects(:rename).with(regexp_matches(/request_\d+\z/), regexp_matches(/request_\d+.complete\z/)).in_sequence(add_rfr)
97
+
98
+ request = LitleRequest.new({'sessionId'=>'8675309',
99
+ 'user'=>'john',
100
+ 'password'=>'tinkleberry'})
101
+ request.add_rfr_request({'litleSessionId' => '137813712'}, '/usr/srv')
102
+ end
103
+
104
+ def test_commit_batch_with_batch
105
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
106
+
107
+ request = LitleRequest.new({'sessionId'=>'8675309',
108
+ 'user'=>'john',
109
+ 'password'=>'tinkleberry'})
110
+ File.expects(:file?).returns(false).once
111
+ File.expects(:file?).returns(false).twice #or's don't quit
112
+ File.expects(:open).twice
113
+ File.expects(:directory?).returns(true).once
114
+ request.create_new_litle_request("/usr/srv/batches")
115
+
116
+ batch = LitleBatchRequest.new
117
+ File.expects(:open).twice
118
+ File.expects(:file?).returns(false).twice
119
+ File.expects(:directory?).returns(true).once
120
+ batch.create_new_batch('/usr/srv/batches')
121
+ File.expects(:rename).once
122
+ File.expects(:open).once
123
+ File.expects(:delete).once
124
+ batch.close_batch()
125
+
126
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
127
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
128
+ request.commit_batch(batch)
129
+ end
130
+
131
+ def test_commit_batch_with_path
132
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
133
+
134
+ request = LitleRequest.new({'sessionId'=>'8675309',
135
+ 'user'=>'john',
136
+ 'password'=>'tinkleberry'})
137
+ File.expects(:file?).returns(false).once
138
+ File.expects(:file?).returns(false).twice #or's don't quit
139
+ File.expects(:open).twice
140
+ File.expects(:directory?).returns(true).once
141
+ request.create_new_litle_request("/usr/srv/batches")
142
+
143
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
144
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
145
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
146
+ end
147
+
148
+ def test_add_bad_object
149
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
150
+ request = LitleRequest.new({})
151
+ request.commit_batch({:apple => "pear"})
152
+ test = ""
153
+ rescue RuntimeError => e
154
+ test = e.message
155
+ assert_equal test, "You entered neither a path nor a batch. Game over :("
156
+ end
157
+
158
+ def test_add_open_batch
159
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
160
+ File.expects(:open).with(regexp_matches(/\/usr\/srv\/.*/), 'a+').times(2)
161
+
162
+ Dir.expects(:mkdir).with('/usr/srv/batches/').once
163
+ batch = LitleBatchRequest.new
164
+ batch.create_new_batch('/usr/srv/batches')
165
+ request = LitleRequest.new({'sessionId'=>'8675309',
166
+ 'user'=>'john',
167
+ 'password'=>'tinkleberry'})
168
+
169
+ close_and_add = sequence('close_and_add')
170
+ batch.expects(:get_batch_name).returns("/usr/srv/batches/batch_123123131231").once.in_sequence(close_and_add)
171
+ batch.expects(:close_batch).once.in_sequence(close_and_add)
172
+ batch.expects(:get_batch_name).returns(str = "/usr/srv/batches/batch_123123131231.closed-1000").once.in_sequence(close_and_add)
173
+ str.expects(:index).returns(7).once.in_sequence(close_and_add)
174
+ File.expects(:open).once.in_sequence(close_and_add)
175
+ File.expects(:delete).once.in_sequence(close_and_add)
176
+ request.commit_batch(batch)
177
+ end
178
+
179
+ def test_batch_too_big
180
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
181
+
182
+ request = LitleRequest.new({'sessionId'=>'8675309',
183
+ 'user'=>'john',
184
+ 'password'=>'tinkleberry'})
185
+ File.expects(:file?).returns(false).once
186
+ File.expects(:file?).returns(false).twice #or's don't quit
187
+ File.expects(:open).twice
188
+ File.expects(:directory?).returns(true).once
189
+ request.create_new_litle_request("/usr/srv/batches")
190
+ create_new = sequence('create_new')
191
+
192
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+').times(5)
193
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/)).times(5)
194
+ 5.times {
195
+
196
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
197
+ }
198
+
199
+ request.expects(:finish_request).once
200
+ request.expects(:initialize).once
201
+ request.expects(:create_new_litle_request).once
202
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
203
+ end
204
+
205
+ #TODO: see of we can get deeper with mocking the node returned
206
+ def test_process_response_success
207
+ xml = sequence("xml")
208
+ LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new).in_sequence(xml)
209
+ reader.expects(:read).once.in_sequence(xml)
210
+ reader.expects(:get_attribute).with('response').returns("0").in_sequence(xml)
211
+ reader.expects(:read).once.in_sequence(xml)
212
+ reader.expects(:node).returns(node = LibXML::XML::Node.new("litleResponse")).twice.in_sequence(xml)
213
+
214
+ request = LitleRequest.new({})
215
+ request.process_response(Dir.pwd + '/responses/good_xml.xml' ,
216
+ DefaultLitleListener.new{|txn| puts txn["type"]} ,
217
+ DefaultLitleListener.new{|batch| } )
218
+ end
219
+
220
+ def test_process_response_xml_error
221
+ LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new)
222
+ reader.expects(:read).once
223
+ reader.expects(:get_attribute).with('response').twice.returns(4)
224
+ reader.expects(:get_attribute).with("message").returns("Error validating xml data against the schema")
225
+
226
+ request = LitleRequest.new({})
227
+ response = ''
228
+ begin
229
+ request.process_response(Dir.pwd + '/responses/bad_xml.xml' ,
230
+ DefaultLitleListener.new{|txn| puts txn["type"]} ,
231
+ DefaultLitleListener.new{|batch| } )
232
+ rescue Exception => e
233
+ response = e.message
234
+ end
235
+ assert_equal "Error parsing Litle Request: Error validating xml data against the schema", response.to_s
236
+ end
237
+
238
+ def test_process_responses
239
+ request = LitleRequest.new({})
240
+ listener = DefaultLitleListener.new
241
+ args = {:transaction_listener=>listener,:path_to_responses=>"fake/path/"}
242
+ args.expects(:[]).with(:transaction_listener)
243
+ args.expects(:[]).with(:batch_listener).returns(nil)
244
+ args.expects(:[]).with(:path_to_responses).returns("fake/path/")
245
+ Dir.expects(:foreach).with("fake/path/")
246
+
247
+ request.process_responses(args)
248
+ end
249
+
250
+ def test_get_responses_from_server
251
+ request = LitleRequest.new({})
252
+ resp_seq = sequence("resp_seq")
253
+ args = {:responses_expected=>4, :response_path=>"new/path", :sftp_username=>"periwinkle",:sftp_password=>"password", :sftp_url=>"reddit.com"}
254
+
255
+ File.expects(:directory?).with("new/path/").returns(false).once.in_sequence(resp_seq)
256
+ Dir.expects(:mkdir).with("new/path/").once.in_sequence(resp_seq)
257
+ Net::SFTP.expects(:start).twice.with("reddit.com", "periwinkle", :password=>"password")
258
+
259
+ request.get_responses_from_server(args)
260
+ end
261
+
262
+ def test_send_over_stream
263
+ request = LitleRequest.new({})
264
+ req_seq = sequence('request')
265
+
266
+ File.expects(:directory?).with(regexp_matches(/responses\//)).once.returns(false).in_sequence(req_seq)
267
+ Dir.expects(:mkdir).with(regexp_matches(/responses\//)).once.in_sequence(req_seq)
268
+ Dir.expects(:foreach).once.in_sequence(req_seq)
269
+
270
+ request.send_to_litle_stream({:fast_url=>"www.redit.com", :fast_port=>"2313"})
271
+ end
272
+
273
+ def test_send_over_stream_bad_crds
274
+ request = LitleRequest.new({})
275
+
276
+ assert_raise ArgumentError do
277
+ request.send_to_litle_stream({:fast_url=>"", :fast_port=>""})
278
+ end
279
+ end
280
+ #Outputs an example LitleRequest doc in the current directory
281
+ # def test_finish_request_xml! #that's why the name has a bang
282
+ # # see the bang up there ^^^ that means we ACTUALLY edit the file system
283
+ # # make sure to clear this; otherwise, you're gonna have a bad time.
284
+ # path = Dir.pwd
285
+ #
286
+ # saleHash = {
287
+ # 'reportGroup'=>'Planets',
288
+ # 'id' => '006',
289
+ # 'orderId'=>'12344',
290
+ # 'amount'=>'6000',
291
+ # 'orderSource'=>'ecommerce',
292
+ # 'card'=>{
293
+ # 'type'=>'VI',
294
+ # 'number' =>'4100000000000001',
295
+ # 'expDate' =>'1210'
296
+ # }}
297
+ #
298
+ # request = LitleRequest.new({'sessionId'=>'8675309',
299
+ # 'user'=>'john',
300
+ # 'password'=>'tinkleberry'})
301
+ # request.create_new_litle_request(path)
302
+ #
303
+ #
304
+ # #5.times{
305
+ # batch = LitleBatchRequest.new
306
+ # batch.create_new_batch(path)
307
+ # puts "Batch is at: " + batch.get_batch_name
308
+ #
309
+ # #10.times{
310
+ # batch.sale(saleHash)
311
+ # #batch.update_card_validation_num_on_token(options)
312
+ # #}
313
+ #
314
+ # batch.close_batch()
315
+ # request.commit_batch(batch)
316
+ # #}
317
+ # request.finish_request
318
+ # end
319
+ end
320
+ end
@@ -0,0 +1,398 @@
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 'lib/LitleOnline'
26
+ require 'lib/LitleOnlineRequest'
27
+ require 'lib/LitleBatchRequest'
28
+ require 'test/unit'
29
+ require 'mocha/setup'
30
+
31
+ module LitleOnline
32
+
33
+ class TestLitleTransaction < Test::Unit::TestCase
34
+ def test_authorization
35
+ ltlTxn = LitleTransaction.new
36
+ authHash = {
37
+ 'reportGroup'=>'Planets',
38
+ 'id'=>'12345',
39
+ 'customerId'=>'0987',
40
+ 'orderId'=>'12344',
41
+ 'amount'=>'106',
42
+ 'orderSource'=>'ecommerce',
43
+ 'card'=>{
44
+ 'type'=>'VI',
45
+ 'number' =>'4100000000000001',
46
+ 'expDate' =>'1210'
47
+ }}
48
+
49
+ result = ltlTxn.authorization(authHash)
50
+ assert_equal 'Planets', result.reportGroup
51
+ assert_equal '12345', result.transactionId
52
+ assert_equal '0987', result.customerId
53
+ assert_equal "12344", result.orderId
54
+ assert_equal "106", result.amount
55
+ assert_equal "ecommerce", result.orderSource
56
+ assert_equal "4100000000000001", result.card.number
57
+ assert_equal "VI", result.card.mop
58
+ assert_equal "1210", result.card.expDate
59
+ end
60
+
61
+ def test_sale
62
+ ltlTxn = LitleTransaction.new
63
+ saleHash = {
64
+ 'reportGroup'=>'Planets',
65
+ 'id'=>'12345',
66
+ 'customerId'=>'0987',
67
+ 'orderId'=>'12344',
68
+ 'amount'=>'6000',
69
+ 'orderSource'=>'ecommerce',
70
+ 'card'=>{
71
+ 'type'=>'VI',
72
+ 'number' =>'4100000000000001',
73
+ 'expDate' =>'1210'
74
+ }}
75
+
76
+ result = ltlTxn.sale(saleHash)
77
+ assert_equal 'Planets', result.reportGroup
78
+ assert_equal '12345', result.transactionId
79
+ assert_equal '0987', result.customerId
80
+ assert_equal "12344", result.orderId
81
+ assert_equal "6000", result.amount
82
+ assert_equal "ecommerce", result.orderSource
83
+ assert_equal "4100000000000001", result.card.number
84
+ assert_equal "VI", result.card.mop
85
+ assert_equal "1210", result.card.expDate
86
+ end
87
+
88
+ def test_credit
89
+ ltlTxn = LitleTransaction.new
90
+ creditHash = {
91
+ 'merchantId' => '101',
92
+ 'version'=>'8.8',
93
+ 'reportGroup'=>'Planets',
94
+ 'id'=>'12345',
95
+ 'customerId'=>'0987',
96
+ 'orderId'=>'12344',
97
+ 'amount'=>'106',
98
+ 'orderSource'=>'ecommerce',
99
+ 'card'=>{
100
+ 'type'=>'VI',
101
+ 'number' =>'4100000000000001',
102
+ 'expDate' =>'1210'
103
+ }}
104
+
105
+ result = ltlTxn.credit(creditHash)
106
+ assert_equal 'Planets', result.reportGroup
107
+ assert_equal '12345', result.transactionId
108
+ assert_equal '0987', result.customerId
109
+ assert_equal '12344', result.orderId
110
+ assert_equal '106', result.amount
111
+ assert_equal 'ecommerce', result.orderSource
112
+ assert_equal '4100000000000001', result.card.number
113
+ assert_equal 'VI', result.card.mop
114
+ assert_equal '1210', result.card.expDate
115
+ end
116
+
117
+ def test_auth_reversal
118
+ ltlTxn = LitleTransaction.new
119
+ authReversalHash = {
120
+ 'merchantId' => '101',
121
+ 'version'=>'8.8',
122
+ 'reportGroup'=>'Planets',
123
+ 'id'=>'12345',
124
+ 'customerId'=>'0987',
125
+ 'litleTxnId'=>'12345678000',
126
+ 'amount'=>'106',
127
+ 'payPalNotes'=>'Notes'
128
+ }
129
+
130
+ result = ltlTxn.auth_reversal(authReversalHash)
131
+ assert_equal 'Planets', result.reportGroup
132
+ assert_equal '12345', result.transactionId
133
+ assert_equal '0987', result.customerId
134
+ assert_equal '12345678000', result.litleTxnId
135
+ assert_equal '106', result.amount
136
+ assert_equal 'Notes', result.payPalNotes
137
+ end
138
+
139
+ def test_register_token_request
140
+ ltlTxn = LitleTransaction.new
141
+ registerTokenHash = {
142
+ 'merchantId' => '101',
143
+ 'version'=>'8.8',
144
+ 'reportGroup'=>'Planets',
145
+ 'id'=>'12345',
146
+ 'customerId'=>'0987',
147
+ 'orderId'=>'12344',
148
+ 'accountNumber'=>'1233456789103801'
149
+ }
150
+
151
+ result = ltlTxn.register_token_request(registerTokenHash)
152
+ assert_equal 'Planets', result.reportGroup
153
+ assert_equal '12345', result.transactionId
154
+ assert_equal '0987', result.customerId
155
+ assert_equal '12344', result.orderId
156
+ assert_equal '1233456789103801', result.accountNumber
157
+ end
158
+
159
+ def test_update_card_validation_num_on_token
160
+ ltlTxn = LitleTransaction.new
161
+ updateCardHash = {
162
+ 'merchantId' => '101',
163
+ 'version'=>'8.8',
164
+ 'reportGroup'=>'Planets',
165
+ 'id'=>'12345',
166
+ 'customerId'=>'0987',
167
+ 'orderId'=>'12344',
168
+ 'litleToken'=>'1233456789103801',
169
+ 'cardValidationNum'=>'123'
170
+ }
171
+
172
+ result = ltlTxn.update_card_validation_num_on_token(updateCardHash)
173
+ assert_equal 'Planets', result.reportGroup
174
+ assert_equal '12345', result.transactionId
175
+ assert_equal '0987', result.customerId
176
+ assert_equal '12344', result.orderId
177
+ assert_equal '1233456789103801', result.litleToken
178
+ assert_equal '123', result.cardValidationNum
179
+ end
180
+
181
+ def test_force_capture
182
+ ltlTxn = LitleTransaction.new
183
+ forceCaptHash = {
184
+ 'merchantId' => '101',
185
+ 'version'=>'8.8',
186
+ 'reportGroup'=>'Planets',
187
+ 'id'=>'12345',
188
+ 'customerId'=>'0987',
189
+ 'orderId'=>'12344',
190
+ 'amount'=>'106',
191
+ 'orderSource'=>'ecommerce',
192
+ 'card'=>{
193
+ 'type'=>'VI',
194
+ 'number' =>'4100000000000001',
195
+ 'expDate' =>'1210'
196
+ }}
197
+
198
+ result = ltlTxn.force_capture(forceCaptHash)
199
+ assert_equal 'Planets', result.reportGroup
200
+ assert_equal '12345', result.transactionId
201
+ assert_equal '0987', result.customerId
202
+ assert_equal '12344', result.orderId
203
+ assert_equal '106', result.amount
204
+ assert_equal 'ecommerce', result.orderSource
205
+ assert_equal 'VI', result.card.mop
206
+ assert_equal '4100000000000001', result.card.number
207
+ assert_equal '1210', result.card.expDate
208
+ end
209
+
210
+ def test_capture
211
+ ltlTxn = LitleTransaction.new
212
+ captHash = {
213
+ 'merchantId' => '101',
214
+ 'version'=>'8.8',
215
+ 'reportGroup'=>'Planets',
216
+ 'id'=>'12345',
217
+ 'customerId'=>'0987',
218
+ 'litleTxnId'=>'123456000',
219
+ 'amount'=>'106',
220
+ }
221
+
222
+ result = ltlTxn.capture(captHash)
223
+ assert_equal 'Planets', result.reportGroup
224
+ assert_equal '12345', result.transactionId
225
+ assert_equal '0987', result.customerId
226
+ assert_equal '123456000', result.litleTxnId
227
+ assert_equal '106', result.amount
228
+ end
229
+
230
+ def test_capture_given_auth
231
+ ltlTxn = LitleTransaction.new
232
+ captGivenAuthHash = {
233
+ 'merchantId' => '101',
234
+ 'version'=>'8.8',
235
+ 'reportGroup'=>'Planets',
236
+ 'id'=>'12345',
237
+ 'customerId'=>'0987',
238
+ 'orderId'=>'12344',
239
+ 'amount'=>'106',
240
+ 'authInformation' => {
241
+ 'authDate'=>'2002-10-09',
242
+ 'authCode'=>'543216',
243
+ 'authAmount'=>'12345'
244
+ },
245
+ 'orderSource'=>'ecommerce',
246
+ 'card'=>{
247
+ 'type'=>'VI',
248
+ 'number' =>'4100000000000000',
249
+ 'expDate' =>'1210'
250
+ }}
251
+
252
+ result = ltlTxn.capture_given_auth(captGivenAuthHash)
253
+ assert_equal 'Planets', result.reportGroup
254
+ assert_equal '12345', result.transactionId
255
+ assert_equal '0987', result.customerId
256
+ assert_equal '12344', result.orderId
257
+ assert_equal '106', result.amount
258
+ assert_equal 'ecommerce', result.orderSource
259
+ assert_equal 'VI', result.card.mop
260
+ assert_equal '4100000000000000', result.card.number
261
+ assert_equal '1210', result.card.expDate
262
+ assert_equal '2002-10-09', result.authInformation.authDate
263
+ assert_equal '543216', result.authInformation.authCode
264
+ assert_equal '12345', result.authInformation.authAmount
265
+ end
266
+
267
+ def test_echeck_verification
268
+ ltlTxn = LitleTransaction.new
269
+ echeckVerificationHash = {
270
+ 'merchantId' => '101',
271
+ 'version'=>'8.8',
272
+ 'reportGroup'=>'Planets',
273
+ 'id'=>'12345',
274
+ 'customerId'=>'0987',
275
+ 'amount'=>'123456',
276
+ 'orderId'=>'12345',
277
+ 'orderSource'=>'ecommerce',
278
+ 'echeck' => {'accType'=>'Checking',
279
+ 'accNum'=>'12345657890',
280
+ 'routingNum'=>'123456789',
281
+ 'checkNum'=>'123455'},
282
+ 'billToAddress'=>{'name'=>'Bob',
283
+ 'city'=>'lowell',
284
+ 'state'=>'MA',
285
+ 'email'=>'litle.com'}
286
+ }
287
+
288
+ result = ltlTxn.echeck_verification(echeckVerificationHash)
289
+ assert_equal 'Planets', result.reportGroup
290
+ assert_equal '12345', result.transactionId
291
+ assert_equal '0987', result.customerId
292
+ assert_equal '12345', result.orderId
293
+ assert_equal '123456', result.amount
294
+ assert_equal 'ecommerce', result.orderSource
295
+ assert_equal 'Checking', result.echeck.accType
296
+ assert_equal '12345657890', result.echeck.accNum
297
+ assert_equal '123456789', result.echeck.routingNum
298
+ assert_equal '123455', result.echeck.checkNum
299
+ assert_equal 'Bob', result.billToAddress.name
300
+ assert_equal 'lowell', result.billToAddress.city
301
+ assert_equal 'MA', result.billToAddress.state
302
+ assert_equal 'litle.com', result.billToAddress.email
303
+ end
304
+
305
+ def test_echeck_credit
306
+ ltlTxn = LitleTransaction.new
307
+ echeckCreditHash = {
308
+ 'merchantId' => '101',
309
+ 'version'=>'8.8',
310
+ 'reportGroup'=>'Planets',
311
+ 'id'=>'12345',
312
+ 'customerId'=>'0987',
313
+ 'litleTxnId'=>'123456789101112',
314
+ 'amount'=>'12'
315
+ }
316
+
317
+ result = ltlTxn.echeck_credit(echeckCreditHash)
318
+ assert_equal 'Planets', result.reportGroup
319
+ assert_equal '12345', result.transactionId
320
+ assert_equal '0987', result.customerId
321
+ assert_equal '123456789101112', result.litleTxnId
322
+ assert_equal '12', result.amount
323
+ end
324
+
325
+ def test_echeck_redeposit
326
+ ltlTxn = LitleTransaction.new
327
+ echeckRedeopsitHash = {
328
+ 'merchantId' => '101',
329
+ 'version'=>'8.8',
330
+ 'reportGroup'=>'Planets',
331
+ 'id'=>'12345',
332
+ 'customerId'=>'0987',
333
+ 'litleTxnId'=>'123456'
334
+ }
335
+
336
+ result = ltlTxn.echeck_redeposit(echeckRedeopsitHash)
337
+ assert_equal 'Planets', result.reportGroup
338
+ assert_equal '12345', result.transactionId
339
+ assert_equal '0987', result.customerId
340
+ assert_equal '123456', result.litleTxnId
341
+ end
342
+
343
+ def test_echeck_sale
344
+ ltlTxn = LitleTransaction.new
345
+ echeckSaleHash = {
346
+ 'merchantId' => '101',
347
+ 'version'=>'8.8',
348
+ 'reportGroup'=>'Planets',
349
+ 'id'=>'12345',
350
+ 'customerId'=>'0987',
351
+ 'amount'=>'123456',
352
+ 'verify'=>'true',
353
+ 'orderId'=>'12345',
354
+ 'orderSource'=>'ecommerce',
355
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
356
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
357
+ }
358
+
359
+ result = ltlTxn.echeck_sale(echeckSaleHash)
360
+ assert_equal 'Planets', result.reportGroup
361
+ assert_equal '12345', result.transactionId
362
+ assert_equal '0987', result.customerId
363
+ assert_equal '12345', result.orderId
364
+ assert_equal '123456', result.amount
365
+ assert_equal 'true', result.verify
366
+ assert_equal 'ecommerce', result.orderSource
367
+ assert_equal 'Checking', result.echeck.accType
368
+ assert_equal '12345657890', result.echeck.accNum
369
+ assert_equal '123456789', result.echeck.routingNum
370
+ assert_equal '123455', result.echeck.checkNum
371
+ assert_equal 'Bob', result.billToAddress.name
372
+ assert_equal 'lowell', result.billToAddress.city
373
+ assert_equal 'MA', result.billToAddress.state
374
+ assert_equal 'litle.com', result.billToAddress.email
375
+ end
376
+
377
+ def test_account_update
378
+ ltlTxn = LitleTransaction.new
379
+ accountUpdateHash = {
380
+ 'reportGroup'=>'Planets',
381
+ 'id'=>'12345',
382
+ 'customerId'=>'0987',
383
+ 'card'=>{
384
+ 'type'=>'VI',
385
+ 'number' =>'4100000000000001',
386
+ 'expDate' =>'1210'
387
+ }}
388
+
389
+ result = ltlTxn.account_update(accountUpdateHash)
390
+ assert_equal 'Planets', result.reportGroup
391
+ assert_equal '12345', result.transactionId
392
+ assert_equal '0987', result.customerId
393
+ assert_equal "4100000000000001", result.card.number
394
+ assert_equal "VI", result.card.mop
395
+ assert_equal "1210", result.card.expDate
396
+ end
397
+ end
398
+ end