CnpOnline 8.31.1 → 9.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +29 -12
- data/DESCRIPTION +2 -2
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/Rakefile~ +5 -5
- data/SETUP.md +3 -3
- data/bin/Setup.rb +9 -8
- data/bin/sample_batch_driver.rb +1 -1
- data/bin/sample_driver.rb +1 -1
- data/lib/Communications.rb +1 -1
- data/lib/Configuration.rb +16 -16
- data/lib/EnvironmentVariables.rb +1 -2
- data/lib/LitleBatchRequest.rb +283 -147
- data/lib/LitleListeners.rb +132 -33
- data/lib/LitleOnline.rb +5 -4
- data/lib/LitleOnlineRequest.rb +69 -59
- data/lib/LitleRequest.rb +178 -141
- data/lib/LitleTransaction.rb +279 -122
- data/lib/LitleXmlMapper.rb +9 -4
- data/lib/XMLFields.rb +345 -26
- data/test/certification/certTest1_base.rb +74 -73
- data/test/certification/certTest2_authenhanced.rb +1 -1
- data/test/certification/certTest3_authreversal.rb +1 -1
- data/test/certification/certTest4_echeck.rb +4 -1
- data/test/certification/certTest5_token.rb +4 -4
- data/test/certification/certTest_batchAll.rb +296 -55
- data/test/certification/ts_all.rb +1 -1
- data/test/functional/test_activate.rb +7 -3
- data/test/functional/test_activateReversal.rb +7 -3
- data/test/functional/test_auth.rb +119 -16
- data/test/functional/test_authReversal.rb +5 -3
- data/test/functional/test_balanceInquiry.rb +5 -3
- data/test/functional/test_batch.rb +3 -3
- data/test/functional/test_batchStream.rb +14 -4
- data/test/functional/test_cancelSubscription.rb +5 -3
- data/test/functional/test_capture.rb +34 -3
- data/test/functional/test_captureGivenAuth.rb +55 -4
- data/test/functional/test_configuration.rb +2 -2
- data/test/functional/test_createPlan.rb +5 -3
- data/test/functional/test_credit.rb +45 -16
- data/test/functional/test_deactivate.rb +5 -3
- data/test/functional/test_deactivateReversal.rb +5 -3
- data/test/functional/test_depositReversal.rb +5 -3
- data/test/functional/test_echeckCredit.rb +26 -9
- data/test/functional/test_echeckRedeposit.rb +5 -3
- data/test/functional/test_echeckSale.rb +49 -28
- data/test/functional/test_echeckVerification.rb +20 -12
- data/test/functional/test_echeckVoid.rb +1 -1
- data/test/functional/test_forceCapture.rb +44 -22
- data/test/functional/test_fraudCheck.rb +77 -0
- data/test/functional/test_litle_requests.rb +24 -24
- data/test/functional/test_load.rb +5 -3
- data/test/functional/test_loadReversal.rb +5 -3
- data/test/functional/test_refundReversal.rb +5 -3
- data/test/functional/test_sale.rb +214 -29
- data/test/functional/test_token.rb +19 -3
- data/test/functional/test_unload.rb +5 -3
- data/test/functional/test_unloadReversal.rb +6 -4
- data/test/functional/test_updateCardValidationNumOnToken.rb +1 -1
- data/test/functional/test_updatePlan.rb +5 -3
- data/test/functional/test_updateSubscription.rb +5 -3
- data/test/functional/test_utf8.rb +44 -0
- data/test/functional/test_xmlfields.rb +10 -6
- data/test/functional/ts_all.rb +2 -1
- data/test/unit/test_LitleAUBatch.rb +29 -1
- data/test/unit/test_LitleBatchRequest.rb +247 -113
- data/test/unit/test_LitleOnlineRequest.rb +37 -54
- data/test/unit/test_LitleRequest.rb +3 -3
- data/test/unit/test_LitleTransaction.rb +5 -5
- data/test/unit/test_LitleXmlMapper.rb +136 -0
- data/test/unit/test_activate.rb +1 -21
- data/test/unit/test_activateReversal.rb +1 -1
- data/test/unit/test_auth.rb +54 -14
- data/test/unit/test_authReversal.rb +1 -1
- data/test/unit/test_balanceInquiry.rb +1 -1
- data/test/unit/test_cancelSubscription.rb +1 -1
- data/test/unit/test_capture.rb +27 -1
- data/test/unit/test_captureGivenAuth.rb +44 -18
- data/test/unit/test_createPlan.rb +1 -1
- data/test/unit/test_credit.rb +16 -3
- data/test/unit/test_deactivate.rb +1 -1
- data/test/unit/test_deactivateReversal.rb +1 -1
- data/test/unit/test_depositReversal.rb +1 -1
- data/test/unit/test_echeckCredit.rb +15 -2
- data/test/unit/test_echeckRedeposit.rb +1 -1
- data/test/unit/test_echeckSale.rb +18 -1
- data/test/unit/test_echeckVerification.rb +1 -1
- data/test/unit/test_echeckVoid.rb +1 -1
- data/test/unit/test_forceCapture.rb +20 -2
- data/test/unit/test_fraudCheck.rb +45 -0
- data/test/unit/test_load.rb +1 -1
- data/test/unit/test_loadReversal.rb +1 -1
- data/test/unit/test_refundReversal.rb +1 -1
- data/test/unit/test_sale.rb +73 -7
- data/test/unit/test_token.rb +15 -4
- data/test/unit/test_unload.rb +1 -1
- data/test/unit/test_unloadReversal.rb +1 -1
- data/test/unit/test_updateCardValidationNumOnToken.rb +1 -1
- data/test/unit/test_updatePlan.rb +1 -1
- data/test/unit/test_updateSubscription.rb +1 -1
- data/test/unit/test_xmlfields.rb +1 -1
- data/test/unit/ts_unit.rb +2 -1
- metadata +10 -7
- data/CHANGELOG~ +0 -142
data/lib/LitleRequest.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2017 Vantiv eCommerce
|
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
|
23
25
|
require_relative 'Configuration'
|
24
26
|
require 'net/sftp'
|
25
27
|
require 'libxml'
|
@@ -28,20 +30,22 @@ require 'socket'
|
|
28
30
|
|
29
31
|
include Socket::Constants
|
30
32
|
#
|
31
|
-
# This class handles sending the Litle Request
|
33
|
+
# This class handles sending the Litle Request
|
34
|
+
# (which is actually a series of batches!)
|
32
35
|
#
|
33
36
|
|
34
37
|
module LitleOnline
|
35
38
|
class LitleRequest
|
36
39
|
include XML::Mapping
|
40
|
+
|
37
41
|
def initialize(options = {})
|
38
|
-
#
|
42
|
+
#load configuration data
|
39
43
|
@config_hash = Configuration.new.config
|
40
44
|
@num_batch_requests = 0
|
41
|
-
@path_to_request =
|
42
|
-
@path_to_batches =
|
45
|
+
@path_to_request = ""
|
46
|
+
@path_to_batches = ""
|
43
47
|
@num_total_transactions = 0
|
44
|
-
@MAX_NUM_TRANSACTIONS =
|
48
|
+
@MAX_NUM_TRANSACTIONS = 500000
|
45
49
|
@options = options
|
46
50
|
# current time out set to 2 mins
|
47
51
|
# this value is in seconds
|
@@ -55,23 +59,29 @@ module LitleOnline
|
|
55
59
|
# Params:
|
56
60
|
# +path+:: A +String+ containing the path to the folder on disc to write the files to
|
57
61
|
def create_new_litle_request(path)
|
58
|
-
ts = Time
|
62
|
+
ts = Time::now.to_i.to_s
|
59
63
|
begin
|
60
|
-
ts += Time
|
64
|
+
ts += Time::now.nsec.to_s
|
61
65
|
rescue NoMethodError # ruby 1.8.7 fix
|
62
|
-
ts += Time
|
66
|
+
ts += Time::now.usec.to_s
|
63
67
|
end
|
64
68
|
|
65
|
-
|
69
|
+
if (File.file?(path)) then
|
70
|
+
raise 'Entered a file not a path.'
|
71
|
+
end
|
66
72
|
|
67
|
-
|
73
|
+
if (path[-1, 1] != '/' and path[-1, 1] != '\\') then
|
74
|
+
path = path + File::SEPARATOR
|
75
|
+
end
|
68
76
|
|
69
|
-
|
77
|
+
if !File.directory?(path) then
|
78
|
+
Dir.mkdir(path)
|
79
|
+
end
|
70
80
|
|
71
81
|
@path_to_request = path + 'request_' + ts
|
72
82
|
@path_to_batches = @path_to_request + '_batches'
|
73
83
|
|
74
|
-
if File.file?(@path_to_request)
|
84
|
+
if File.file?(@path_to_request) or File.file?(@path_to_batches) then
|
75
85
|
create_new_litle_request(path)
|
76
86
|
return
|
77
87
|
end
|
@@ -84,61 +94,66 @@ module LitleOnline
|
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
87
|
-
# Adds a batch to the LitleRequest. If the batch is open when passed,
|
97
|
+
# Adds a batch to the LitleRequest. If the batch is open when passed,
|
98
|
+
# it will be closed prior to being added.
|
88
99
|
# Params:
|
89
|
-
# +arg+:: a +LitleBatchRequest+ containing the transactions you wish to
|
100
|
+
# +arg+:: a +LitleBatchRequest+ containing the transactions you wish to
|
101
|
+
# send or a +String+ specifying the
|
90
102
|
# path to the batch file
|
91
103
|
def commit_batch(arg)
|
92
104
|
path_to_batch = ''
|
93
105
|
# they passed a batch
|
94
|
-
if arg.
|
106
|
+
if arg.kind_of?(LitleBatchRequest) then
|
95
107
|
path_to_batch = arg.get_batch_name
|
96
|
-
if (au = arg.get_au_batch) != nil
|
108
|
+
if ((au = arg.get_au_batch) != nil) then
|
97
109
|
# also commit the account updater batch
|
98
110
|
commit_batch(au)
|
99
111
|
end
|
100
|
-
elsif arg.
|
112
|
+
elsif arg.kind_of?(LitleAUBatch) then
|
101
113
|
path_to_batch = arg.get_batch_name
|
102
|
-
elsif arg.
|
114
|
+
elsif arg.kind_of?(String) then
|
103
115
|
path_to_batch = arg
|
104
116
|
else
|
105
117
|
raise 'You entered neither a path nor a batch. Game over :('
|
106
118
|
end
|
107
119
|
# the batch isn't closed. let's help a brother out
|
108
|
-
if (ind = path_to_batch.index(/\.closed/))
|
109
|
-
if arg.
|
120
|
+
if (ind = path_to_batch.index(/\.closed/)) == nil then
|
121
|
+
if arg.kind_of?(String) then
|
110
122
|
new_batch = LitleBatchRequest.new
|
111
123
|
new_batch.open_existing_batch(path_to_batch)
|
112
|
-
new_batch.close_batch
|
124
|
+
new_batch.close_batch()
|
113
125
|
path_to_batch = new_batch.get_batch_name
|
114
|
-
# if we passed a path to an AU batch, then new_batch will be a new,
|
115
|
-
#
|
116
|
-
|
126
|
+
# if we passed a path to an AU batch, then new_batch will be a new,
|
127
|
+
# empty batch and the batch we passed
|
128
|
+
# will be in the AU batch variable. thus, we wanna grab that file name
|
129
|
+
# and remove the empty batch.
|
130
|
+
if (new_batch.get_au_batch != nil) then
|
117
131
|
File.remove(path_to_batch)
|
118
132
|
path_to_batch = new_batch.get_au_batch.get_batch_name
|
119
133
|
end
|
120
|
-
elsif arg.
|
121
|
-
arg.close_batch
|
134
|
+
elsif arg.kind_of?(LitleBatchRequest) then
|
135
|
+
arg.close_batch()
|
122
136
|
path_to_batch = arg.get_batch_name
|
123
|
-
elsif arg.
|
124
|
-
arg.close_batch
|
137
|
+
elsif arg.kind_of?(LitleAUBatch) then
|
138
|
+
arg.close_batch()
|
125
139
|
path_to_batch = arg.get_batch_name
|
126
140
|
end
|
127
141
|
ind = path_to_batch.index(/\.closed/)
|
128
142
|
end
|
129
|
-
transactions_in_batch = path_to_batch[ind
|
143
|
+
transactions_in_batch = path_to_batch[ind+8..path_to_batch.length].to_i
|
130
144
|
|
131
145
|
# if the litle request would be too big, let's make another!
|
132
|
-
if (@num_total_transactions + transactions_in_batch) > @MAX_NUM_TRANSACTIONS
|
146
|
+
if (@num_total_transactions + transactions_in_batch) > @MAX_NUM_TRANSACTIONS then
|
133
147
|
finish_request
|
134
148
|
initialize(@options)
|
135
149
|
create_new_litle_request
|
136
150
|
else # otherwise, let's add it line by line to the request doc
|
137
151
|
# @num_batch_requests += 1
|
138
|
-
# how long we
|
152
|
+
# how long we want to wait around for the
|
153
|
+
# FTP server to get us a response
|
139
154
|
@RESPONSE_TIME_OUT += 90 + (transactions_in_batch * 0.25)
|
140
155
|
# don't start looking until there could possibly be a response
|
141
|
-
@POLL_DELAY += 30 +
|
156
|
+
@POLL_DELAY += 30 +(transactions_in_batch * 0.02)
|
142
157
|
@num_total_transactions += transactions_in_batch
|
143
158
|
# Don't add empty batches
|
144
159
|
@num_batch_requests += 1 unless transactions_in_batch.eql?(0)
|
@@ -153,22 +168,23 @@ module LitleOnline
|
|
153
168
|
end
|
154
169
|
|
155
170
|
# Adds an RFRRequest to the LitleRequest.
|
156
|
-
# params:
|
157
|
-
# +options+:: a required +Hash+ containing configuration info for the RFRRequest. If the RFRRequest is for a batch, then the
|
171
|
+
# params:
|
172
|
+
# +options+:: a required +Hash+ containing configuration info for the RFRRequest. If the RFRRequest is for a batch, then the
|
158
173
|
# litleSessionId is required as a key/val pair. If the RFRRequest is for account updater, then merchantId and postDay are required
|
159
174
|
# as key/val pairs.
|
160
175
|
# +path+:: optional path to save the new litle request containing the RFRRequest at
|
161
|
-
def add_rfr_request(options, path = File.dirname(@path_to_batches))
|
176
|
+
def add_rfr_request(options, path = (File.dirname(@path_to_batches)))
|
177
|
+
|
162
178
|
rfrrequest = LitleRFRRequest.new
|
163
|
-
if options['litleSessionId']
|
179
|
+
if (options['litleSessionId']) then
|
164
180
|
rfrrequest.litleSessionId = options['litleSessionId']
|
165
|
-
elsif options['merchantId']
|
181
|
+
elsif (options['merchantId'] and options['postDay']) then
|
166
182
|
accountUpdate = AccountUpdateFileRequestData.new
|
167
183
|
accountUpdate.merchantId = options['merchantId']
|
168
184
|
accountUpdate.postDay = options['postDay']
|
169
185
|
rfrrequest.accountUpdateFileRequestData = accountUpdate
|
170
186
|
else
|
171
|
-
raise ArgumentError, "For an RFR Request, you must specify either a litleSessionId for an RFRRequest for batch or a merchantId
|
187
|
+
raise ArgumentError, "For an RFR Request, you must specify either a litleSessionId for an RFRRequest for batch or a merchantId
|
172
188
|
and a postDay for an RFRRequest for account updater."
|
173
189
|
end
|
174
190
|
|
@@ -182,22 +198,29 @@ module LitleOnline
|
|
182
198
|
litleRequest.authentication = authentication
|
183
199
|
litleRequest.numBatchRequests = '0'
|
184
200
|
|
185
|
-
litleRequest.version
|
186
|
-
litleRequest.xmlns
|
201
|
+
litleRequest.version = '9.14'
|
202
|
+
litleRequest.xmlns = 'http://www.litle.com/schema'
|
203
|
+
|
187
204
|
|
188
205
|
xml = litleRequest.save_to_xml.to_s
|
189
206
|
|
190
|
-
ts = Time
|
207
|
+
ts = Time::now.to_i.to_s
|
191
208
|
begin
|
192
|
-
ts += Time
|
209
|
+
ts += Time::now.nsec.to_s
|
193
210
|
rescue NoMethodError # ruby 1.8.7 fix
|
194
|
-
ts += Time
|
211
|
+
ts += Time::now.usec.to_s
|
212
|
+
end
|
213
|
+
if File.file?(path) then
|
214
|
+
raise 'Entered a file not a path.'
|
195
215
|
end
|
196
|
-
raise 'Entered a file not a path.' if File.file?(path)
|
197
216
|
|
198
|
-
|
217
|
+
if (path[-1, 1] != '/' and path[-1, 1] != '\\') then
|
218
|
+
path = path + File::SEPARATOR
|
219
|
+
end
|
199
220
|
|
200
|
-
|
221
|
+
if !File.directory?(path) then
|
222
|
+
Dir.mkdir(path)
|
223
|
+
end
|
201
224
|
|
202
225
|
path_to_request = path + 'request_' + ts
|
203
226
|
|
@@ -215,37 +238,40 @@ module LitleOnline
|
|
215
238
|
# provided, then we use the directory where the current working batches file is stored.
|
216
239
|
# +options+:: An (option) +Hash+ containing the username, password, and URL to attempt to sFTP to.
|
217
240
|
# If not provided, the values will be populated from the configuration file.
|
218
|
-
def send_to_litle(path = File.dirname(@path_to_batches), options = {})
|
241
|
+
def send_to_litle(path = (File.dirname(@path_to_batches)), options = {})
|
219
242
|
username = get_config(:sftp_username, options)
|
220
243
|
password = get_config(:sftp_password, options)
|
221
244
|
|
222
245
|
url = get_config(:sftp_url, options)
|
223
246
|
|
224
|
-
if username
|
247
|
+
if username == nil or password == nil or url == nil then
|
225
248
|
raise ArgumentError, 'You are not configured to use sFTP for batch processing. Please run /bin/Setup.rb again!'
|
226
249
|
end
|
227
250
|
|
228
|
-
|
251
|
+
if (path[-1, 1] != '/' && path[-1, 1] != '\\') then
|
252
|
+
path = path + File::SEPARATOR
|
253
|
+
end
|
229
254
|
|
230
255
|
begin
|
231
|
-
Net::SFTP.start(url, username, password
|
256
|
+
Net::SFTP.start(url, username, :password => password) do |sftp|
|
257
|
+
|
232
258
|
# our folder is /SHORTNAME/SHORTNAME/INBOUND
|
233
259
|
Dir.foreach(path) do |filename|
|
234
260
|
# we have a complete report according to filename regex
|
235
|
-
if (filename =~ /request_\d+.complete\z/) != nil
|
236
|
-
# adding .prg extension per the XML
|
261
|
+
if (filename =~ /request_\d+.complete\z/) != nil then
|
262
|
+
# adding .prg extension per the XML
|
237
263
|
File.rename(path + filename, path + filename + '.prg')
|
238
264
|
end
|
239
265
|
end
|
240
266
|
|
241
267
|
@responses_expected = 0
|
242
268
|
Dir.foreach(path) do |filename|
|
243
|
-
if (filename =~ /request_\d+.complete.prg\z/) != nil
|
269
|
+
if (filename =~ /request_\d+.complete.prg\z/) != nil then
|
244
270
|
# upload the file
|
245
271
|
sftp.upload!(path + filename, '/inbound/' + filename)
|
246
272
|
@responses_expected += 1
|
247
273
|
# rename now that we're done
|
248
|
-
sftp.rename!('/inbound/'
|
274
|
+
sftp.rename!('/inbound/'+ filename, '/inbound/' + filename.gsub('prg', 'asc'))
|
249
275
|
File.rename(path + filename, path + filename.gsub('prg', 'sent'))
|
250
276
|
end
|
251
277
|
end
|
@@ -258,34 +284,38 @@ module LitleOnline
|
|
258
284
|
# Sends all previously unsent LitleRequests in the specified directory to the Litle server
|
259
285
|
# by use of fast batch. All results will be written to disk as we get them. Note that use
|
260
286
|
# of fastbatch is strongly discouraged!
|
261
|
-
def send_to_litle_stream(options = {}, path = File.dirname(@path_to_batches))
|
287
|
+
def send_to_litle_stream(options = {}, path = (File.dirname(@path_to_batches)))
|
262
288
|
url = get_config(:fast_url, options)
|
263
289
|
port = get_config(:fast_port, options)
|
264
290
|
|
265
|
-
if url
|
291
|
+
if url == nil or url == '' then
|
266
292
|
raise ArgumentError, 'A URL for fastbatch was not specified in the config file or passed options. Reconfigure and try again.'
|
267
293
|
end
|
268
294
|
|
269
|
-
if port ==
|
295
|
+
if (port == "" or port == nil) then
|
270
296
|
raise ArgumentError, 'A port number for fastbatch was not specified in the config file or passed options. Reconfigure and try again.'
|
271
297
|
end
|
272
298
|
|
273
|
-
|
299
|
+
if (path[-1, 1] != '/' && path[-1, 1] != '\\') then
|
300
|
+
path = path + File::SEPARATOR
|
301
|
+
end
|
274
302
|
|
275
|
-
|
303
|
+
if (!File.directory?(path + 'responses/')) then
|
304
|
+
Dir.mkdir(path + 'responses/')
|
305
|
+
end
|
276
306
|
|
277
307
|
Dir.foreach(path) do |filename|
|
278
|
-
if (filename =~ /request_\d+.complete\z/) != nil
|
308
|
+
if ((filename =~ /request_\d+.complete\z/) != nil) then
|
279
309
|
begin
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
310
|
+
socket = TCPSocket.open(url, port.to_i)
|
311
|
+
ssl_context = OpenSSL::SSL::SSLContext.new()
|
312
|
+
ssl_context.ssl_version = :SSLv23
|
313
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
314
|
+
ssl_socket.sync_close = true
|
315
|
+
ssl_socket.connect
|
316
|
+
rescue => e
|
317
|
+
raise 'A connection could not be established. Are you sure you have the correct credentials? Exception: ' + e.message
|
318
|
+
end
|
289
319
|
|
290
320
|
File.foreach(path + filename) do |li|
|
291
321
|
ssl_socket.puts li
|
@@ -294,13 +324,14 @@ module LitleOnline
|
|
294
324
|
File.open(path + 'responses/' + (filename + '.asc.received').gsub('request', 'response'), 'a+') do |fo|
|
295
325
|
while line = ssl_socket.gets
|
296
326
|
fo.puts(line)
|
297
|
-
|
327
|
+
end
|
298
328
|
end
|
299
329
|
|
300
330
|
end
|
301
331
|
end
|
302
332
|
end
|
303
333
|
|
334
|
+
|
304
335
|
# Grabs response files over SFTP from Litle.
|
305
336
|
# Params:
|
306
337
|
# +args+:: An (optional) +Hash+ containing values for the number of responses expected, the
|
@@ -314,24 +345,26 @@ module LitleOnline
|
|
314
345
|
password = get_config(:sftp_password, args)
|
315
346
|
url = get_config(:sftp_url, args)
|
316
347
|
|
317
|
-
if username
|
348
|
+
if (username == nil or password == nil or url == nil) then
|
318
349
|
raise ConfigurationException, 'You are not configured to use sFTP for batch processing. Please run /bin/Setup.rb again!'
|
319
350
|
end
|
320
351
|
|
321
|
-
if response_path[-1, 1] != '/' && response_path[-1, 1] != '\\'
|
322
|
-
response_path
|
352
|
+
if (response_path[-1, 1] != '/' && response_path[-1, 1] != '\\') then
|
353
|
+
response_path = response_path + File::SEPARATOR
|
323
354
|
end
|
324
355
|
|
325
|
-
|
356
|
+
if (!File.directory?(response_path)) then
|
357
|
+
Dir.mkdir(response_path)
|
358
|
+
end
|
326
359
|
begin
|
327
360
|
responses_grabbed = 0
|
328
|
-
Net::SFTP.start(url, username, password
|
361
|
+
Net::SFTP.start(url, username, :password => password) do |sftp|
|
329
362
|
# clear out the sFTP outbound dir prior to checking for new files, avoids leaving files on the server
|
330
363
|
# if files are left behind we are not counting then towards the expected total
|
331
364
|
sftp.dir.foreach('/outbound/') do |entry|
|
332
|
-
if (entry.name =~ /request_\d+.complete.asc\z/) != nil
|
365
|
+
if ((entry.name =~ /request_\d+.complete.asc\z/) != nil) then
|
333
366
|
sftp.download!('/outbound/' + entry.name, response_path + entry.name.gsub('request', 'response') + '.received')
|
334
|
-
3.times
|
367
|
+
3.times {
|
335
368
|
begin
|
336
369
|
sftp.remove!('/outbound/' + entry.name)
|
337
370
|
break
|
@@ -339,22 +372,22 @@ module LitleOnline
|
|
339
372
|
# try, try, try again
|
340
373
|
puts "We couldn't remove it! Try again"
|
341
374
|
end
|
342
|
-
|
375
|
+
}
|
343
376
|
end
|
344
377
|
end
|
345
378
|
end
|
346
379
|
# wait until a response has a possibility of being there
|
347
380
|
sleep(@POLL_DELAY)
|
348
381
|
time_begin = Time.now
|
349
|
-
Net::SFTP.start(url, username, password
|
350
|
-
while (Time.now - time_begin) < @RESPONSE_TIME_OUT && responses_grabbed < @responses_expected
|
382
|
+
Net::SFTP.start(url, username, :password => password) do |sftp|
|
383
|
+
while ((Time.now - time_begin) < @RESPONSE_TIME_OUT && responses_grabbed < @responses_expected)
|
351
384
|
# sleep for 60 seconds, ¿no es bueno?
|
352
385
|
sleep(60)
|
353
386
|
sftp.dir.foreach('/outbound/') do |entry|
|
354
|
-
if (entry.name =~ /request_\d+.complete.asc\z/) != nil
|
387
|
+
if ((entry.name =~ /request_\d+.complete.asc\z/) != nil) then
|
355
388
|
sftp.download!('/outbound/' + entry.name, response_path + entry.name.gsub('request', 'response') + '.received')
|
356
389
|
responses_grabbed += 1
|
357
|
-
3.times
|
390
|
+
3.times {
|
358
391
|
begin
|
359
392
|
sftp.remove!('/outbound/' + entry.name)
|
360
393
|
break
|
@@ -362,12 +395,12 @@ module LitleOnline
|
|
362
395
|
# try, try, try again
|
363
396
|
puts "We couldn't remove it! Try again"
|
364
397
|
end
|
365
|
-
|
398
|
+
}
|
366
399
|
end
|
367
400
|
end
|
368
401
|
end
|
369
402
|
# if our timeout timed out, we're having problems
|
370
|
-
if responses_grabbed < @responses_expected
|
403
|
+
if responses_grabbed < @responses_expected then
|
371
404
|
raise 'We timed out in waiting for a response from the server. :('
|
372
405
|
end
|
373
406
|
end
|
@@ -382,7 +415,7 @@ module LitleOnline
|
|
382
415
|
# custom path where response files from the server are located (if it is not provided, we'll guess the position)
|
383
416
|
def process_responses(args)
|
384
417
|
# the transaction listener is required
|
385
|
-
|
418
|
+
if (!args.has_key?(:transaction_listener)) then
|
386
419
|
raise ArgumentError, 'The arguments hash must contain an entry for transaction listener!'
|
387
420
|
end
|
388
421
|
|
@@ -391,7 +424,7 @@ module LitleOnline
|
|
391
424
|
path_to_responses = args[:path_to_responses] ||= (File.dirname(@path_to_batches) + '/responses/')
|
392
425
|
|
393
426
|
Dir.foreach(path_to_responses) do |filename|
|
394
|
-
if (filename =~ /response_\d+.complete.asc.received\z/) != nil
|
427
|
+
if (filename =~ /response_\d+.complete.asc.received\z/) != nil then
|
395
428
|
process_response(path_to_responses + filename, transaction_listener, batch_listener)
|
396
429
|
File.rename(path_to_responses + filename, path_to_responses + filename + '.processed')
|
397
430
|
end
|
@@ -400,53 +433,56 @@ module LitleOnline
|
|
400
433
|
|
401
434
|
# Params:
|
402
435
|
# +path_to_response+:: The path to a specific .asc file to process
|
403
|
-
# +transaction_listener+:: A listener to be applied to the hash of each transaction
|
436
|
+
# +transaction_listener+:: A listener to be applied to the hash of each transaction
|
404
437
|
# (see +DefaultLitleListener+)
|
405
|
-
# +batch_listener+:: An (optional) listener to be applied to the hash of each batch.
|
406
|
-
# Note that this will om-nom-nom quite a bit of memory
|
407
|
-
def process_response(path_to_response, transaction_listener,
|
438
|
+
# +batch_listener+:: An (optional) listener to be applied to the hash of each batch.
|
439
|
+
# Note that this will om-nom-nom quite a bit of memory
|
440
|
+
def process_response(path_to_response, transaction_listener, batch_listener = nil)
|
408
441
|
reader = LibXML::XML::Reader.file(path_to_response)
|
409
442
|
reader.read # read into the root node
|
410
443
|
# if the response attribute is nil, we're dealing with an RFR and everything is a-okay
|
411
|
-
if reader.get_attribute('response') != '0'
|
444
|
+
if reader.get_attribute('response') != '0' and reader.get_attribute('response') != nil then
|
412
445
|
raise 'Error parsing Litle Request: ' + reader.get_attribute('message')
|
413
446
|
end
|
414
447
|
|
415
448
|
reader.read
|
416
449
|
count = 0
|
417
|
-
while true
|
450
|
+
while true and count < 500001 do
|
418
451
|
|
419
452
|
count += 1
|
420
|
-
|
453
|
+
if reader.node == nil then
|
454
|
+
return false
|
455
|
+
end
|
421
456
|
|
422
457
|
case reader.node.name.to_s
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
458
|
+
when 'batchResponse'
|
459
|
+
reader.read
|
460
|
+
when 'litleResponse'
|
461
|
+
return false
|
462
|
+
when 'text'
|
463
|
+
reader.read
|
464
|
+
else
|
465
|
+
xml = reader.read_outer_xml
|
466
|
+
duck = Crack::XML.parse(xml)
|
467
|
+
duck[duck.keys[0]]['type'] = duck.keys[0]
|
468
|
+
duck = duck[duck.keys[0]]
|
469
|
+
transaction_listener.apply(duck)
|
470
|
+
reader.next
|
436
471
|
end
|
437
472
|
end
|
438
473
|
end
|
439
474
|
|
440
475
|
def get_path_to_batches
|
441
|
-
@path_to_batches
|
476
|
+
return @path_to_batches
|
442
477
|
end
|
443
478
|
|
444
|
-
# Called when you wish to finish adding batches to your request, this method
|
445
|
-
# batch file to the final LitleRequest xml doc
|
479
|
+
# Called when you wish to finish adding batches to your request, this method
|
480
|
+
# rewrites the aggregate batch file to the final LitleRequest xml doc
|
481
|
+
# with the appropos LitleRequest tags.
|
446
482
|
def finish_request
|
447
483
|
File.open(@path_to_request, 'w') do |f|
|
448
484
|
# jam dat header in there
|
449
|
-
f.puts(build_request_header)
|
485
|
+
f.puts(build_request_header())
|
450
486
|
# read into the request file from the batches file
|
451
487
|
File.foreach(@path_to_batches) do |li|
|
452
488
|
f.puts li
|
@@ -471,23 +507,24 @@ module LitleOnline
|
|
471
507
|
authentication.password = get_config(:password, options)
|
472
508
|
|
473
509
|
litle_request.authentication = authentication
|
474
|
-
litle_request.version
|
475
|
-
litle_request.xmlns
|
476
|
-
# litle_request.id = options['sessionId']
|
510
|
+
litle_request.version = '9.14'
|
511
|
+
litle_request.xmlns = 'http://www.litle.com/schema'
|
512
|
+
# litle_request.id = options['sessionId']
|
513
|
+
# grab from options; okay if nil
|
477
514
|
litle_request.numBatchRequests = @num_batch_requests
|
478
515
|
|
479
516
|
xml = litle_request.save_to_xml.to_s
|
480
517
|
xml[/<\/litleRequest>/] = ''
|
481
|
-
xml
|
518
|
+
return xml
|
482
519
|
end
|
483
520
|
|
484
521
|
def get_config(field, options)
|
485
|
-
if options[field.to_s]
|
486
|
-
@config_hash[field.to_s]
|
487
|
-
elsif
|
488
|
-
options[field.to_s]
|
522
|
+
if options[field.to_s] == nil and options[field] == nil then
|
523
|
+
return @config_hash[field.to_s]
|
524
|
+
elsif options[field.to_s] != nil then
|
525
|
+
return options[field.to_s]
|
489
526
|
else
|
490
|
-
options[field]
|
527
|
+
return options[field]
|
491
528
|
end
|
492
529
|
end
|
493
530
|
end
|