CnpOnline 9.14.0 → 11.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -7
  2. data/CHANGELOG +23 -17
  3. data/CONTRIBUTORS +0 -0
  4. data/DESCRIPTION +1 -1
  5. data/LICENSE +1 -1
  6. data/README.md +5 -3
  7. data/Rakefile +5 -5
  8. data/Rakefile~ +5 -5
  9. data/SETUP.md +3 -3
  10. data/bin/Setup.rb +59 -41
  11. data/lib/Communications.rb +3 -3
  12. data/lib/Configuration.rb +52 -45
  13. data/lib/EnvironmentVariables.rb +5 -1
  14. data/lib/LitleBatchRequest.rb +72 -7
  15. data/lib/LitleListeners.rb +17 -1
  16. data/lib/LitleOnline.rb +3 -4
  17. data/lib/LitleOnlineRequest.rb +37 -7
  18. data/lib/LitleRequest.rb +315 -186
  19. data/lib/LitleTransaction.rb +212 -85
  20. data/lib/LitleXmlMapper.rb +4 -2
  21. data/lib/XMLFields.rb +384 -171
  22. data/lib/cacert.pem +0 -0
  23. data/samples/Auth/LitleAuthReversalTransaction.rb +2 -2
  24. data/samples/Auth/LitleAuthorizationTransaction.rb +1 -0
  25. data/samples/Auth/LitlePaymentFullLifeCycle.rb +12 -6
  26. data/samples/Batch/AccountUpdate.rb +1 -0
  27. data/samples/Batch/SampleBatchDriver.rb +2 -1
  28. data/samples/Capture/LitleCaptureGivenAuthTransaction.rb +2 -1
  29. data/samples/Capture/LitleCaptureTransaction.rb +2 -2
  30. data/samples/Capture/LitleForceCaptureTransaction.rb +2 -1
  31. data/samples/Capture/LitlePartialCapture.rb +3 -3
  32. data/samples/Credit/LitleCreditTransaction.rb +2 -2
  33. data/samples/Credit/LitleRefundTransaction.rb +2 -1
  34. data/samples/Other/LitleAvsTransaction.rb +2 -1
  35. data/samples/Other/LitleVoidTransaction.rb +2 -1
  36. data/samples/Paypage/FullPaypageLifeCycle.rb +7 -2
  37. data/samples/Run_all.rb +0 -0
  38. data/samples/Sale/LitleSaleTransaction.rb +2 -1
  39. data/samples/Sale/SampleSaleTransaction.rb +2 -1
  40. data/test/certification/certTest1_base.rb +52 -53
  41. data/test/certification/certTest2_authenhanced.rb +24 -25
  42. data/test/certification/certTest3_authreversal.rb +23 -26
  43. data/test/certification/certTest4_echeck.rb +18 -32
  44. data/test/certification/certTest5_token.rb +105 -106
  45. data/test/certification/certTest_batchAll.rb +47 -15
  46. data/test/functional/test_activate.rb +32 -4
  47. data/test/functional/test_activateReversal.rb +18 -5
  48. data/test/functional/test_auth.rb +94 -48
  49. data/test/functional/test_authReversal.rb +4 -1
  50. data/test/functional/test_balanceInquiry.rb +28 -3
  51. data/test/functional/test_batchStream.rb +2 -4
  52. data/test/functional/test_cancelSubscription.rb +2 -2
  53. data/test/functional/test_capture.rb +21 -14
  54. data/test/functional/test_captureGivenAuth.rb +15 -6
  55. data/test/functional/test_createPlan.rb +1 -1
  56. data/test/functional/test_credit.rb +14 -5
  57. data/test/functional/test_deactivate.rb +26 -3
  58. data/test/functional/test_deactivateReversal.rb +18 -5
  59. data/test/functional/test_depositReversal.rb +31 -19
  60. data/test/functional/test_echeckCredit.rb +34 -6
  61. data/test/functional/test_echeckRedeposit.rb +29 -2
  62. data/test/functional/test_echeckSale.rb +68 -11
  63. data/test/functional/test_echeckVerification.rb +32 -7
  64. data/test/functional/test_echeckVoid.rb +2 -1
  65. data/test/functional/test_forceCapture.rb +20 -6
  66. data/test/functional/test_fraudCheck.rb +3 -5
  67. data/test/functional/test_giftCardAuthReversal.rb +72 -0
  68. data/test/functional/test_giftCardCapture.rb +72 -0
  69. data/test/functional/test_giftCardCredit.rb +69 -0
  70. data/test/functional/test_litle_requests.rb +3 -6
  71. data/test/functional/test_load.rb +27 -3
  72. data/test/functional/test_loadReversal.rb +18 -5
  73. data/test/functional/test_override.rb +7 -3
  74. data/test/functional/test_pgp_litle_requests.rb +294 -0
  75. data/test/functional/test_queryTransaction.rb +152 -0
  76. data/test/functional/test_refundReversal.rb +18 -5
  77. data/test/functional/test_sale.rb +122 -159
  78. data/test/functional/test_token.rb +17 -11
  79. data/test/functional/test_unload.rb +27 -3
  80. data/test/functional/test_unloadReversal.rb +18 -5
  81. data/test/functional/test_updateCardValidationNumOnToken.rb +1 -0
  82. data/test/functional/test_updatePlan.rb +2 -1
  83. data/test/functional/test_updateSubscription.rb +3 -1
  84. data/test/functional/test_wallet.rb +74 -0
  85. data/test/functional/test_xmlfields.rb +22 -3
  86. data/test/functional/ts_all.rb +2 -0
  87. data/test/unit/test_LitleBatchRequest.rb +53 -5
  88. data/test/unit/test_LitleOnlineRequest.rb +5 -30
  89. data/test/unit/test_LitleRequest.rb +7 -6
  90. data/test/unit/test_LitleTransaction.rb +34 -5
  91. data/test/unit/test_LitleXmlMapper.rb +3 -0
  92. data/test/unit/test_activate.rb +22 -2
  93. data/test/unit/test_activateReversal.rb +15 -3
  94. data/test/unit/test_auth.rb +11 -9
  95. data/test/unit/test_balanceInquiry.rb +2 -2
  96. data/test/unit/test_capture.rb +2 -2
  97. data/test/unit/test_captureGivenAuth.rb +21 -1
  98. data/test/unit/test_credit.rb +1 -1
  99. data/test/unit/test_deactivate.rb +19 -0
  100. data/test/unit/test_deactivateReversal.rb +15 -3
  101. data/test/unit/test_depositReversal.rb +17 -5
  102. data/test/unit/test_echeckCredit.rb +19 -0
  103. data/test/unit/test_echeckRedeposit.rb +15 -0
  104. data/test/unit/test_echeckSale.rb +20 -1
  105. data/test/unit/test_echeckVerification.rb +6 -3
  106. data/test/unit/test_forceCapture.rb +1 -1
  107. data/test/unit/test_giftCardAuthReversal.rb +58 -0
  108. data/test/{functional/test_utf8.rb → unit/test_giftCardCapture.rb} +25 -12
  109. data/test/unit/test_giftCardCredit.rb +57 -0
  110. data/test/unit/test_load.rb +2 -2
  111. data/test/unit/test_loadReversal.rb +15 -3
  112. data/test/unit/test_pgp_LitleRequest +139 -0
  113. data/test/unit/test_queryTransaction.rb +105 -0
  114. data/test/unit/test_refundReversal.rb +15 -3
  115. data/test/unit/test_sale.rb +23 -3
  116. data/test/unit/test_token.rb +24 -20
  117. data/test/unit/test_unload.rb +2 -2
  118. data/test/unit/test_unloadReversal.rb +15 -3
  119. data/test/unit/test_wallet.rb +262 -0
  120. data/test/unit/ts_unit.rb +2 -1
  121. metadata +81 -100
