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,41 @@
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 File.expand_path("../../../lib/LitleOnline",__FILE__)
26
+ require 'test/unit'
27
+
28
+ module LitleOnline
29
+ class TestAuthReversal < Test::Unit::TestCase
30
+ def test_simple_echeck_void
31
+ hash = {
32
+ 'merchantId' => '101',
33
+ 'version'=>'8.8',
34
+ 'reportGroup'=>'Planets',
35
+ 'litleTxnId'=>'12345678000',
36
+ }
37
+ response= LitleOnlineRequest.new.echeck_void(hash)
38
+ assert_equal('Approved', response.echeckVoidResponse.message)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,183 @@
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 File.expand_path("../../../lib/LitleOnline",__FILE__)
26
+ require 'test/unit'
27
+
28
+ module LitleOnline
29
+ class TestForceCapture < Test::Unit::TestCase
30
+ def test_simple_force_capture_with_card
31
+ hash = {
32
+ 'merchantId' => '101',
33
+ 'version'=>'8.8',
34
+ 'reportGroup'=>'Planets',
35
+ 'litleTxnId'=>'123456',
36
+ 'orderId'=>'12344',
37
+ 'amount'=>'106',
38
+ 'orderSource'=>'ecommerce',
39
+ 'card'=>{
40
+ 'type'=>'VI',
41
+ 'number' =>'4100000000000001',
42
+ 'expDate' =>'1210'
43
+ }}
44
+ response= LitleOnlineRequest.new.force_capture(hash)
45
+ assert_equal('000', response.forceCaptureResponse.response)
46
+ end
47
+
48
+ def test_simple_force_capture_with_token
49
+ hash = {
50
+ 'merchantId' => '101',
51
+ 'version'=>'8.8',
52
+ 'reportGroup'=>'Planets',
53
+ 'litleTxnId'=>'123456',
54
+ 'orderId'=>'12344',
55
+ 'amount'=>'106',
56
+ 'orderSource'=>'ecommerce',
57
+ 'token'=> {
58
+ 'litleToken'=>'123456789101112',
59
+ 'expDate'=>'1210',
60
+ 'cardValidationNum'=>'555',
61
+ 'type'=>'VI'
62
+ }}
63
+ response= LitleOnlineRequest.new.force_capture(hash)
64
+ assert_equal('Valid Format', response.message)
65
+ end
66
+
67
+ def test_fields_out_of_order
68
+ hash = {
69
+ 'merchantId' => '101',
70
+ 'version'=>'8.8',
71
+ 'orderSource'=>'ecommerce',
72
+ 'litleTxnId'=>'123456',
73
+ 'amount'=>'106',
74
+ 'card'=>{
75
+ 'type'=>'VI',
76
+ 'number' =>'4100000000000001',
77
+ 'expDate' =>'1210'
78
+ },
79
+ 'reportGroup'=>'Planets',
80
+ 'orderId'=>'12344'
81
+ }
82
+ response= LitleOnlineRequest.new.force_capture(hash)
83
+ assert_equal('Valid Format', response.message)
84
+ end
85
+
86
+ def test_invalid_field
87
+ hash = {
88
+ 'merchantId' => '101',
89
+ 'version'=>'8.8',
90
+ 'reportGroup'=>'Planets',
91
+ 'litleTxnId'=>'123456',
92
+ 'orderId'=>'12344',
93
+ 'amount'=>'106',
94
+ 'orderSource'=>'ecommerce',
95
+ 'card'=>{
96
+ 'NOexistantField' => 'ShouldNotCauseError',
97
+ 'type'=>'VI',
98
+ 'number' =>'4100000000000001',
99
+ 'expDate' =>'1210'
100
+ }}
101
+ response= LitleOnlineRequest.new.force_capture(hash)
102
+ assert_equal('Valid Format', response.message)
103
+ end
104
+
105
+ def test_no_order_id
106
+ hash = {
107
+ 'merchantId' => '101',
108
+ 'version'=>'8.8',
109
+ 'reportGroup'=>'Planets',
110
+ 'litleTxnId'=>'123456',
111
+ 'amount'=>'106',
112
+ 'orderSource'=>'ecommerce',
113
+ 'token'=> {
114
+ 'litleToken'=>'123456789101112',
115
+ 'expDate'=>'1210',
116
+ 'cardValidationNum'=>'555',
117
+ 'type'=>'VI'
118
+ }}
119
+ response= LitleOnlineRequest.new.force_capture(hash)
120
+ assert(response.message =~ /Error validating xml data against the schema/)
121
+ end
122
+
123
+ def test_no_order_source
124
+ hash = {
125
+ 'merchantId' => '101',
126
+ 'version'=>'8.8',
127
+ 'reportGroup'=>'Planets',
128
+ 'litleTxnId'=>'123456',
129
+ 'orderId'=>'12344',
130
+ 'amount'=>'106',
131
+ 'card'=>{
132
+ 'type'=>'VI',
133
+ 'number' =>'4100000000000001',
134
+ 'expDate' =>'1210'
135
+ }}
136
+ response= LitleOnlineRequest.new.force_capture(hash)
137
+ assert(response.message =~ /Error validating xml data against the schema/)
138
+ end
139
+
140
+ def test_simple_forceCapture_with_mpos
141
+ hash = {
142
+ 'merchantId' => '101',
143
+ 'version'=>'8.8',
144
+ 'reportGroup'=>'Planets',
145
+ 'litleTxnId'=>'123456',
146
+ 'orderId'=>'12344',
147
+ 'amount'=>'106',
148
+ 'orderSource'=>'ecommerce',
149
+ 'mpos'=>
150
+ {
151
+ 'ksn'=>'ksnString',
152
+ 'formatId'=>'30',
153
+ 'encryptedTrack'=>'encryptedTrackString',
154
+ 'track1Status'=>'0',
155
+ 'track2Status'=>'0'
156
+ }
157
+ }
158
+ response= LitleOnlineRequest.new.force_capture(hash)
159
+ assert_equal('000', response.forceCaptureResponse.response)
160
+ end
161
+
162
+ def test_simple_force_capture_with_secondaryAmount
163
+ hash = {
164
+ 'merchantId' => '101',
165
+ 'version'=>'8.8',
166
+ 'reportGroup'=>'Planets',
167
+ 'litleTxnId'=>'123456',
168
+ 'orderId'=>'12344',
169
+ 'amount'=>'106',
170
+ 'secondaryAmount'=>'20',
171
+ 'orderSource'=>'ecommerce',
172
+ 'card'=>{
173
+ 'type'=>'VI',
174
+ 'number' =>'4100000000000001',
175
+ 'expDate' =>'1210'
176
+ }}
177
+ response= LitleOnlineRequest.new.force_capture(hash)
178
+ assert_equal('000', response.forceCaptureResponse.response)
179
+ end
180
+
181
+ end
182
+
183
+ end
@@ -0,0 +1,356 @@
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 File.expand_path("../../../lib/LitleOnline",__FILE__)
26
+ require 'test/unit'
27
+ require 'fileutils'
28
+
29
+ module LitleOnline
30
+ class TestLitleRequest < Test::Unit::TestCase
31
+
32
+ def setup
33
+ dir = '/tmp/litle-sdk-for-ruby-test'
34
+ FileUtils.rm_rf dir
35
+ Dir.mkdir dir
36
+ end
37
+
38
+ def test_request_creation
39
+ dir = '/tmp'
40
+
41
+ request = LitleRequest.new()
42
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
43
+
44
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
45
+ entries.sort!
46
+
47
+ assert_equal entries.size, 4
48
+ assert_not_nil entries[2] =~ /request_\d+\z/
49
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
50
+ end
51
+
52
+ def test_commit_batch_with_path
53
+ dir = '/tmp'
54
+
55
+ batch = LitleBatchRequest.new
56
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
57
+ batch.close_batch
58
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
59
+
60
+ assert_equal entries.length, 3
61
+ entries.sort!
62
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
63
+
64
+ request = LitleRequest.new
65
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
66
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
67
+ entries.sort!
68
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
69
+ assert_not_nil entries[3] =~ /request_\d+\z/
70
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
71
+
72
+ request.commit_batch(batch.get_batch_name)
73
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
74
+ entries.sort!
75
+ assert_equal entries.length, 4
76
+ assert_not_nil entries[2] =~ /request_\d+\z/
77
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
78
+ end
79
+
80
+ def test_commit_batch_with_batch
81
+ dir = '/tmp'
82
+
83
+ batch = LitleBatchRequest.new
84
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
85
+ batch.close_batch
86
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
87
+
88
+ assert_equal entries.length, 3
89
+ entries.sort!
90
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
91
+
92
+ request = LitleRequest.new
93
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
94
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
95
+ entries.sort!
96
+ assert_equal entries.length, 5
97
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
98
+ assert_not_nil entries[3] =~ /request_\d+\z/
99
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
100
+
101
+ request.commit_batch(batch)
102
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
103
+ entries.sort!
104
+ assert_equal entries.length, 4
105
+ assert_not_nil entries[2] =~ /request_\d+\z/
106
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
107
+ end
108
+
109
+ def test_commit_batch_with_batch_and_au
110
+ dir = '/tmp'
111
+
112
+ batch = LitleBatchRequest.new
113
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
114
+ accountUpdateHash = {
115
+ 'reportGroup'=>'Planets',
116
+ 'id'=>'12345',
117
+ 'customerId'=>'0987',
118
+ 'card'=>{
119
+ 'type'=>'VI',
120
+ 'number' =>'4100000000000001',
121
+ 'expDate' =>'1210'
122
+ }}
123
+ batch.account_update(accountUpdateHash)
124
+ batch.close_batch
125
+
126
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
127
+
128
+ assert_equal entries.length, 4
129
+ entries.sort!
130
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
131
+ assert_not_nil entries[3] =~ /batch_\d+.closed-1\z/
132
+
133
+ request = LitleRequest.new
134
+ request.create_new_litle_request(dir+ '/litle-sdk-for-ruby-test')
135
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
136
+ entries.sort!
137
+ assert_equal entries.length, 6
138
+ assert_not_nil entries[2] =~ /batch_\d+.closed-0\z/
139
+ assert_not_nil entries[3] =~ /batch_\d+.closed-1\z/
140
+ assert_not_nil entries[4] =~ /request_\d+\z/
141
+ assert_not_nil entries[5] =~ /request_\d+_batches\z/
142
+
143
+ request.commit_batch(batch)
144
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
145
+ entries.sort!
146
+ assert_equal entries.length, 4
147
+ assert_not_nil entries[2] =~ /request_\d+\z/
148
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
149
+ end
150
+
151
+ def test_finish_request
152
+ dir = '/tmp'
153
+
154
+ request = LitleRequest.new()
155
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
156
+
157
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
158
+ entries.sort!
159
+
160
+ assert_equal entries.size, 4
161
+ assert_not_nil entries[2] =~ /request_\d+\z/
162
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
163
+
164
+ request.finish_request
165
+
166
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
167
+ entries.sort!
168
+
169
+ assert_equal entries.size, 3
170
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
171
+ end
172
+
173
+ def test_add_rfr
174
+ @config_hash = Configuration.new.config
175
+
176
+ dir = '/tmp'
177
+ temp = dir + '/litle-sdk-for-ruby-test/'
178
+
179
+ request = LitleRequest.new()
180
+ request.add_rfr_request({'litleSessionId' => '137813712'}, temp)
181
+
182
+ entries = Dir.entries(temp)
183
+ entries.sort!
184
+
185
+ assert_equal entries.size, 3
186
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
187
+ end
188
+
189
+ def test_send_to_litle
190
+ @config_hash = Configuration.new.config
191
+
192
+ dir = '/tmp'
193
+
194
+ request = LitleRequest.new()
195
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
196
+ request.finish_request
197
+ request.send_to_litle
198
+
199
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
200
+ entries.sort!
201
+
202
+ assert_equal entries.size, 3
203
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
204
+
205
+ uploaded_file = entries[2]
206
+
207
+ options = {}
208
+ username = get_config(:sftp_username, options)
209
+ password = get_config(:sftp_password, options)
210
+ url = get_config(:sftp_url, options)
211
+
212
+ Net::SFTP.start(url, username, :password => password) do |sftp|
213
+ # clear out the sFTP outbound dir prior to checking for new files, avoids leaving files on the server
214
+ # if files are left behind we are not counting then towards the expected total
215
+ ents = []
216
+ handle = sftp.opendir!('/inbound/')
217
+ files_on_srv = sftp.readdir!(handle)
218
+ files_on_srv.each {|file|
219
+ ents.push(file.name)
220
+ }
221
+ assert_equal ents.size, 3
222
+ ents.sort!
223
+ assert_equal ents[2], uploaded_file.gsub('sent', 'asc')
224
+ sftp.remove('/inbound/' + ents[2])
225
+ end
226
+ end
227
+
228
+ def test_send_to_litle_stream
229
+ @config_hash = Configuration.new.config
230
+
231
+ dir = '/tmp'
232
+
233
+ request = LitleRequest.new()
234
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
235
+ request.finish_request
236
+ request.send_to_litle_stream
237
+
238
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
239
+ entries.sort!
240
+
241
+ assert_equal entries.size, 4
242
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
243
+ File.delete(dir + '/litle-sdk-for-ruby-test/' + entries[2])
244
+
245
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test/responses')
246
+ entries.sort!
247
+
248
+ assert_equal entries.size, 3
249
+ assert_not_nil entries[2] =~ /response_\d+.complete.asc.received\z/
250
+ end
251
+
252
+ def test_full_flow
253
+ saleHash = {
254
+ 'reportGroup'=>'Planets',
255
+ 'id' => '006',
256
+ 'orderId'=>'12344',
257
+ 'amount'=>'6000',
258
+ 'orderSource'=>'ecommerce',
259
+ 'card'=>{
260
+ 'type'=>'VI',
261
+ 'number' =>'4100000000000001',
262
+ 'expDate' =>'1210'
263
+ }}
264
+
265
+ dir = '/tmp'
266
+
267
+ request = LitleRequest.new()
268
+ request.create_new_litle_request(dir + '/litle-sdk-for-ruby-test')
269
+
270
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
271
+ entries.sort!
272
+
273
+ assert_equal entries.size, 4
274
+ assert_not_nil entries[2] =~ /request_\d+\z/
275
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
276
+
277
+ #create five batches, each with 10 sales
278
+ 5.times{
279
+ batch = LitleBatchRequest.new
280
+ batch.create_new_batch(dir + '/litle-sdk-for-ruby-test')
281
+
282
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
283
+
284
+ assert_equal entries.length, 6
285
+ entries.sort!
286
+ assert_not_nil entries[2] =~ /batch_\d+\z/
287
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
288
+ assert_not_nil entries[4] =~ /request_\d+\z/
289
+ assert_not_nil entries[5] =~ /request_\d+_batches\z/
290
+ #add the same sale ten times
291
+ 10.times{
292
+ #batch.account_update(accountUpdateHash)
293
+ saleHash['card']['number']= (saleHash['card']['number'].to_i + 1).to_s
294
+ batch.sale(saleHash)
295
+ }
296
+
297
+ #close the batch, indicating we plan to add no more transactions
298
+ batch.close_batch()
299
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
300
+
301
+ assert_equal entries.length, 5
302
+ entries.sort!
303
+ assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
304
+ assert_not_nil entries[3] =~ /request_\d+\z/
305
+ assert_not_nil entries[4] =~ /request_\d+_batches\z/
306
+
307
+ #add the batch to the LitleRequest
308
+ request.commit_batch(batch)
309
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
310
+ assert_equal entries.length, 4
311
+ entries.sort!
312
+ assert_not_nil entries[2] =~ /request_\d+\z/
313
+ assert_not_nil entries[3] =~ /request_\d+_batches\z/
314
+ }
315
+ #finish the Litle Request, indicating we plan to add no more batches
316
+ request.finish_request
317
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
318
+ assert_equal entries.length, 3
319
+ entries.sort!
320
+ assert_not_nil entries[2] =~ /request_\d+.complete\z/
321
+
322
+ #send the batch files at the given directory over sFTP
323
+ request.send_to_litle
324
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
325
+ assert_equal entries.length, 3
326
+ entries.sort!
327
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
328
+ #grab the expected number of responses from the sFTP server and save them to the given path
329
+ request.get_responses_from_server()
330
+ #process the responses from the server with a listener which applies the given block
331
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction| end})
332
+
333
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
334
+ assert_equal entries.length, 4
335
+ entries.sort!
336
+ assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
337
+ File.delete(dir + '/litle-sdk-for-ruby-test/' + entries[2])
338
+
339
+ entries = Dir.entries(dir + '/litle-sdk-for-ruby-test/' + entries[3])
340
+ entries.sort!
341
+ assert_equal entries.length, 3
342
+ assert_not_nil entries[2] =~ /response_\d+.complete.asc.received.processed\z/
343
+
344
+ end
345
+
346
+ def get_config(field, options)
347
+ if options[field.to_s] == nil and options[field] == nil then
348
+ return @config_hash[field.to_s]
349
+ elsif options[field.to_s] != nil then
350
+ return options[field.to_s]
351
+ else
352
+ return options[field]
353
+ end
354
+ end
355
+ end
356
+ end