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.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +139 -0
  3. data/CONTRIBUTORS +2 -0
  4. data/DESCRIPTION +5 -0
  5. data/LICENSE +22 -0
  6. data/README.md +72 -0
  7. data/Rakefile +89 -0
  8. data/SETUP.md +46 -0
  9. data/bin/Setup.rb +124 -0
  10. data/bin/sample_batch_driver.rb +123 -0
  11. data/bin/sample_driver.rb +49 -0
  12. data/lib/Communications.rb +85 -0
  13. data/lib/Configuration.rb +67 -0
  14. data/lib/EnvironmentVariables.rb +22 -0
  15. data/lib/LitleBatchRequest.rb +562 -0
  16. data/lib/LitleListeners.rb +142 -0
  17. data/lib/LitleOnline.rb +62 -0
  18. data/lib/LitleOnlineRequest.rb +297 -0
  19. data/lib/LitleRequest.rb +494 -0
  20. data/lib/LitleTransaction.rb +463 -0
  21. data/lib/LitleXmlMapper.rb +64 -0
  22. data/lib/XMLFields.rb +1869 -0
  23. data/lib/cacert.pem +3331 -0
  24. data/samples/Auth/LitleAuthReversalTransaction.rb +15 -0
  25. data/samples/Auth/LitleAuthorizationTransaction.rb +31 -0
  26. data/samples/Auth/LitlePaymentFullLifeCycle.rb +47 -0
  27. data/samples/Batch/AccountUpdate.rb +64 -0
  28. data/samples/Batch/SampleBatchDriver.rb +94 -0
  29. data/samples/Capture/LitleCaptureGivenAuthTransaction.rb +30 -0
  30. data/samples/Capture/LitleCaptureTransaction.rb +14 -0
  31. data/samples/Capture/LitleForceCaptureTransaction.rb +26 -0
  32. data/samples/Capture/LitlePartialCapture.rb +16 -0
  33. data/samples/Credit/LitleCreditTransaction.rb +16 -0
  34. data/samples/Credit/LitleRefundTransaction.rb +29 -0
  35. data/samples/Other/LitleAvsTransaction.rb +34 -0
  36. data/samples/Other/LitleVoidTransaction.rb +18 -0
  37. data/samples/Paypage/FullPaypageLifeCycle.rb +74 -0
  38. data/samples/Run_all.rb +17 -0
  39. data/samples/Sale/LitleSaleTransaction.rb +29 -0
  40. data/samples/Sale/SampleSaleTransaction.rb +24 -0
  41. data/test/certification/certTest1_base.rb +945 -0
  42. data/test/certification/certTest2_authenhanced.rb +573 -0
  43. data/test/certification/certTest3_authreversal.rb +185 -0
  44. data/test/certification/certTest4_echeck.rb +278 -0
  45. data/test/certification/certTest5_token.rb +204 -0
  46. data/test/certification/certTest_batchAll.rb +337 -0
  47. data/test/certification/ts_all.rb +33 -0
  48. data/test/functional/test_activate.rb +100 -0
  49. data/test/functional/test_activateReversal.rb +56 -0
  50. data/test/functional/test_auth.rb +298 -0
  51. data/test/functional/test_authReversal.rb +69 -0
  52. data/test/functional/test_balanceInquiry.rb +80 -0
  53. data/test/functional/test_batch.rb +164 -0
  54. data/test/functional/test_batchStream.rb +145 -0
  55. data/test/functional/test_cancelSubscription.rb +55 -0
  56. data/test/functional/test_capture.rb +84 -0
  57. data/test/functional/test_captureGivenAuth.rb +235 -0
  58. data/test/functional/test_configuration.rb +89 -0
  59. data/test/functional/test_createPlan.rb +85 -0
  60. data/test/functional/test_credit.rb +174 -0
  61. data/test/functional/test_deactivate.rb +80 -0
  62. data/test/functional/test_deactivateReversal.rb +56 -0
  63. data/test/functional/test_depositReversal.rb +56 -0
  64. data/test/functional/test_echeckCredit.rb +134 -0
  65. data/test/functional/test_echeckRedeposit.rb +88 -0
  66. data/test/functional/test_echeckSale.rb +177 -0
  67. data/test/functional/test_echeckVerification.rb +127 -0
  68. data/test/functional/test_echeckVoid.rb +41 -0
  69. data/test/functional/test_forceCapture.rb +183 -0
  70. data/test/functional/test_litle_requests.rb +356 -0
  71. data/test/functional/test_load.rb +82 -0
  72. data/test/functional/test_loadReversal.rb +56 -0
  73. data/test/functional/test_override.rb +64 -0
  74. data/test/functional/test_refundReversal.rb +56 -0
  75. data/test/functional/test_sale.rb +259 -0
  76. data/test/functional/test_token.rb +115 -0
  77. data/test/functional/test_unload.rb +82 -0
  78. data/test/functional/test_unloadReversal.rb +56 -0
  79. data/test/functional/test_updateCardValidationNumOnToken.rb +43 -0
  80. data/test/functional/test_updatePlan.rb +58 -0
  81. data/test/functional/test_updateSubscription.rb +76 -0
  82. data/test/functional/test_xmlfields.rb +427 -0
  83. data/test/functional/ts_all.rb +66 -0
  84. data/test/unit/test_LitleAUBatch.rb +216 -0
  85. data/test/unit/test_LitleBatchRequest.rb +643 -0
  86. data/test/unit/test_LitleOnlineRequest.rb +295 -0
  87. data/test/unit/test_LitleRequest.rb +316 -0
  88. data/test/unit/test_LitleTransaction.rb +397 -0
  89. data/test/unit/test_activate.rb +92 -0
  90. data/test/unit/test_activateReversal.rb +44 -0
  91. data/test/unit/test_auth.rb +421 -0
  92. data/test/unit/test_authReversal.rb +82 -0
  93. data/test/unit/test_balanceInquiry.rb +52 -0
  94. data/test/unit/test_cancelSubscription.rb +43 -0
  95. data/test/unit/test_capture.rb +73 -0
  96. data/test/unit/test_captureGivenAuth.rb +188 -0
  97. data/test/unit/test_createPlan.rb +52 -0
  98. data/test/unit/test_credit.rb +342 -0
  99. data/test/unit/test_deactivate.rb +52 -0
  100. data/test/unit/test_deactivateReversal.rb +44 -0
  101. data/test/unit/test_depositReversal.rb +44 -0
  102. data/test/unit/test_echeckCredit.rb +71 -0
  103. data/test/unit/test_echeckRedeposit.rb +94 -0
  104. data/test/unit/test_echeckSale.rb +71 -0
  105. data/test/unit/test_echeckVerification.rb +71 -0
  106. data/test/unit/test_echeckVoid.rb +54 -0
  107. data/test/unit/test_forceCapture.rb +145 -0
  108. data/test/unit/test_load.rb +53 -0
  109. data/test/unit/test_loadReversal.rb +44 -0
  110. data/test/unit/test_refundReversal.rb +44 -0
  111. data/test/unit/test_sale.rb +465 -0
  112. data/test/unit/test_token.rb +144 -0
  113. data/test/unit/test_unload.rb +53 -0
  114. data/test/unit/test_unloadReversal.rb +44 -0
  115. data/test/unit/test_updateCardValidationNumOnToken.rb +80 -0
  116. data/test/unit/test_updatePlan.rb +45 -0
  117. data/test/unit/test_updateSubscription.rb +172 -0
  118. data/test/unit/test_xmlfields.rb +2930 -0
  119. data/test/unit/ts_unit.rb +65 -0
  120. metadata +224 -0