@@ -1,6 +1,5 @@
1
1
  =begin
2
2
  Copyright (c) 2017 Vantiv eCommerce
3
-
4
3
  Permission is hereby granted, free of charge, to any person
5
4
  obtaining a copy of this software and associated documentation
6
5
  files (the "Software"), to deal in the Software without
@@ -9,10 +8,8 @@ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
8
  copies of the Software, and to permit persons to whom the
10
9
  Software is furnished to do so, subject to the following
11
10
  conditions:
12
-
13
11
  The above copyright notice and this permission notice shall be
14
12
  included in all copies or substantial portions of the Software.
15
-
16
13
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
14
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
15
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -198,8 +195,8 @@ module LitleOnline
198
195
 
199
196
  entries = Dir.entries(dir + '/litle-sdk-for-ruby-test')
200
197
  entries.sort!
201
-
202
198
  assert_equal 3, entries.size
199
+ puts entries[2]
203
200
  assert_not_nil entries[2] =~ /request_\d+.complete.sent\z/
204
201
 
205
202
  uploaded_file = entries[2]
@@ -247,6 +244,7 @@ module LitleOnline
247
244
 
248
245
  assert_equal 3, entries.size
249
246
  assert_not_nil entries[2] =~ /response_\d+.complete.asc.received\z/
