CnpOnline 12.3.0 → 12.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -0
- data/Rakefile +1 -1
- data/lib/CnpBatchRequest.rb +17 -8
- data/lib/CnpOnline.rb +2 -0
- data/lib/CnpOnlineRequest.rb +30 -2
- data/lib/CnpRequest.rb +24 -4
- data/lib/CnpTransaction.rb +70 -7
- data/lib/CommManager.rb +185 -0
- data/lib/Communications.rb +7 -3
- data/lib/EnvironmentVariables.rb +8 -0
- data/lib/RequestTarget.rb +10 -0
- data/lib/XMLFields.rb +148 -11
- data/out/production/cnp-sdk-for-ruby/CnpBatchRequest.rb +787 -0
- data/out/production/cnp-sdk-for-ruby/CnpListeners.rb +265 -0
- data/out/production/cnp-sdk-for-ruby/CnpOnline.rb +65 -0
- data/out/production/cnp-sdk-for-ruby/CnpOnlineRequest.rb +370 -0
- data/out/production/cnp-sdk-for-ruby/CnpRequest.rb +670 -0
- data/out/production/cnp-sdk-for-ruby/CnpTransaction.rb +831 -0
- data/out/production/cnp-sdk-for-ruby/CnpXmlMapper.rb +71 -0
- data/out/production/cnp-sdk-for-ruby/CommManager.rb +185 -0
- data/out/production/cnp-sdk-for-ruby/Communications.rb +90 -0
- data/out/production/cnp-sdk-for-ruby/Configuration.rb +75 -0
- data/out/production/cnp-sdk-for-ruby/EnvironmentVariables.rb +33 -0
- data/out/production/cnp-sdk-for-ruby/RequestTarget.rb +10 -0
- data/out/production/cnp-sdk-for-ruby/Setup.rb +147 -0
- data/out/production/cnp-sdk-for-ruby/XMLFields.rb +2638 -0
- data/out/production/cnp-sdk-for-ruby/cacert.pem +3331 -0
- data/out/production/cnp-sdk-for-ruby/sample_batch_driver.rb +123 -0
- data/out/production/cnp-sdk-for-ruby/sample_driver.rb +49 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest1_base.rb +948 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest2_authenhanced.rb +577 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest3_authreversal.rb +190 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest4_echeck.rb +288 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest5_token.rb +209 -0
- data/out/test/cnp-sdk-for-ruby/certification/certTest_batchAll.rb +610 -0
- data/out/test/cnp-sdk-for-ruby/certification/ts_all.rb +33 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_activate.rb +133 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_activateReversal.rb +73 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_auth.rb +478 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_authReversal.rb +74 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_balanceInquiry.rb +107 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_batch.rb +264 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_batchStream.rb +154 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_cancelSubscription.rb +57 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_capture.rb +147 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_captureGivenAuth.rb +352 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_commManager.rb +302 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_configuration.rb +89 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_createPlan.rb +87 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_credit.rb +222 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_ctx.rb +124 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_deactivate.rb +105 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_deactivateReversal.rb +71 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_depositReversal.rb +70 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_echeckCredit.rb +179 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_echeckRedeposit.rb +117 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_echeckSale.rb +255 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_echeckVerification.rb +160 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_echeckVoid.rb +42 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_fastAccessFunding.rb +177 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_forceCapture.rb +272 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_fraudCheck.rb +76 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_giftCardAuthReversal.rb +72 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_giftCardCapture.rb +72 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_giftCardCredit.rb +69 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_litle_requests.rb +355 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_load.rb +108 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_loadReversal.rb +71 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_override.rb +68 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_pgp_cnp_requests.rb +295 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_queryTransaction.rb +154 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_refundReversal.rb +71 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_sale.rb +459 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_token.rb +137 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_translateToken.rb +203 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_unload.rb +108 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_unloadReversal.rb +71 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_updateCardValidationNumOnToken.rb +44 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_updatePlan.rb +61 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_updateSubscription.rb +80 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_wallet.rb +74 -0
- data/out/test/cnp-sdk-for-ruby/functional/test_xmlfields.rb +429 -0
- data/out/test/cnp-sdk-for-ruby/functional/ts_all.rb +69 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleAUBatch.rb +244 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleBatchRequest.rb +791 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleOnlineRequest.rb +253 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleRequest.rb +317 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleTransaction.rb +426 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_LitleXmlMapper.rb +139 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_activate.rb +92 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_activateReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_auth.rb +463 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_authReversal.rb +82 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_balanceInquiry.rb +52 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_cancelSubscription.rb +43 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_capture.rb +99 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_captureGivenAuth.rb +234 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_createPlan.rb +52 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_credit.rb +355 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_deactivate.rb +71 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_deactivateReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_depositReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_echeckCredit.rb +103 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_echeckRedeposit.rb +109 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_echeckSale.rb +107 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_echeckVerification.rb +74 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_echeckVoid.rb +54 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_forceCapture.rb +163 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_fraudCheck.rb +45 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_giftCardAuthReversal.rb +58 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_giftCardCapture.rb +57 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_giftCardCredit.rb +57 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_load.rb +53 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_loadReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_pgp_CnpRequest.rb +139 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_queryTransaction.rb +106 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_refundReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_sale.rb +551 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_token.rb +159 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_unload.rb +53 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_unloadReversal.rb +56 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_updateCardValidationNumOnToken.rb +80 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_updatePlan.rb +45 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_updateSubscription.rb +172 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_wallet.rb +262 -0
- data/out/test/cnp-sdk-for-ruby/unit/test_xmlfields.rb +2930 -0
- data/out/test/cnp-sdk-for-ruby/unit/ts_unit.rb +67 -0
- data/test/certification/certTest2_authenhanced.rb +28 -27
- data/test/functional/test_batch.rb +106 -1
- data/test/functional/test_batchStream.rb +3 -2
- data/test/functional/test_captureGivenAuth.rb +24 -0
- data/test/functional/test_commManager.rb +302 -0
- data/test/functional/test_ctx.rb +124 -0
- data/test/functional/test_fastAccessFunding.rb +21 -0
- data/test/functional/test_forceCapture.rb +21 -0
- data/test/functional/test_xmlfields.rb +20 -1
- metadata +122 -4
@@ -0,0 +1,108 @@
|
|
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
|
25
|
+
require File.expand_path("../../../lib/CnpOnline",__FILE__)
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
#test Load Transaction
|
29
|
+
module CnpOnline
|
30
|
+
class TestLoad < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def test_simple_happy
|
33
|
+
hash = {
|
34
|
+
'merchantId' => '101',
|
35
|
+
'version'=>'8.8',
|
36
|
+
'id'=>'test',
|
37
|
+
'reportGroup'=>'Planets',
|
38
|
+
'orderId' =>'1001',
|
39
|
+
'amount' =>'500',
|
40
|
+
'orderSource' =>'ecommerce',
|
41
|
+
'card'=>{
|
42
|
+
'type'=>'GC',
|
43
|
+
'number' =>'4100000000000001',
|
44
|
+
'expDate' =>'1210'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
response= CnpOnlineRequest.new.load_request(hash)
|
49
|
+
assert_equal('Valid Format', response.message)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_simple_out_of_order
|
53
|
+
hash = {
|
54
|
+
'merchantId' => '101',
|
55
|
+
'version'=>'8.8',
|
56
|
+
'id'=>'test',
|
57
|
+
'reportGroup'=>'Planets',
|
58
|
+
'amount' =>'500',
|
59
|
+
'orderId' =>'1001',
|
60
|
+
'orderSource' =>'ecommerce',
|
61
|
+
'card'=>{
|
62
|
+
'type'=>'GC',
|
63
|
+
'number' =>'4100000000000001',
|
64
|
+
'expDate' =>'1210'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
response= CnpOnlineRequest.new.load_request(hash)
|
69
|
+
assert_equal('Valid Format', response.message)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_simple_error
|
73
|
+
hash = {
|
74
|
+
'merchantId' => '101',
|
75
|
+
'version'=>'8.8',
|
76
|
+
'reportGroup'=>'Planets',
|
77
|
+
'amount' =>'500',
|
78
|
+
}
|
79
|
+
|
80
|
+
#Get exceptions
|
81
|
+
exception = assert_raise(RuntimeError){CnpOnlineRequest.new.load_request(hash)}
|
82
|
+
#Test
|
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){CnpOnlineRequest.new.load_request(hash)}
|
104
|
+
#Test
|
105
|
+
assert(exception.message =~ /Error validating xml data against the schema/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
25
|
+
require File.expand_path("../../../lib/CnpOnline",__FILE__)
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
#test loadReversal Transaction
|
29
|
+
module CnpOnline
|
30
|
+
class TestLoadReversal < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def test_simple
|
33
|
+
hash = {
|
34
|
+
'merchantId' => '101',
|
35
|
+
'version'=>'8.8',
|
36
|
+
'id'=>'test',
|
37
|
+
'reportGroup'=>'Planets',
|
38
|
+
'cnpTxnId' =>'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
|
+
}
|
52
|
+
|
53
|
+
response= CnpOnlineRequest.new.deposit_reversal(hash)
|
54
|
+
assert_equal('000', response.depositReversalResponse.response)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_simple_error
|
59
|
+
hash = {
|
60
|
+
'merchantId' => '101',
|
61
|
+
'version'=>'8.8',
|
62
|
+
'reportGroup'=>'Planets',
|
63
|
+
}
|
64
|
+
|
65
|
+
#Get exceptions
|
66
|
+
exception = assert_raise(RuntimeError){CnpOnlineRequest.new.load_reversal(hash)}
|
67
|
+
#Test
|
68
|
+
assert(exception.message =~ /Error validating xml data against the schema/)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path("../../../lib/CnpOnline",__FILE__)
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
#test Activate Transaction
|
5
|
+
module CnpOnline
|
6
|
+
class TestOverride < Test::Unit::TestCase
|
7
|
+
def test_override_withoutLocalAndEnv
|
8
|
+
hash = {
|
9
|
+
'merchantId' => '101',
|
10
|
+
'id' => 'test',
|
11
|
+
'version'=>'8.8',
|
12
|
+
'orderId' =>'1001',
|
13
|
+
'amount' =>'500',
|
14
|
+
'orderSource' =>'ecommerce',
|
15
|
+
'card'=>{
|
16
|
+
'type'=>'GC',
|
17
|
+
'number' =>'4100000000000001',
|
18
|
+
'expDate' =>'1210'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
response= CnpOnlineRequest.new.activate(hash)
|
22
|
+
assert_equal('Default Report Group', response.activateResponse.reportGroup)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_override_withoutLocal
|
26
|
+
hash = {
|
27
|
+
'merchantId' => '101',
|
28
|
+
'id' => 'test',
|
29
|
+
'version'=>'8.8',
|
30
|
+
'orderId' =>'1001',
|
31
|
+
'amount' =>'500',
|
32
|
+
'orderSource' =>'ecommerce',
|
33
|
+
'card'=>{
|
34
|
+
'type'=>'GC',
|
35
|
+
'number' =>'4100000000000001',
|
36
|
+
'expDate' =>'1210'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
ENV['cnp_default_report_group']='380'
|
40
|
+
response= CnpOnlineRequest.new.activate(hash)
|
41
|
+
assert_equal('380', response.activateResponse.reportGroup)
|
42
|
+
ENV['cnp_default_report_group']=nil
|
43
|
+
|
44
|
+
end
|
45
|
+
def test_override
|
46
|
+
hash = {
|
47
|
+
'merchantId' => '101',
|
48
|
+
'id' => 'test',
|
49
|
+
'version'=>'8.8',
|
50
|
+
'reportGroup'=>'Planets',
|
51
|
+
'orderId' =>'1001',
|
52
|
+
'amount' =>'500',
|
53
|
+
'orderSource' =>'ecommerce',
|
54
|
+
'card'=>{
|
55
|
+
'type'=>'GC',
|
56
|
+
'number' =>'4100000000000001',
|
57
|
+
'expDate' =>'1210'
|
58
|
+
}
|
59
|
+
}
|
60
|
+
ENV['cnp_default_report_group']='380'
|
61
|
+
response= CnpOnlineRequest.new.activate(hash)
|
62
|
+
assert_equal('Planets', response.activateResponse.reportGroup)
|
63
|
+
ENV['cnp_default_report_group']=nil
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
require File.expand_path("../../../lib/CnpOnline",__FILE__)
|
2
|
+
require 'test/unit'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
CNP_SDK_TEST_FOLDER = '/cnp-sdk-for-ruby-test'
|
6
|
+
|
7
|
+
|
8
|
+
module CnpOnline
|
9
|
+
class TestPgpCnpRequest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
dir = '/tmp' + CNP_SDK_TEST_FOLDER
|
13
|
+
FileUtils.rm_rf dir
|
14
|
+
Dir.mkdir dir
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_send_to_cnp
|
19
|
+
ENV['cnp_deleteBatchFiles'] = 'false'
|
20
|
+
config_dir = ENV['CNP_CONFIG_DIR']
|
21
|
+
ENV['CNP_CONFIG_DIR'] = '/tmp/pgp_ruby'
|
22
|
+
|
23
|
+
@config_hash = Configuration.new.config
|
24
|
+
|
25
|
+
dir = '/tmp'
|
26
|
+
|
27
|
+
request = CnpRequest.new()
|
28
|
+
ENV['CNP_CONFIG_DIR'] = config_dir
|
29
|
+
request.create_new_cnp_request(dir + CNP_SDK_TEST_FOLDER)
|
30
|
+
request.finish_request
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
request.send_to_cnp()
|
35
|
+
|
36
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
37
|
+
encrypted_entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
|
38
|
+
entries.sort!
|
39
|
+
assert_equal 4, entries.size
|
40
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
|
41
|
+
encrypted_entries.sort!
|
42
|
+
assert_equal 3, encrypted_entries.size
|
43
|
+
assert_not_nil encrypted_entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{ENCRYPTED_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
|
44
|
+
|
45
|
+
uploaded_file = encrypted_entries[2]
|
46
|
+
|
47
|
+
options = {}
|
48
|
+
username = get_config(:sftp_username, options)
|
49
|
+
password = get_config(:sftp_password, options)
|
50
|
+
url = get_config(:sftp_url, options)
|
51
|
+
|
52
|
+
Net::SFTP.start(url, username, :password => password) do |sftp|
|
53
|
+
# clear out the sFTP outbound dir prior to checking for new files, avoids leaving files on the server
|
54
|
+
# if files are left behind we are not counting then towards the expected total
|
55
|
+
ents = []
|
56
|
+
handle = sftp.opendir!('/inbound/')
|
57
|
+
files_on_srv = sftp.readdir!(handle)
|
58
|
+
files_on_srv.each {|file|
|
59
|
+
ents.push(file.name)
|
60
|
+
}
|
61
|
+
assert_equal 3,ents.size
|
62
|
+
ents.sort!
|
63
|
+
assert_equal ents[2], uploaded_file.gsub(SENT_FILE_SUFFIX, '.asc')
|
64
|
+
sftp.remove('/inbound/' + ents[2])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_full_flow
|
69
|
+
ENV['cnp_deleteBatchFiles'] = 'false'
|
70
|
+
config_dir = ENV['CNP_CONFIG_DIR']
|
71
|
+
ENV['CNP_CONFIG_DIR'] = '/tmp/pgp_ruby'
|
72
|
+
|
73
|
+
saleHash = {
|
74
|
+
'reportGroup'=>'Planets',
|
75
|
+
'id' => '006',
|
76
|
+
'orderId'=>'12344',
|
77
|
+
'amount'=>'6000',
|
78
|
+
'orderSource'=>'ecommerce',
|
79
|
+
'card'=>{
|
80
|
+
'type'=>'VI',
|
81
|
+
'number' =>'4100000000000001',
|
82
|
+
'expDate' =>'1210'
|
83
|
+
}}
|
84
|
+
|
85
|
+
dir = '/tmp'
|
86
|
+
|
87
|
+
request = CnpRequest.new()
|
88
|
+
ENV['CNP_CONFIG_DIR'] = config_dir
|
89
|
+
request.create_new_cnp_request(dir + CNP_SDK_TEST_FOLDER)
|
90
|
+
|
91
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
92
|
+
entries.sort!
|
93
|
+
|
94
|
+
assert_equal 4, entries.size
|
95
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
96
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
97
|
+
|
98
|
+
#create five batches, each with 10 sales
|
99
|
+
5.times{
|
100
|
+
batch = CnpBatchRequest.new
|
101
|
+
batch.create_new_batch(dir + CNP_SDK_TEST_FOLDER)
|
102
|
+
|
103
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
104
|
+
|
105
|
+
assert_equal 6, entries.length
|
106
|
+
entries.sort!
|
107
|
+
assert_not_nil entries[2] =~ /batch_\d+\z/
|
108
|
+
assert_not_nil entries[3] =~ /batch_\d+_txns\z/
|
109
|
+
assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
110
|
+
assert_not_nil entries[5] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
111
|
+
#add the same sale ten times
|
112
|
+
10.times{
|
113
|
+
#batch.account_update(accountUpdateHash)
|
114
|
+
saleHash['card']['number']= (saleHash['card']['number'].to_i + 1).to_s
|
115
|
+
batch.sale(saleHash)
|
116
|
+
}
|
117
|
+
|
118
|
+
#close the batch, indicating we plan to add no more transactions
|
119
|
+
batch.close_batch()
|
120
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
121
|
+
|
122
|
+
assert_equal 5, entries.length
|
123
|
+
entries.sort!
|
124
|
+
assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
|
125
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
126
|
+
assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
127
|
+
|
128
|
+
#add the batch to the CnpRequest
|
129
|
+
request.commit_batch(batch)
|
130
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
131
|
+
assert_equal 4, entries.length
|
132
|
+
entries.sort!
|
133
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
134
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
135
|
+
}
|
136
|
+
#finish the Cnp Request, indicating we plan to add no more batches
|
137
|
+
request.finish_request
|
138
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
139
|
+
assert_equal 3, entries.length
|
140
|
+
entries.sort!
|
141
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+.complete\z/
|
142
|
+
|
143
|
+
#send the batch files at the given directory over sFTP
|
144
|
+
|
145
|
+
request.send_to_cnp()
|
146
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
147
|
+
encrypted_entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
|
148
|
+
|
149
|
+
assert_equal entries.length, 4
|
150
|
+
entries.sort!
|
151
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
|
152
|
+
encrypted_entries.sort!
|
153
|
+
assert_not_nil encrypted_entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{ENCRYPTED_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
#grab the expected number of responses from the sFTP server and save them to the given path
|
158
|
+
request.get_responses_from_server()
|
159
|
+
#process the responses from the server with a listener which applies the given block
|
160
|
+
request.process_responses({:transaction_listener => CnpOnline::DefaultCnpListener.new do |transaction| end})
|
161
|
+
|
162
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
163
|
+
|
164
|
+
assert_equal 5, entries.length
|
165
|
+
entries.sort!
|
166
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}#{SENT_FILE_SUFFIX}\z/
|
167
|
+
File.delete(dir + CNP_SDK_TEST_FOLDER + '/' + entries[3])
|
168
|
+
|
169
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + entries[4])
|
170
|
+
entries.sort!
|
171
|
+
assert_equal 4, entries.length
|
172
|
+
assert_not_nil entries[3] =~ /#{RESPONSE_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}.asc#{RECEIVED_FILE_SUFFIX}.processed\z/
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def test_full_flow_with_deleteBatchFiles
|
177
|
+
ENV['cnp_deleteBatchFiles'] = 'true'
|
178
|
+
config_dir = ENV['CNP_CONFIG_DIR']
|
179
|
+
ENV['CNP_CONFIG_DIR'] = '/tmp/pgp_ruby'
|
180
|
+
|
181
|
+
saleHash = {
|
182
|
+
'reportGroup'=>'Planets',
|
183
|
+
'id' => '006',
|
184
|
+
'orderId'=>'12344',
|
185
|
+
'amount'=>'6000',
|
186
|
+
'orderSource'=>'ecommerce',
|
187
|
+
'card'=>{
|
188
|
+
'type'=>'VI',
|
189
|
+
'number' =>'4100000000000001',
|
190
|
+
'expDate' =>'1210'
|
191
|
+
}}
|
192
|
+
|
193
|
+
dir = '/tmp'
|
194
|
+
|
195
|
+
request = CnpRequest.new()
|
196
|
+
ENV['CNP_CONFIG_DIR'] = config_dir
|
197
|
+
ENV['cnp_deleteBatchFiles'] = 'false'
|
198
|
+
request.create_new_cnp_request(dir + CNP_SDK_TEST_FOLDER)
|
199
|
+
|
200
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
201
|
+
entries.sort!
|
202
|
+
|
203
|
+
assert_equal 4, entries.size
|
204
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
205
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
206
|
+
|
207
|
+
#create five batches, each with 10 sales
|
208
|
+
5.times{
|
209
|
+
batch = CnpBatchRequest.new
|
210
|
+
batch.create_new_batch(dir + CNP_SDK_TEST_FOLDER)
|
211
|
+
|
212
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
213
|
+
|
214
|
+
assert_equal 6, entries.length
|
215
|
+
entries.sort!
|
216
|
+
assert_not_nil entries[2] =~ /batch_\d+\z/
|
217
|
+
assert_not_nil entries[3] =~ /batch_\d+_txns\z/
|
218
|
+
assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
219
|
+
assert_not_nil entries[5] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
220
|
+
#add the same sale ten times
|
221
|
+
10.times{
|
222
|
+
#batch.account_update(accountUpdateHash)
|
223
|
+
saleHash['card']['number']= (saleHash['card']['number'].to_i + 1).to_s
|
224
|
+
batch.sale(saleHash)
|
225
|
+
}
|
226
|
+
|
227
|
+
#close the batch, indicating we plan to add no more transactions
|
228
|
+
batch.close_batch()
|
229
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
230
|
+
|
231
|
+
assert_equal 5, entries.length
|
232
|
+
entries.sort!
|
233
|
+
assert_not_nil entries[2] =~ /batch_\d+.closed-\d+\z/
|
234
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
235
|
+
assert_not_nil entries[4] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
236
|
+
|
237
|
+
#add the batch to the CnpRequest
|
238
|
+
request.commit_batch(batch)
|
239
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
240
|
+
assert_equal 4, entries.length
|
241
|
+
entries.sort!
|
242
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+\z/
|
243
|
+
assert_not_nil entries[3] =~ /#{REQUEST_FILE_PREFIX}\d+_batches\z/
|
244
|
+
}
|
245
|
+
#finish the Cnp Request, indicating we plan to add no more batches
|
246
|
+
request.finish_request
|
247
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
248
|
+
assert_equal 3, entries.length
|
249
|
+
entries.sort!
|
250
|
+
assert_not_nil entries[2] =~ /#{REQUEST_FILE_PREFIX}\d+.complete\z/
|
251
|
+
|
252
|
+
#send the batch files at the given directory over sFTP
|
253
|
+
|
254
|
+
request.send_to_cnp()
|
255
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER)
|
256
|
+
encrypted_entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + ENCRYPTED_PATH_DIR)
|
257
|
+
|
258
|
+
assert_equal 3, entries.length
|
259
|
+
entries.sort!
|
260
|
+
puts entries[2]
|
261
|
+
assert_not_nil entries[2] =~ /encrypted/
|
262
|
+
assert_equal 2, encrypted_entries.length
|
263
|
+
|
264
|
+
|
265
|
+
#grab the expected number of responses from the sFTP server and save them to the given path
|
266
|
+
request.get_responses_from_server()
|
267
|
+
|
268
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR)
|
269
|
+
encrypted_entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR + ENCRYPTED_PATH_DIR)
|
270
|
+
assert_equal 4, entries.length
|
271
|
+
entries.sort!
|
272
|
+
assert_not_nil entries[3] =~ /#{RESPONSE_FILE_PREFIX}\d+#{COMPLETE_FILE_SUFFIX}.asc#{RECEIVED_FILE_SUFFIX}\z/
|
273
|
+
assert_equal 2, encrypted_entries.length
|
274
|
+
|
275
|
+
#process the responses from the server with a listener which applies the given block
|
276
|
+
request.process_responses({:transaction_listener => CnpOnline::DefaultCnpListener.new do |transaction| end})
|
277
|
+
|
278
|
+
entries = Dir.entries(dir + CNP_SDK_TEST_FOLDER + '/' + RESPONSE_PATH_DIR)
|
279
|
+
assert_equal 3, entries.length
|
280
|
+
entries.sort!
|
281
|
+
assert_not_nil entries[2] =~ /encrypted/
|
282
|
+
end
|
283
|
+
|
284
|
+
def get_config(field, options)
|
285
|
+
if options[field.to_s] == nil and options[field] == nil then
|
286
|
+
return @config_hash[field.to_s]
|
287
|
+
elsif options[field.to_s] != nil then
|
288
|
+
return options[field.to_s]
|
289
|
+
else
|
290
|
+
return options[field]
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
end
|