@@ -0,0 +1,66 @@
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 File.expand_path("../../../lib/LitleOnline",__FILE__)
27
+
28
+
29
+ #test driver for running all tests
30
+ require_relative 'test_updateSubscription'
31
+ require_relative 'test_captureGivenAuth'
32
+ require_relative 'test_xmlfields'
33
+ require_relative 'test_sale'
34
+ require_relative 'test_captureGivenAuth'
35
+ require_relative 'test_authReversal'
36
+ require_relative 'test_credit'
37
+ require_relative 'test_auth'
38
+ require_relative 'test_token'
39
+ require_relative 'test_forceCapture'
40
+ require_relative 'test_capture'
41
+ require_relative 'test_echeckRedeposit'
42
+ require_relative 'test_echeckSale'
43
+ require_relative 'test_echeckCredit'
44
+ require_relative 'test_echeckVerification'
45
+ require_relative 'test_echeckVoid'
46
+ require_relative 'test_updateCardValidationNumOnToken'
47
+ require_relative 'test_litle_requests'
48
+ require_relative 'test_batch'
49
+ require_relative 'test_cancelSubscription'
50
+ require_relative 'test_updateSubscription'
51
+ require_relative 'test_deactivate'
52
+ require_relative 'test_load'
53
+ require_relative 'test_unload'
54
+ require_relative 'test_balanceInquiry'
55
+ require_relative 'test_createPlan'
56
+ require_relative 'test_updatePlan'
57
+ require_relative 'test_batchStream'
58
+ require_relative 'test_activate'
59
+ require_relative 'test_activateReversal'
60
+ require_relative 'test_depositReversal'
61
+ require_relative 'test_refundReversal'
62
+ require_relative 'test_loadReversal'
63
+ require_relative 'test_unloadReversal'
64
+ require_relative 'test_deactivateReversal'
65
+ require_relative 'test_override'
66
+ require_relative 'test_configuration'
@@ -0,0 +1,216 @@
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 TestLitleAUBatch < Test::Unit::TestCase
32
+ def test_create_new_batch
33
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
34
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
35
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
36
+ File.expects(:directory?).returns(false).once
37
+
38
+ batch = LitleAUBatch.new
39
+ batch.create_new_batch('/usr/local/Batches/')
40
+ end
41
+
42
+ def test_account_update
43
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
44
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
45
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
46
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
47
+ File.expects(:directory?).returns(true).once
48
+
49
+ accountUpdateHash = {
50
+ 'reportGroup'=>'Planets',
51
+ 'id'=>'12345',
52
+ 'customerId'=>'0987',
53
+ 'card'=>{
54
+ 'type'=>'VI',
55
+ 'number' =>'4100000000000001',
56
+ 'expDate' =>'1210'
57
+ }}
58
+
59
+ batch = LitleAUBatch.new
60
+ batch.create_new_batch('D:\Batches\\')
61
+ batch.account_update(accountUpdateHash)
62
+
63
+ counts = batch.get_counts_and_amounts
64
+ assert_equal 1, counts[:numAccountUpdates]
65
+ assert_equal 1, counts[:total]
66
+ end
67
+
68
+ def test_close_batch
69
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
70
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
71
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
72
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
73
+ File.expects(:rename).once
74
+ File.expects(:delete).once
75
+ File.expects(:directory?).returns(true).once
76
+
77
+ batch = LitleAUBatch.new
78
+ batch.create_new_batch('D:\Batches\\')
79
+
80
+ batch.close_batch()
81
+ end
82
+
83
+ def test_open_existing_batch
84
+ open = sequence('open')
85
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
86
+
87
+ File.expects(:file?).returns(false).once.in_sequence(open)
88
+ File.expects(:directory?).returns(true).in_sequence(open)
89
+ File.expects(:file?).returns(false).in_sequence(open)
90
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
91
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
92
+ File.expects(:file?).returns(true).in_sequence(open)
93
+
94
+
95
+
96
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
97
+ File.expects(:rename).once.in_sequence(open)
98
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
99
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
100
+ batch1 = LitleAUBatch.new
101
+ batch2 = LitleAUBatch.new
102
+ batch1.create_new_batch('/usr/local/Batches/')
103
+
104
+ batch2.open_existing_batch(batch1.get_batch_name)
105
+ batch2.close_batch()
106
+ end
107
+
108
+ def test_build_batch_header
109
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
110
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
111
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
112
+ File.expects(:rename).once
113
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
114
+ File.expects(:delete).once
115
+ File.expects(:directory?).returns(true).once
116
+
117
+ batch = LitleAUBatch.new
118
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(5)
119
+
120
+ batch.create_new_batch('/usr/local/batches')
121
+ batch.close_batch()
122
+ end
123
+
124
+ def test_create_new_batch_missing_separator
125
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
126
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
127
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
128
+
129
+ batch = LitleAUBatch.new
130
+ batch.create_new_batch('/usr/local')
131
+
132
+ assert batch.get_batch_name.include?('/usr/local/')
133
+ end
134
+
135
+ def test_create_new_batch_name_collision
136
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
137
+
138
+ fileExists = sequence('fileExists')
139
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
140
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
141
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
142
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
143
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
144
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
145
+
146
+
147
+ batch = LitleAUBatch.new
148
+ batch.create_new_batch('/usr/local/')
149
+ end
150
+
151
+ def test_create_new_batch_when_full
152
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
153
+
154
+ batch = LitleAUBatch.new
155
+ addTxn = sequence('addTxn')
156
+
157
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
158
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
159
+ batch.create_new_batch('/usr/local')
160
+
161
+ batch.get_counts_and_amounts.expects(:[]).with(:numAccountUpdates).returns(499999).in_sequence(addTxn)
162
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(30000).in_sequence(addTxn)
163
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
164
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
165
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
166
+ batch.expects(:close_batch).once.in_sequence(addTxn)
167
+ batch.expects(:initialize).once.in_sequence(addTxn)
168
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
169
+
170
+ accountUpdateHash = {
171
+ 'reportGroup'=>'Planets',
172
+ 'id'=>'12345',
173
+ 'customerId'=>'0987',
174
+ 'card'=>{
175
+ 'type'=>'VI',
176
+ 'number' =>'4100000000000001',
177
+ 'expDate' =>'1210'
178
+ }}
179
+
180
+ batch.account_update(accountUpdateHash)
181
+ end
182
+
183
+ def test_complete_batch
184
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
185
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(7)
186
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(5)
187
+ File.expects(:rename).once
188
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
189
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
190
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
191
+ File.expects(:directory?).returns(false).once
192
+
193
+ batch = LitleAUBatch.new
194
+ batch.create_new_batch('/usr/local/Batches/')
195
+
196
+ accountUpdateHash = {
197
+ 'reportGroup'=>'Planets',
198
+ 'id'=>'12345',
199
+ 'customerId'=>'0987',
200
+ 'card'=>{
201
+ 'type'=>'VI',
202
+ 'number' =>'4100000000000001',
203
+ 'expDate' =>'1210'
204
+ }}
205
+
206
+ 5.times(){ batch.account_update(accountUpdateHash ) }
207
+
208
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
209
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
210
+ batch.close_batch()
211
+ counts = batch.get_counts_and_amounts
212
+
213
+ assert_equal 5, counts[:numAccountUpdates]
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,643 @@
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
+
27
+ require 'test/unit'
28
+ require 'mocha/setup'
29
+
30
+ module LitleOnline
31
+
32
+ class TestLitleBatchRequest < Test::Unit::TestCase
33
+ def test_create_new_batch
34
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
35
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
36
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
37
+ File.expects(:directory?).returns(false).once
38
+
39
+ batch = LitleBatchRequest.new
40
+ batch.create_new_batch('/usr/local/Batches/')
41
+ end
42
+
43
+
44
+ def test_add_authorization
45
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
46
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
47
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').at_most(3)
48
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').twice
49
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
50
+ File.expects(:directory?).returns(false).once
51
+ authHash = {
52
+ 'reportGroup'=>'Planets',
53
+ 'orderId'=>'12344',
54
+ 'amount'=>'106',
55
+ 'orderSource'=>'ecommerce',
56
+ 'card'=>{
57
+ 'type'=>'VI',
58
+ 'number' =>'4100000000000001',
59
+ 'expDate' =>'1210'
60
+ }}
61
+
62
+ batch = LitleBatchRequest.new
63
+ batch.create_new_batch('/usr/local/Batches/')
64
+
65
+ 2.times(){ batch.authorization(authHash) }
66
+ counts = batch.get_counts_and_amounts
67
+
68
+ assert_equal 2, counts[:auth][:numAuths]
69
+ assert_equal 212, counts[:auth][:authAmount]
70
+ end
71
+
72
+ def test_add_sale
73
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
74
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
75
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
76
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
77
+ File.expects(:directory?).returns(true).once
78
+
79
+ saleHash = {
80
+ 'reportGroup'=>'Planets',
81
+ 'id' => '006',
82
+ 'orderId'=>'12344',
83
+ 'amount'=>'6000',
84
+ 'orderSource'=>'ecommerce',
85
+ 'card'=>{
86
+ 'type'=>'VI',
87
+ 'number' =>'4100000000000001',
88
+ 'expDate' =>'1210'
89
+ }}
90
+
91
+ batch = LitleBatchRequest.new
92
+ batch.create_new_batch('D:\Batches\\')
93
+ batch.sale(saleHash)
94
+
95
+ counts = batch.get_counts_and_amounts
96
+ assert_equal 1, counts[:sale][:numSales]
97
+ assert_equal 6000, counts[:sale][:saleAmount]
98
+ end
99
+
100
+ def test_add_credit
101
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
102
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
103
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
104
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
105
+ File.expects(:directory?).returns(true).once
106
+
107
+ creditHash = {
108
+ 'merchantId' => '101',
109
+ 'version'=>'8.8',
110
+ 'reportGroup'=>'Planets',
111
+ 'orderId'=>'12344',
112
+ 'amount'=>'106',
113
+ 'orderSource'=>'ecommerce',
114
+ 'card'=>{
115
+ 'type'=>'VI',
116
+ 'number' =>'4100000000000001',
117
+ 'expDate' =>'1210'
118
+ }}
119
+
120
+ batch = LitleBatchRequest.new
121
+ batch.create_new_batch('D:\Batches\\')
122
+ batch.credit(creditHash)
123
+
124
+ counts = batch.get_counts_and_amounts
125
+ assert_equal 1, counts[:credit][:numCredits]
126
+ assert_equal 106, counts[:credit][:creditAmount]
127
+ end
128
+
129
+ def test_add_auth_reversal
130
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
131
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
132
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
133
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
134
+ File.expects(:directory?).returns(true).once
135
+
136
+ authReversalHash = {
137
+ 'merchantId' => '101',
138
+ 'version'=>'8.8',
139
+ 'reportGroup'=>'Planets',
140
+ 'litleTxnId'=>'12345678000',
141
+ 'amount'=>'106',
142
+ 'payPalNotes'=>'Notes'
143
+ }
144
+
145
+ batch = LitleBatchRequest.new
146
+ batch.create_new_batch('D:\Batches\\')
147
+ batch.auth_reversal(authReversalHash)
148
+
149
+ counts = batch.get_counts_and_amounts
150
+ assert_equal 1, counts[:authReversal][:numAuthReversals]
151
+ assert_equal 106, counts[:authReversal][:authReversalAmount]
152
+ end
153
+
154
+ def test_add_register_token_request
155
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
156
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
157
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
158
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
159
+ File.expects(:directory?).returns(true).once
160
+
161
+ registerTokenHash = {
162
+ 'merchantId' => '101',
163
+ 'version'=>'8.8',
164
+ 'reportGroup'=>'Planets',
165
+ 'orderId'=>'12344',
166
+ 'accountNumber'=>'1233456789103801'
167
+ }
168
+
169
+ batch = LitleBatchRequest.new
170
+ batch.create_new_batch('D:\Batches\\')
171
+ batch.register_token_request(registerTokenHash)
172
+
173
+ counts = batch.get_counts_and_amounts
174
+ assert_equal 1, counts[:numTokenRegistrations]
175
+ end
176
+
177
+ def test_cancel_subscription
178
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
179
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
180
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
181
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
182
+ File.expects(:directory?).returns(true).once
183
+
184
+ hash = {
185
+ 'merchantId' => '101',
186
+ 'version'=>'8.8',
187
+ 'reportGroup'=>'Planets',
188
+ 'subscriptionId'=>'100'
189
+ }
190
+
191
+ batch = LitleBatchRequest.new
192
+ batch.create_new_batch('D:\Batches\\')
193
+ batch.cancel_subscription(hash)
194
+
195
+ counts = batch.get_counts_and_amounts
196
+ assert_equal 1, counts[:numCancelSubscriptions]
197
+ end
198
+
199
+ def test_update_subscription
200
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
201
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
202
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
203
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
204
+ File.expects(:directory?).returns(true).once
205
+
206
+ hash = {
207
+ 'merchantId' => '101',
208
+ 'version'=>'8.8',
209
+ 'reportGroup'=>'Planets',
210
+ 'subscriptionId'=>'100',
211
+ 'planCode'=>'planCodeString',
212
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
213
+ }
214
+
215
+ batch = LitleBatchRequest.new
216
+ batch.create_new_batch('D:\Batches\\')
217
+ batch.update_subscription(hash)
218
+
219
+ counts = batch.get_counts_and_amounts
220
+ assert_equal 1, counts[:numUpdateSubscriptions]
221
+ end
222
+ def test_add_update_card_validation_num_on_token
223
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
224
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
225
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
226
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
227
+ File.expects(:directory?).returns(true).once
228
+
229
+ updateCardHash = {
230
+ 'merchantId' => '101',
231
+ 'version'=>'8.8',
232
+ 'reportGroup'=>'Planets',
233
+ 'orderId'=>'12344',
234
+ 'litleToken'=>'1233456789103801',
235
+ 'cardValidationNum'=>'123'
236
+ }
237
+
238
+ batch = LitleBatchRequest.new
239
+ batch.create_new_batch('D:\Batches\\')
240
+ batch.update_card_validation_num_on_token(updateCardHash)
241
+
242
+ counts = batch.get_counts_and_amounts
243
+ assert_equal 1, counts[:numUpdateCardValidationNumOnTokens]
244
+ end
245
+
246
+ def test_add_force_capture
247
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
248
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
249
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
250
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
251
+ File.expects(:directory?).returns(true).once
252
+
253
+ forceCaptHash = {
254
+ 'merchantId' => '101',
255
+ 'version'=>'8.8',
256
+ 'reportGroup'=>'Planets',
257
+ 'litleTxnId'=>'123456',
258
+ 'orderId'=>'12344',
259
+ 'amount'=>'106',
260
+ 'orderSource'=>'ecommerce',
261
+ 'card'=>{
262
+ 'type'=>'VI',
263
+ 'number' =>'4100000000000001',
264
+ 'expDate' =>'1210'
265
+ }}
266
+
267
+ batch = LitleBatchRequest.new
268
+ batch.create_new_batch('D:\Batches\\')
269
+ batch.force_capture(forceCaptHash)
270
+
271
+ counts = batch.get_counts_and_amounts
272
+ assert_equal 1, counts[:forceCapture][:numForceCaptures]
273
+ assert_equal 106, counts[:forceCapture][:forceCaptureAmount]
274
+ end
275
+
276
+ def test_add_capture
277
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
278
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
279
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
280
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
281
+ File.expects(:directory?).returns(true).once
282
+
283
+ captHash = {
284
+ 'merchantId' => '101',
285
+ 'version'=>'8.8',
286
+ 'reportGroup'=>'Planets',
287
+ 'litleTxnId'=>'123456000',
288
+ 'amount'=>'106',
289
+ }
290
+
291
+ batch = LitleBatchRequest.new
292
+ batch.create_new_batch('D:\Batches\\')
293
+ batch.capture(captHash)
294
+
295
+ counts = batch.get_counts_and_amounts
296
+ assert_equal 1, counts[:capture][:numCaptures]
297
+ assert_equal 106, counts[:capture][:captureAmount]
298
+ end
299
+
300
+ def test_add_capture_given_auth
301
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
302
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
303
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
304
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
305
+ File.expects(:directory?).returns(true).once
306
+
307
+ captGivenAuthHash = {
308
+ 'merchantId' => '101',
309
+ 'version'=>'8.8',
310
+ 'reportGroup'=>'Planets',
311
+ 'orderId'=>'12344',
312
+ 'amount'=>'106',
313
+ 'authInformation' => {
314
+ 'authDate'=>'2002-10-09','authCode'=>'543216',
315
+ 'authAmount'=>'12345'
316
+ },
317
+ 'orderSource'=>'ecommerce',
318
+ 'card'=>{
319
+ 'type'=>'VI',
320
+ 'number' =>'4100000000000000',
321
+ 'expDate' =>'1210'
322
+ }}
323
+
324
+ batch = LitleBatchRequest.new
325
+ batch.create_new_batch('D:\Batches\\')
326
+ batch.capture_given_auth(captGivenAuthHash)
327
+
328
+ counts = batch.get_counts_and_amounts
329
+ assert_equal 1, counts[:captureGivenAuth][:numCaptureGivenAuths]
330
+ assert_equal 106, counts[:captureGivenAuth][:captureGivenAuthAmount]
331
+ end
332
+
333
+ def test_add_echeck_verification
334
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
335
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
336
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
337
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
338
+ File.expects(:directory?).returns(true).once
339
+
340
+ echeckVerificationHash = {
341
+ 'merchantId' => '101',
342
+ 'version'=>'8.8',
343
+ 'reportGroup'=>'Planets',
344
+ 'amount'=>'123456',
345
+ 'orderId'=>'12345',
346
+ 'orderSource'=>'ecommerce',
347
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
348
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
349
+ }
350
+
351
+ batch = LitleBatchRequest.new
352
+ batch.create_new_batch('D:\Batches\\')
353
+ batch.echeck_verification(echeckVerificationHash)
354
+
355
+ counts = batch.get_counts_and_amounts
356
+ assert_equal 1, counts[:echeckVerification][:numEcheckVerification]
357
+ assert_equal 123456, counts[:echeckVerification][:echeckVerificationAmount]
358
+ end
359
+
360
+ def test_add_echeck_credit
361
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
362
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
363
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
364
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
365
+ File.expects(:directory?).returns(true).once
366
+
367
+ echeckCreditHash = {
368
+ 'merchantId' => '101',
369
+ 'version'=>'8.8',
370
+ 'reportGroup'=>'Planets',
371
+ 'litleTxnId'=>'123456789101112',
372
+ 'amount'=>'12'
373
+ }
374
+
375
+ batch = LitleBatchRequest.new
376
+ batch.create_new_batch('D:\Batches\\')
377
+ batch.echeck_credit(echeckCreditHash)
378
+
379
+ counts = batch.get_counts_and_amounts
380
+ assert_equal 1, counts[:echeckCredit][:numEcheckCredit]
381
+ assert_equal 12, counts[:echeckCredit][:echeckCreditAmount]
382
+ end
383
+
384
+ def test_add_echeck_redeposit
385
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
386
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
387
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
388
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
389
+ File.expects(:directory?).returns(true).once
390
+
391
+ echeckRedeopsitHash = {
392
+ 'merchantId' => '101',
393
+ 'version'=>'8.8',
394
+ 'reportGroup'=>'Planets',
395
+ 'litleTxnId'=>'123456'
396
+ }
397
+
398
+ batch = LitleBatchRequest.new
399
+ batch.create_new_batch('D:\Batches\\')
400
+ batch.echeck_redeposit(echeckRedeopsitHash)
401
+
402
+ counts = batch.get_counts_and_amounts
403
+ assert_equal 1, counts[:numEcheckRedeposit]
404
+ end
405
+
406
+ def test_add_echeck_sale
407
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
408
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
409
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
410
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
411
+ File.expects(:directory?).returns(true).once
412
+
413
+ echeckSaleHash = {
414
+ 'merchantId' => '101',
415
+ 'version'=>'8.8',
416
+ 'reportGroup'=>'Planets',
417
+ 'amount'=>'123456',
418
+ 'verify'=>'true',
419
+ 'orderId'=>'12345',
420
+ 'orderSource'=>'ecommerce',
421
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
422
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
423
+ }
424
+
425
+ batch = LitleBatchRequest.new
426
+ batch.create_new_batch('D:\Batches\\')
427
+ batch.echeck_sale(echeckSaleHash)
428
+
429
+ counts = batch.get_counts_and_amounts
430
+ assert_equal 1, counts[:echeckSale][:numEcheckSales]
431
+ assert_equal 123456, counts[:echeckSale][:echeckSalesAmount]
432
+ end
433
+
434
+ def test_close_batch
435
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
436
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
437
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
438
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
439
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
440
+ File.expects(:rename).once
441
+ File.expects(:delete).once
442
+ File.expects(:directory?).returns(true).once
443
+
444
+ saleHash = {
445
+ 'reportGroup'=>'Planets',
446
+ 'id' => '006',
447
+ 'orderId'=>'12344',
448
+ 'amount'=>'6000',
449
+ 'orderSource'=>'ecommerce',
450
+ 'card'=>{
451
+ 'type'=>'VI',
452
+ 'number' =>'4100000000000001',
453
+ 'expDate' =>'1210'
454
+ }}
455
+
456
+ batch = LitleBatchRequest.new
457
+ batch.create_new_batch('D:\Batches\\')
458
+
459
+ batch.sale(saleHash)
460
+ batch.close_batch()
461
+ end
462
+
463
+ def test_open_existing_batch
464
+
465
+ saleHash = {
466
+ 'reportGroup'=>'Planets',
467
+ 'id' => '006',
468
+ 'orderId'=>'12344',
469
+ 'amount'=>'6000',
470
+ 'orderSource'=>'ecommerce',
471
+ 'card'=>{
472
+ 'type'=>'VI',
473
+ 'number' =>'4100000000000001',
474
+ 'expDate' =>'1210'
475
+ }}
476
+
477
+ open = sequence('open')
478
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
479
+
480
+ File.expects(:file?).returns(false).once.in_sequence(open)
481
+ File.expects(:directory?).returns(true).in_sequence(open)
482
+ File.expects(:file?).returns(false).in_sequence(open)
483
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
484
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
485
+ File.expects(:file?).returns(true).in_sequence(open)
486
+
487
+
488
+
489
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
490
+ File.expects(:rename).once.in_sequence(open)
491
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
492
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
493
+ batch1 = LitleBatchRequest.new
494
+ batch2 = LitleBatchRequest.new
495
+ batch2.expects(:build_batch_header).returns("foo")
496
+ batch1.create_new_batch('/usr/local/Batches/')
497
+ batch2.open_existing_batch(batch1.get_batch_name)
498
+ batch2.close_batch()
499
+ end
500
+
501
+ def test_build_batch_header
502
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
503
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
504
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
505
+ File.expects(:rename).once
506
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
507
+ File.expects(:delete).once
508
+ File.expects(:directory?).returns(true).once
509
+
510
+ batch = LitleBatchRequest.new
511
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(25)
512
+ hash.expects(:[]).returns('a').at_least(20)
513
+
514
+ batch.create_new_batch('/usr/local/Batches')
515
+ batch.close_batch()
516
+ end
517
+
518
+ def test_create_new_batch_missing_separator
519
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
520
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
521
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
522
+
523
+ batch = LitleBatchRequest.new
524
+ batch.create_new_batch('/usr/local')
525
+
526
+ assert batch.get_batch_name.include?('/usr/local/')
527
+ end
528
+
529
+ def test_create_new_batch_name_collision
530
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
531
+
532
+ fileExists = sequence('fileExists')
533
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
534
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
535
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
536
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
537
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
538
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
539
+
540
+
541
+ batch = LitleBatchRequest.new
542
+ batch.create_new_batch('/usr/local/')
543
+ end
544
+
545
+ def test_create_new_batch_when_full
546
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
547
+
548
+ batch = LitleBatchRequest.new
549
+ addTxn = sequence('addTxn')
550
+
551
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
552
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
553
+ batch.create_new_batch('/usr/local')
554
+
555
+ batch.get_counts_and_amounts.expects(:[]).with(:sale).returns({:numSales => 10, :saleAmount => 20}).twice.in_sequence(addTxn)
556
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(499999).in_sequence(addTxn)
557
+
558
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
559
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
560
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
561
+
562
+ batch.expects(:close_batch).once.in_sequence(addTxn)
563
+ batch.expects(:initialize).once.in_sequence(addTxn)
564
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
565
+
566
+ saleHash = {
567
+ 'reportGroup'=>'Planets',
568
+ 'id' => '006',
569
+ 'orderId'=>'12344',
570
+ 'amount'=>'6000',
571
+ 'orderSource'=>'ecommerce',
572
+ 'card'=>{
573
+ 'type'=>'VI',
574
+ 'number' =>'4100000000000001',
575
+ 'expDate' =>'1210'
576
+ }}
577
+
578
+ batch.sale(saleHash)
579
+
580
+ end
581
+
582
+ def test_complete_batch
583
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
584
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(9)
585
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(7)
586
+ File.expects(:rename).once
587
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
588
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
589
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
590
+ File.expects(:directory?).returns(false).once
591
+
592
+ authHash = {
593
+ 'reportGroup'=>'Planets',
594
+ 'orderId'=>'12344',
595
+ 'amount'=>'106',
596
+ 'orderSource'=>'ecommerce',
597
+ 'card'=>{
598
+ 'type'=>'VI',
599
+ 'number' =>'4100000000000001',
600
+ 'expDate' =>'1210'
601
+ }}
602
+
603
+ saleHash = {
604
+ 'reportGroup'=>'Planets',
605
+ 'id' => '006',
606
+ 'orderId'=>'12344',
607
+ 'amount'=>'6000',
608
+ 'orderSource'=>'ecommerce',
609
+ 'card'=>{
610
+ 'type'=>'VI',
611
+ 'number' =>'4100000000000001',
612
+ 'expDate' =>'1210'
613
+ }}
614
+
615
+ updateCardHash = {
616
+ 'merchantId' => '101',
617
+ 'version'=>'8.8',
618
+ 'reportGroup'=>'Planets',
619
+ 'id'=>'12345',
620
+ 'customerId'=>'0987',
621
+ 'orderId'=>'12344',
622
+ 'litleToken'=>'1233456789103801',
623
+ 'cardValidationNum'=>'123'
624
+ }
625
+
626
+ batch = LitleBatchRequest.new
627
+ batch.create_new_batch('/usr/local/Batches/')
628
+
629
+ 5.times(){ batch.authorization(authHash) }
630
+ 2.times(){ batch.sale(saleHash) }
631
+
632
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
633
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
634
+ batch.close_batch()
635
+ counts = batch.get_counts_and_amounts
636
+
637
+ assert_equal 5, counts[:auth][:numAuths]
638
+ #assert_equal 212, counts[:auth][:authAmount]
639
+ assert_equal 2, counts[:sale][:numSales]
640
+ #assert_equal 6000, counts[:sale][:saleAmount]
641
+ end
642
+ end
643
+ end