247
+
250
248
  end
251
249
 
252
250
  def test_full_flow
@@ -340,7 +338,6 @@ module LitleOnline
340
338
  entries.sort!
341
339
  assert_equal 3, entries.length
342
340
  assert_not_nil entries[2] =~ /response_\d+.complete.asc.received.processed\z/
343
-
344
341
  end
345
342
 
346
343
  def get_config(field, options)
@@ -353,4 +350,4 @@ module LitleOnline
353
350
  end
354
351
  end
355
352
  end
356
- end
353
+ end
@@ -33,12 +33,13 @@ def test_simple_happy
33
33
  hash = {
34
34
  'merchantId' => '101',
35
35
  'version'=>'8.8',
36
+ 'id'=>'test',
36
37
  'reportGroup'=>'Planets',
37
38
  'orderId' =>'1001',
38
39
  'amount' =>'500',
39
40
  'orderSource' =>'ecommerce',
40
41
  'card'=>{
41
- 'type'=>'VI',
42
+ 'type'=>'GC',
42
43
  'number' =>'4100000000000001',
43
44
  'expDate' =>'1210'
44
45
  }
@@ -52,12 +53,13 @@ def test_simple_happy
52
53
  hash = {
53
54
  'merchantId' => '101',
54
55
  'version'=>'8.8',
56
+ 'id'=>'test',
55
57
  'reportGroup'=>'Planets',
56
58
  'amount' =>'500',
57
59
  'orderId' =>'1001',
58
60
  'orderSource' =>'ecommerce',
59
61
  'card'=>{
60
- 'type'=>'VI',
62
+ 'type'=>'GC',
61
63
  'number' =>'4100000000000001',
62
64
  'expDate' =>'1210'
63
65
  }
@@ -78,7 +80,29 @@ def test_simple_happy
78
80
  #Get exceptions
79
81
  exception = assert_raise(RuntimeError){LitleOnlineRequest.new.load_request(hash)}
80
82
  #Test
81
- assert(exception.message =~ /Error validating xml data against the schema/)
83
+ assert(exception.message =~ /Error validating xml data against the schema/)
84
+ end
85
+
86
+ def test_GiftCardCardType_NotPresent
87
+ hash = {
88
+ 'merchantId' => '101',
89
+ 'version'=>'8.8',
90
+ 'id' =>'test',
91
+ 'reportGroup'=>'Planets',
92
+ 'amount' =>'500',
93
+ 'orderId' =>'1001',
94
+ 'orderSource' =>'ecommerce',
95
+ 'card'=>{
96
+ 'type'=>'VI',
97
+ 'number' =>'4100000000000001',
98
+ 'expDate' =>'1210'
99
+ }
100
+ }
101
+
102
+ #Get exceptions
103
+ exception = assert_raise(RuntimeError){LitleOnlineRequest.new.load_request(hash)}
104
+ #Test
105
+ assert(exception.message =~ /Error validating xml data against the schema/)
82
106
  end
83
107
  end
84
108
  end
@@ -33,12 +33,25 @@ def test_simple
33
33
  hash = {
34
34
  'merchantId' => '101',
35
35
  'version'=>'8.8',
36
+ 'id'=>'test',
36
37
  'reportGroup'=>'Planets',
37
- 'litleTxnId' =>'5000'
38
- }
38
+ 'litleTxnId' =>'5000',
39
+ 'card'=>{
40
+ 'type'=>'GC',
41
+ 'number' =>'400000000000001',
42
+ 'expDate' =>'0150',
43
+ 'pin' => '1234',
44
+ 'cardValidationNum' => '411'
45
+ },
46
+ 'originalRefCode' => '101',
47
+ 'originalAmount' => '34561',
48
+ 'originalTxnTime' => '2017-01-24T09:00:00',
49
+ 'originalSystemTraceId' => '33',
50
+ 'originalSequenceNumber' => '111111',
51
+ }
39
52
 
40
- response= LitleOnlineRequest.new.load_reversal(hash)
41
- assert_equal('Valid Format', response.message)
53
+ response= LitleOnlineRequest.new.deposit_reversal(hash)
54
+ assert_equal('000', response.depositReversalResponse.response)
42
55
  end
43
56
 
44
57
 
@@ -52,7 +65,7 @@ def test_simple
52
65
  #Get exceptions
53
66
  exception = assert_raise(RuntimeError){LitleOnlineRequest.new.load_reversal(hash)}
54
67
  #Test
55
- assert(exception.message =~ /Error validating xml data against the schema/)
68
+ assert(exception.message =~ /Error validating xml data against the schema/)
56
69
  end
57
70
  end
58
71
  end
@@ -7,12 +7,13 @@ module LitleOnline
7
7
  def test_override_withoutLocalAndEnv
8
8
  hash = {
9
9
  'merchantId' => '101',
10
+ 'id' => 'test',
10
11
  'version'=>'8.8',
11
12
  'orderId' =>'1001',
12
13
  'amount' =>'500',
13
14
  'orderSource' =>'ecommerce',
14
15
  'card'=>{
15
- 'type'=>'VI',
16
+ 'type'=>'GC',
16
17
  'number' =>'4100000000000001',
17
18
  'expDate' =>'1210'
18
19
  }
@@ -20,15 +21,17 @@ module LitleOnline
20
21
  response= LitleOnlineRequest.new.activate(hash)
21
22
  assert_equal('Default Report Group', response.activateResponse.reportGroup)
22
23
  end
24
+
23
25
  def test_override_withoutLocal
24
26
  hash = {
25
27
  'merchantId' => '101',
28
+ 'id' => 'test',
26
29
  'version'=>'8.8',
27
30
  'orderId' =>'1001',
28
31
  'amount' =>'500',
29
32
  'orderSource' =>'ecommerce',
30
33
  'card'=>{
31
- 'type'=>'VI',
34
+ 'type'=>'GC',
32
35
  'number' =>'4100000000000001',
33
36
  'expDate' =>'1210'
34
37
  }
@@ -42,13 +45,14 @@ module LitleOnline
42
45
  def test_override
43
46
  hash = {
44
47
  'merchantId' => '101',
48
+ 'id' => 'test',
45
49
  'version'=>'8.8',
46
50
  'reportGroup'=>'Planets',
47
51
  'orderId' =>'1001',
48
52
  'amount' =>'500',
49
53
  'orderSource' =>'ecommerce',
50
54
  'card'=>{
51
- 'type'=>'VI',
55
+ 'type'=>'GC',
52
56
  'number' =>'4100000000000001',
53
57
  'expDate' =>'1210'
54
58
  }
@@ -0,0 +1,294 @@
1
+ require File.expand_path("../../../lib/LitleOnline",__FILE__)
2
+ require 'test/unit'
3
+ require 'fileutils'
4
+
5
+ LITLE_SDK_TEST_FOLDER = '/litle-sdk-for-ruby-test'
6
+
7
+ module LitleOnline
8
+ class TestPgpLitleRequest < Test::Unit::TestCase
9
+
10
+ def setup
11
+ dir = '/tmp/litle-sdk-for-ruby-test'
12
+ FileUtils.rm_rf dir
13
+ Dir.mkdir dir
14
+
15
+ end
16
+
17
+ def test_send_to_litle
18
+ ENV['litle_deleteBatchFiles'] = 'false'
19
+ config_dir = ENV['LITLE_CONFIG_DIR']
20
+ ENV['LITLE_CONFIG_DIR'] = '/tmp/pgp_ruby'
21
+
22
+ @config_hash = Configuration.new.config
23
+
24
+ dir = '/tmp'
25
+
26
+ request = LitleRequest.new()
27
+ ENV['LITLE_CONFIG_DIR'] = config_dir
28
+ request.create_new_litle_request(dir + LITLE_SDK_TEST_FOLDER)
29
+ request.finish_request
30
+
31
+
32
+
33
+ request.send_to_litle()
34
+
35
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
36
+ encrypted_entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
37
+ entries.sort!
38
+ assert_equal 4, entries.size
39
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
40
+ encrypted_entries.sort!
41
+ assert_equal 3, encrypted_entries.size
42
+ assert_not_nil encrypted_entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{ENCRYPTED_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
43
+
44
+ uploaded_file = encrypted_entries[2]
45
+
46
+ options = {}
47
+ username = get_config(:sftp_username, options)
48
+ password = get_config(:sftp_password, options)
49
+ url = get_config(:sftp_url, options)
50
+
51
+ Net::SFTP.start(url, username, :password => password) do |sftp|
52
+ # clear out the sFTP outbound dir prior to checking for new files, avoids leaving files on the server
53
+ # if files are left behind we are not counting then towards the expected total
54
+ ents = []
55
+ handle = sftp.opendir!('/inbound/')
56
+ files_on_srv = sftp.readdir!(handle)
57
+ files_on_srv.each {|file|
58
+ ents.push(file.name)
59
+ }
60
+ assert_equal 3,ents.size
61
+ ents.sort!
62
+ assert_equal ents[2], uploaded_file.gsub(SENT_FILE_SUFFIX, '.asc')
63
+ sftp.remove('/inbound/' + ents[2])
64
+ end
65
+ end
66
+
67
+ def test_full_flow
68
+ ENV['litle_deleteBatchFiles'] = 'false'
69
+ config_dir = ENV['LITLE_CONFIG_DIR']
70
+ ENV['LITLE_CONFIG_DIR'] = '/tmp/pgp_ruby'
71
+
72
+ saleHash = {
73
+ 'reportGroup'=>'Planets',
74
+ 'id' => '006',
75
+ 'orderId'=>'12344',
76
+ 'amount'=>'6000',
77
+ 'orderSource'=>'ecommerce',
78
+ 'card'=>{
79
+ 'type'=>'VI',
80
+ 'number' =>'4100000000000001',
81
+ 'expDate' =>'1210'
82
+ }}
83
+
84
+ dir = '/tmp'
85
+
86
+ request = LitleRequest.new()
87
+ ENV['LITLE_CONFIG_DIR'] = config_dir
88
+ request.create_new_litle_request(dir + LITLE_SDK_TEST_FOLDER)
89
+
90
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
91
+ entries.sort!
92
+
93
+ assert_equal 4, entries.size
94
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
95
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
96
+
97
+ #create five batches, each with 10 sales
98
+ 5.times{
99
+ batch = LitleBatchRequest.new
100
+ batch.create_new_batch(dir + LITLE_SDK_TEST_FOLDER)
101
+
102
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
103
+
104
+ assert_equal 6, entries.length
105
+ entries.sort!
106
+ assert_not_nil entries[2] =~ /batch_\d+\z/
107
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
108
+ assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
109
+ assert_not_nil entries[5] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
110
+ #add the same sale ten times
111
+ 10.times{
112
+ #batch.account_update(accountUpdateHash)
113
+ saleHash['card']['number']= (saleHash['card']['number'].to_i + 1).to_s
114
+ batch.sale(saleHash)
115
+ }
116
+
117
+ #close the batch, indicating we plan to add no more transactions
118
+ batch.close_batch()
119
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
120
+
121
+ assert_equal 5, entries.length
122
+ entries.sort!
123
+ assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
124
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
125
+ assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
126
+
127
+ #add the batch to the LitleRequest
128
+ request.commit_batch(batch)
129
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
130
+ assert_equal 4, entries.length
131
+ entries.sort!
132
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
133
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
134
+ }
135
+ #finish the Litle Request, indicating we plan to add no more batches
136
+ request.finish_request
137
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
138
+ assert_equal 3, entries.length
139
+ entries.sort!
140
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+.complete\z/
141
+
142
+ #send the batch files at the given directory over sFTP
143
+
144
+ request.send_to_litle()
145
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
146
+ encrypted_entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
147
+
148
+ assert_equal entries.length, 4
149
+ entries.sort!
150
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
151
+ encrypted_entries.sort!
152
+ assert_not_nil encrypted_entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{ENCRYPTED_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
153
+
154
+
155
+
156
+ #grab the expected number of responses from the sFTP server and save them to the given path
157
+ request.get_responses_from_server()
158
+ #process the responses from the server with a listener which applies the given block
159
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction| end})
160
+
161
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
162
+
163
+ assert_equal 5, entries.length
164
+ entries.sort!
165
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
166
+ File.delete(dir + LITLE_SDK_TEST_FOLDER + '/' + entries[3])
167
+
168
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + entries[4])
169
+ entries.sort!
170
+ assert_equal 4, entries.length
171
+ assert_not_nil entries[3] =~ /#{RESPONSE_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}.asc#{RECEIVED_FILE_SUFFIX}.processed\z/
172
+ end
173
+
174
+
175
+ def test_full_flow_with_deleteBatchFiles
176
+ ENV['litle_deleteBatchFiles'] = 'true'
177
+ config_dir = ENV['LITLE_CONFIG_DIR']
178
+ ENV['LITLE_CONFIG_DIR'] = '/tmp/pgp_ruby'
179
+
180
+ saleHash = {
181
+ 'reportGroup'=>'Planets',
182
+ 'id' => '006',
183
+ 'orderId'=>'12344',
184
+ 'amount'=>'6000',
185
+ 'orderSource'=>'ecommerce',
186
+ 'card'=>{
187
+ 'type'=>'VI',
188
+ 'number' =>'4100000000000001',
189
+ 'expDate' =>'1210'
190
+ }}
191
+
192
+ dir = '/tmp'
193
+
194
+ request = LitleRequest.new()
195
+ ENV['LITLE_CONFIG_DIR'] = config_dir
196
+ ENV['litle_deleteBatchFiles'] = 'false'
197
+ request.create_new_litle_request(dir + LITLE_SDK_TEST_FOLDER)
198
+
199
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
200
+ entries.sort!
201
+
202
+ assert_equal 4, entries.size
203
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
204
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
205
+
206
+ #create five batches, each with 10 sales
207
+ 5.times{
208
+ batch = LitleBatchRequest.new
209
+ batch.create_new_batch(dir + LITLE_SDK_TEST_FOLDER)
210
+
211
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
212
+
213
+ assert_equal 6, entries.length
214
+ entries.sort!
215
+ assert_not_nil entries[2] =~ /batch_\d+\z/
216
+ assert_not_nil entries[3] =~ /batch_\d+_txns\z/
217
+ assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
218
+ assert_not_nil entries[5] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
219
+ #add the same sale ten times
220
+ 10.times{
221
+ #batch.account_update(accountUpdateHash)
222
+ saleHash['card']['number']= (saleHash['card']['number'].to_i + 1).to_s
223
+ batch.sale(saleHash)
224
+ }
225
+
226
+ #close the batch, indicating we plan to add no more transactions
227
+ batch.close_batch()
228
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
229
+
230
+ assert_equal 5, entries.length
231
+ entries.sort!
232
+ assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
233
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
234
+ assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
235
+
236
+ #add the batch to the LitleRequest
237
+ request.commit_batch(batch)
238
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
239
+ assert_equal 4, entries.length
240
+ entries.sort!
241
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
242
+ assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
243
+ }
244
+ #finish the Litle Request, indicating we plan to add no more batches
245
+ request.finish_request
246
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
247
+ assert_equal 3, entries.length
248
+ entries.sort!
249
+ assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+.complete\z/
250
+
251
+ #send the batch files at the given directory over sFTP
252
+
253
+ request.send_to_litle()
254
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER)
255
+ encrypted_entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
256
+
257
+ assert_equal 3, entries.length
258
+ entries.sort!
259
+ puts entries[2]
260
+ assert_not_nil entries[2] =~ /encrypted/
261
+ assert_equal 2, encrypted_entries.length
262
+
263
+
264
+ #grab the expected number of responses from the sFTP server and save them to the given path
265
+ request.get_responses_from_server()
266
+
267
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR)
268
+ encrypted_entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR + ENCRYPTED_PATH_DIR)
269
+ assert_equal 4, entries.length
270
+ entries.sort!
271
+ assert_not_nil entries[3] =~ /#{RESPONSE_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}.asc#{RECEIVED_FILE_SUFFIX}\z/
272
+ assert_equal 2, encrypted_entries.length
273
+
274
+ #process the responses from the server with a listener which applies the given block
275
+ request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction| end})
276
+
277
+ entries = Dir.entries(dir + LITLE_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR)
278
+ assert_equal 3, entries.length
279
+ entries.sort!
280
+ assert_not_nil entries[2] =~ /encrypted/
281
+ end
282
+
283
+ def get_config(field, options)
284
+ if options[field.to_s] == nil and options[field] == nil then
285
+ return @config_hash[field.to_s]
286
+ elsif options[field.to_s] != nil then
287
+ return options[field.to_s]
288
+ else
289
+ return options[field]
290
+ end
291
+ end
292
+
293
+ end
294
+ end