CnpOnline 12.3.0 → 12.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -0
  3. data/Rakefile +1 -1
  4. data/lib/CnpBatchRequest.rb +17 -8
  5. data/lib/CnpOnline.rb +2 -0
  6. data/lib/CnpOnlineRequest.rb +30 -2
  7. data/lib/CnpRequest.rb +24 -4
  8. data/lib/CnpTransaction.rb +70 -7
  9. data/lib/CommManager.rb +185 -0
  10. data/lib/Communications.rb +7 -3
  11. data/lib/EnvironmentVariables.rb +8 -0
  12. data/lib/RequestTarget.rb +10 -0
  13. data/lib/XMLFields.rb +148 -11
  14. data/out/production/cnp-sdk-for-ruby/CnpBatchRequest.rb +787 -0
  15. data/out/production/cnp-sdk-for-ruby/CnpListeners.rb +265 -0
  16. data/out/production/cnp-sdk-for-ruby/CnpOnline.rb +65 -0
  17. data/out/production/cnp-sdk-for-ruby/CnpOnlineRequest.rb +370 -0
  18. data/out/production/cnp-sdk-for-ruby/CnpRequest.rb +670 -0
  19. data/out/production/cnp-sdk-for-ruby/CnpTransaction.rb +831 -0
  20. data/out/production/cnp-sdk-for-ruby/CnpXmlMapper.rb +71 -0
  21. data/out/production/cnp-sdk-for-ruby/CommManager.rb +185 -0
  22. data/out/production/cnp-sdk-for-ruby/Communications.rb +90 -0
  23. data/out/production/cnp-sdk-for-ruby/Configuration.rb +75 -0
  24. data/out/production/cnp-sdk-for-ruby/EnvironmentVariables.rb +33 -0
  25. data/out/production/cnp-sdk-for-ruby/RequestTarget.rb +10 -0
  26. data/out/production/cnp-sdk-for-ruby/Setup.rb +147 -0
  27. data/out/production/cnp-sdk-for-ruby/XMLFields.rb +2638 -0
  28. data/out/production/cnp-sdk-for-ruby/cacert.pem +3331 -0
  29. data/out/production/cnp-sdk-for-ruby/sample_batch_driver.rb +123 -0
  30. data/out/production/cnp-sdk-for-ruby/sample_driver.rb +49 -0
  31. data/out/test/cnp-sdk-for-ruby/certification/certTest1_base.rb +948 -0
  32. data/out/test/cnp-sdk-for-ruby/certification/certTest2_authenhanced.rb +577 -0
  33. data/out/test/cnp-sdk-for-ruby/certification/certTest3_authreversal.rb +190 -0
  34. data/out/test/cnp-sdk-for-ruby/certification/certTest4_echeck.rb +288 -0
  35. data/out/test/cnp-sdk-for-ruby/certification/certTest5_token.rb +209 -0
  36. data/out/test/cnp-sdk-for-ruby/certification/certTest_batchAll.rb +610 -0
  37. data/out/test/cnp-sdk-for-ruby/certification/ts_all.rb +33 -0
  38. data/out/test/cnp-sdk-for-ruby/functional/test_activate.rb +133 -0
  39. data/out/test/cnp-sdk-for-ruby/functional/test_activateReversal.rb +73 -0
  40. data/out/test/cnp-sdk-for-ruby/functional/test_auth.rb +478 -0
  41. data/out/test/cnp-sdk-for-ruby/functional/test_authReversal.rb +74 -0
  42. data/out/test/cnp-sdk-for-ruby/functional/test_balanceInquiry.rb +107 -0
  43. data/out/test/cnp-sdk-for-ruby/functional/test_batch.rb +264 -0
  44. data/out/test/cnp-sdk-for-ruby/functional/test_batchStream.rb +154 -0
  45. data/out/test/cnp-sdk-for-ruby/functional/test_cancelSubscription.rb +57 -0
  46. data/out/test/cnp-sdk-for-ruby/functional/test_capture.rb +147 -0
  47. data/out/test/cnp-sdk-for-ruby/functional/test_captureGivenAuth.rb +352 -0
  48. data/out/test/cnp-sdk-for-ruby/functional/test_commManager.rb +302 -0
  49. data/out/test/cnp-sdk-for-ruby/functional/test_configuration.rb +89 -0
  50. data/out/test/cnp-sdk-for-ruby/functional/test_createPlan.rb +87 -0
  51. data/out/test/cnp-sdk-for-ruby/functional/test_credit.rb +222 -0
  52. data/out/test/cnp-sdk-for-ruby/functional/test_ctx.rb +124 -0
  53. data/out/test/cnp-sdk-for-ruby/functional/test_deactivate.rb +105 -0
  54. data/out/test/cnp-sdk-for-ruby/functional/test_deactivateReversal.rb +71 -0
  55. data/out/test/cnp-sdk-for-ruby/functional/test_depositReversal.rb +70 -0
  56. data/out/test/cnp-sdk-for-ruby/functional/test_echeckCredit.rb +179 -0
  57. data/out/test/cnp-sdk-for-ruby/functional/test_echeckRedeposit.rb +117 -0
  58. data/out/test/cnp-sdk-for-ruby/functional/test_echeckSale.rb +255 -0
  59. data/out/test/cnp-sdk-for-ruby/functional/test_echeckVerification.rb +160 -0
  60. data/out/test/cnp-sdk-for-ruby/functional/test_echeckVoid.rb +42 -0
  61. data/out/test/cnp-sdk-for-ruby/functional/test_fastAccessFunding.rb +177 -0
  62. data/out/test/cnp-sdk-for-ruby/functional/test_forceCapture.rb +272 -0
  63. data/out/test/cnp-sdk-for-ruby/functional/test_fraudCheck.rb +76 -0
  64. data/out/test/cnp-sdk-for-ruby/functional/test_giftCardAuthReversal.rb +72 -0
  65. data/out/test/cnp-sdk-for-ruby/functional/test_giftCardCapture.rb +72 -0
  66. data/out/test/cnp-sdk-for-ruby/functional/test_giftCardCredit.rb +69 -0
  67. data/out/test/cnp-sdk-for-ruby/functional/test_litle_requests.rb +355 -0
  68. data/out/test/cnp-sdk-for-ruby/functional/test_load.rb +108 -0
  69. data/out/test/cnp-sdk-for-ruby/functional/test_loadReversal.rb +71 -0
  70. data/out/test/cnp-sdk-for-ruby/functional/test_override.rb +68 -0
  71. data/out/test/cnp-sdk-for-ruby/functional/test_pgp_cnp_requests.rb +295 -0
  72. data/out/test/cnp-sdk-for-ruby/functional/test_queryTransaction.rb +154 -0
  73. data/out/test/cnp-sdk-for-ruby/functional/test_refundReversal.rb +71 -0
  74. data/out/test/cnp-sdk-for-ruby/functional/test_sale.rb +459 -0
  75. data/out/test/cnp-sdk-for-ruby/functional/test_token.rb +137 -0
  76. data/out/test/cnp-sdk-for-ruby/functional/test_translateToken.rb +203 -0
  77. data/out/test/cnp-sdk-for-ruby/functional/test_unload.rb +108 -0
  78. data/out/test/cnp-sdk-for-ruby/functional/test_unloadReversal.rb +71 -0
  79. data/out/test/cnp-sdk-for-ruby/functional/test_updateCardValidationNumOnToken.rb +44 -0
  80. data/out/test/cnp-sdk-for-ruby/functional/test_updatePlan.rb +61 -0
  81. data/out/test/cnp-sdk-for-ruby/functional/test_updateSubscription.rb +80 -0
  82. data/out/test/cnp-sdk-for-ruby/functional/test_wallet.rb +74 -0
  83. data/out/test/cnp-sdk-for-ruby/functional/test_xmlfields.rb +429 -0
  84. data/out/test/cnp-sdk-for-ruby/functional/ts_all.rb +69 -0
  85. data/out/test/cnp-sdk-for-ruby/unit/test_LitleAUBatch.rb +244 -0
  86. data/out/test/cnp-sdk-for-ruby/unit/test_LitleBatchRequest.rb +791 -0
  87. data/out/test/cnp-sdk-for-ruby/unit/test_LitleOnlineRequest.rb +253 -0
  88. data/out/test/cnp-sdk-for-ruby/unit/test_LitleRequest.rb +317 -0
  89. data/out/test/cnp-sdk-for-ruby/unit/test_LitleTransaction.rb +426 -0
  90. data/out/test/cnp-sdk-for-ruby/unit/test_LitleXmlMapper.rb +139 -0
  91. data/out/test/cnp-sdk-for-ruby/unit/test_activate.rb +92 -0
  92. data/out/test/cnp-sdk-for-ruby/unit/test_activateReversal.rb +56 -0
  93. data/out/test/cnp-sdk-for-ruby/unit/test_auth.rb +463 -0
  94. data/out/test/cnp-sdk-for-ruby/unit/test_authReversal.rb +82 -0
  95. data/out/test/cnp-sdk-for-ruby/unit/test_balanceInquiry.rb +52 -0
  96. data/out/test/cnp-sdk-for-ruby/unit/test_cancelSubscription.rb +43 -0
  97. data/out/test/cnp-sdk-for-ruby/unit/test_capture.rb +99 -0
  98. data/out/test/cnp-sdk-for-ruby/unit/test_captureGivenAuth.rb +234 -0
  99. data/out/test/cnp-sdk-for-ruby/unit/test_createPlan.rb +52 -0
  100. data/out/test/cnp-sdk-for-ruby/unit/test_credit.rb +355 -0
  101. data/out/test/cnp-sdk-for-ruby/unit/test_deactivate.rb +71 -0
  102. data/out/test/cnp-sdk-for-ruby/unit/test_deactivateReversal.rb +56 -0
  103. data/out/test/cnp-sdk-for-ruby/unit/test_depositReversal.rb +56 -0
  104. data/out/test/cnp-sdk-for-ruby/unit/test_echeckCredit.rb +103 -0
  105. data/out/test/cnp-sdk-for-ruby/unit/test_echeckRedeposit.rb +109 -0
  106. data/out/test/cnp-sdk-for-ruby/unit/test_echeckSale.rb +107 -0
  107. data/out/test/cnp-sdk-for-ruby/unit/test_echeckVerification.rb +74 -0
  108. data/out/test/cnp-sdk-for-ruby/unit/test_echeckVoid.rb +54 -0
  109. data/out/test/cnp-sdk-for-ruby/unit/test_forceCapture.rb +163 -0
  110. data/out/test/cnp-sdk-for-ruby/unit/test_fraudCheck.rb +45 -0
  111. data/out/test/cnp-sdk-for-ruby/unit/test_giftCardAuthReversal.rb +58 -0
  112. data/out/test/cnp-sdk-for-ruby/unit/test_giftCardCapture.rb +57 -0
  113. data/out/test/cnp-sdk-for-ruby/unit/test_giftCardCredit.rb +57 -0
  114. data/out/test/cnp-sdk-for-ruby/unit/test_load.rb +53 -0
  115. data/out/test/cnp-sdk-for-ruby/unit/test_loadReversal.rb +56 -0
  116. data/out/test/cnp-sdk-for-ruby/unit/test_pgp_CnpRequest.rb +139 -0
  117. data/out/test/cnp-sdk-for-ruby/unit/test_queryTransaction.rb +106 -0
  118. data/out/test/cnp-sdk-for-ruby/unit/test_refundReversal.rb +56 -0
  119. data/out/test/cnp-sdk-for-ruby/unit/test_sale.rb +551 -0
  120. data/out/test/cnp-sdk-for-ruby/unit/test_token.rb +159 -0
  121. data/out/test/cnp-sdk-for-ruby/unit/test_unload.rb +53 -0
  122. data/out/test/cnp-sdk-for-ruby/unit/test_unloadReversal.rb +56 -0
  123. data/out/test/cnp-sdk-for-ruby/unit/test_updateCardValidationNumOnToken.rb +80 -0
  124. data/out/test/cnp-sdk-for-ruby/unit/test_updatePlan.rb +45 -0
  125. data/out/test/cnp-sdk-for-ruby/unit/test_updateSubscription.rb +172 -0
  126. data/out/test/cnp-sdk-for-ruby/unit/test_wallet.rb +262 -0
  127. data/out/test/cnp-sdk-for-ruby/unit/test_xmlfields.rb +2930 -0
  128. data/out/test/cnp-sdk-for-ruby/unit/ts_unit.rb +67 -0
  129. data/test/certification/certTest2_authenhanced.rb +28 -27
  130. data/test/functional/test_batch.rb +106 -1
  131. data/test/functional/test_batchStream.rb +3 -2
  132. data/test/functional/test_captureGivenAuth.rb +24 -0
  133. data/test/functional/test_commManager.rb +302 -0
  134. data/test/functional/test_ctx.rb +124 -0
  135. data/test/functional/test_fastAccessFunding.rb +21 -0
  136. data/test/functional/test_forceCapture.rb +21 -0
  137. data/test/functional/test_xmlfields.rb +20 -1
  138. metadata +122 -4
@@ -0,0 +1,69 @@
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
+
26
+ require File.expand_path("../../../lib/CnpOnline",__FILE__)
27
+
28
+
29
+ #test driver for running all tests
30
+ require_relative 'test_updateSubscription'
31
+ require_relative 'test_captureGivenAuth'
32
+ require_relative 'test_xmlfields'
33
+ require_relative 'test_sale'
34
+ require_relative 'test_captureGivenAuth'
35
+ require_relative 'test_authReversal'
36
+ require_relative 'test_credit'
37
+ require_relative 'test_auth'
38
+ require_relative 'test_token'
39
+ require_relative 'test_forceCapture'
40
+ require_relative 'test_capture'
41
+ require_relative 'test_echeckRedeposit'
42
+ require_relative 'test_echeckSale'
43
+ require_relative 'test_echeckCredit'
44
+ require_relative 'test_echeckVerification'
45
+ require_relative 'test_echeckVoid'
46
+ require_relative 'test_updateCardValidationNumOnToken'
47
+ require_relative 'test_wallet'
48
+ require_relative 'test_queryTransaction'
49
+ #require_relative 'test_cnp_requests'
50
+ require_relative 'test_batch'
51
+ require_relative 'test_cancelSubscription'
52
+ require_relative 'test_updateSubscription'
53
+ require_relative 'test_deactivate'
54
+ require_relative 'test_load'
55
+ require_relative 'test_unload'
56
+ require_relative 'test_balanceInquiry'
57
+ require_relative 'test_createPlan'
58
+ require_relative 'test_updatePlan'
59
+ require_relative 'test_batchStream'
60
+ require_relative 'test_activate'
61
+ require_relative 'test_activateReversal'
62
+ require_relative 'test_depositReversal'
63
+ require_relative 'test_refundReversal'
64
+ require_relative 'test_loadReversal'
65
+ require_relative 'test_unloadReversal'
66
+ require_relative 'test_deactivateReversal'
67
+ require_relative 'test_override'
68
+ require_relative 'test_configuration'
69
+ require_relative 'test_fraudCheck'
@@ -0,0 +1,244 @@
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
+ require 'mocha/setup'
28
+
29
+ module CnpOnline
30
+
31
+ class TestCnpAUBatch < Test::Unit::TestCase
32
+ def test_create_new_batch
33
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
34
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
35
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
36
+ File.expects(:directory?).returns(false).once
37
+
38
+ batch = CnpAUBatch.new
39
+ batch.create_new_batch('/usr/local/Batches/')
40
+ end
41
+
42
+ def test_account_update
43
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
44
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
45
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
46
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
47
+ File.expects(:directory?).returns(true).once
48
+
49
+ accountUpdateHash = {
50
+ 'reportGroup'=>'Planets',
51
+ 'id'=>'12345',
52
+ 'customerId'=>'0987',
53
+ 'card'=>{
54
+ 'type'=>'VI',
55
+ 'number' =>'4100000000000001',
56
+ 'expDate' =>'1210'
57
+ }}
58
+
59
+ batch = CnpAUBatch.new
60
+ batch.create_new_batch('D:\Batches\\')
61
+ batch.account_update(accountUpdateHash)
62
+
63
+ counts = batch.get_counts_and_amounts
64
+ assert_equal 1, counts[:numAccountUpdates]
65
+ assert_equal 1, counts[:total]
66
+ end
67
+
68
+ def test_close_batch
69
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
70
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
71
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
72
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
73
+ File.expects(:rename).once
74
+ File.expects(:delete).once
75
+ File.expects(:directory?).returns(true).once
76
+
77
+ batch = CnpAUBatch.new
78
+ batch.create_new_batch('D:\Batches\\')
79
+
80
+ batch.close_batch()
81
+ end
82
+
83
+ def test_open_existing_batch
84
+ open = sequence('open')
85
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
86
+
87
+ File.expects(:file?).returns(false).once.in_sequence(open)
88
+ File.expects(:directory?).returns(true).in_sequence(open)
89
+ File.expects(:file?).returns(false).in_sequence(open)
90
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
91
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
92
+ File.expects(:file?).returns(true).in_sequence(open)
93
+
94
+
95
+
96
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
97
+ File.expects(:rename).once.in_sequence(open)
98
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
99
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
100
+ batch1 = CnpAUBatch.new
101
+ batch2 = CnpAUBatch.new
102
+ batch1.create_new_batch('/usr/local/Batches/')
103
+
104
+ batch2.open_existing_batch(batch1.get_batch_name)
105
+ batch2.close_batch()
106
+ end
107
+
108
+ def test_build_batch_header
109
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
110
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
111
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
112
+ File.expects(:rename).once
113
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
114
+ File.expects(:delete).once
115
+ File.expects(:directory?).returns(true).once
116
+
117
+ batch = CnpAUBatch.new
118
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(5)
119
+
120
+ batch.create_new_batch('/usr/local/batches')
121
+ batch.close_batch()
122
+ end
123
+
124
+ def test_create_new_batch_missing_separator
125
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
126
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
127
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
128
+
129
+ batch = CnpAUBatch.new
130
+ batch.create_new_batch('/usr/local')
131
+
132
+ assert batch.get_batch_name.include?('/usr/local/')
133
+ end
134
+
135
+ def test_create_new_batch_name_collision
136
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
137
+
138
+ fileExists = sequence('fileExists')
139
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
140
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
141
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
142
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
143
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
144
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
145
+
146
+
147
+ batch = CnpAUBatch.new
148
+ batch.create_new_batch('/usr/local/')
149
+ end
150
+
151
+ def test_create_new_batch_when_full
152
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
153
+
154
+ batch = CnpAUBatch.new
155
+ addTxn = sequence('addTxn')
156
+
157
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
158
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
159
+ batch.create_new_batch('/usr/local')
160
+
161
+ batch.get_counts_and_amounts.expects(:[]).with(:numAccountUpdates).returns(499999).in_sequence(addTxn)
162
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(30000).in_sequence(addTxn)
163
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
164
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
165
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
166
+ batch.expects(:close_batch).once.in_sequence(addTxn)
167
+ batch.expects(:initialize).once.in_sequence(addTxn)
168
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
169
+
170
+ accountUpdateHash = {
171
+ 'reportGroup'=>'Planets',
172
+ 'id'=>'12345',
173
+ 'customerId'=>'0987',
174
+ 'card'=>{
175
+ 'type'=>'VI',
176
+ 'number' =>'4100000000000001',
177
+ 'expDate' =>'1210'
178
+ }}
179
+
180
+ batch.account_update(accountUpdateHash)
181
+ end
182
+
183
+ def test_complete_batch
184
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
185
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(7)
186
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(5)
187
+ File.expects(:rename).once
188
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
189
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
190
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
191
+ File.expects(:directory?).returns(false).once
192
+
193
+ batch = CnpAUBatch.new
194
+ batch.create_new_batch('/usr/local/Batches/')
195
+
196
+ accountUpdateHash = {
197
+ 'reportGroup'=>'Planets',
198
+ 'id'=>'12345',
199
+ 'customerId'=>'0987',
200
+ 'card'=>{
201
+ 'type'=>'VI',
202
+ 'number' =>'4100000000000001',
203
+ 'expDate' =>'1210'
204
+ }}
205
+
206
+ 5.times(){ batch.account_update(accountUpdateHash ) }
207
+
208
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
209
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
210
+ batch.close_batch()
211
+ counts = batch.get_counts_and_amounts
212
+
213
+ assert_equal 5, counts[:numAccountUpdates]
214
+ end
215
+
216
+ def test_AU_batch_with_token
217
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
218
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(7)
219
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(5)
220
+ File.expects(:rename).once
221
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
222
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
223
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
224
+ File.expects(:directory?).returns(false).once
225
+
226
+ batch = CnpAUBatch.new
227
+ batch.create_new_batch('/usr/local/Batches/')
228
+
229
+ accountUpdateHash = {
230
+ 'reportGroup'=>'Planets',
231
+ 'id'=>'12345',
232
+ 'customerId'=>'0987',
233
+ 'token'=>{'cnpToken'=>'1234567890123'
234
+ }}
235
+
236
+ 5.times(){ batch.account_update(accountUpdateHash ) }
237
+
238
+ batch.close_batch()
239
+ counts = batch.get_counts_and_amounts
240
+
241
+ assert_equal 5, counts[:numAccountUpdates]
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,791 @@
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
+ require 'mocha/setup'
28
+
29
+ module CnpOnline
30
+ class TestCnpBatchRequest < Test::Unit::TestCase
31
+ def test_create_new_batch
32
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
33
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
34
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
35
+ File.expects(:directory?).returns(false).once
36
+
37
+ batch = CnpBatchRequest.new
38
+ batch.create_new_batch('/usr/local/Batches/')
39
+ end
40
+
41
+ def test_add_authorization
42
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
43
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
44
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').at_most(3)
45
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').twice
46
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
47
+ File.expects(:directory?).returns(false).once
48
+ authHash = {
49
+ 'reportGroup'=>'Planets',
50
+ 'orderId'=>'12344',
51
+ 'amount'=>'106',
52
+ 'orderSource'=>'ecommerce',
53
+ 'card'=>{
54
+ 'type'=>'VI',
55
+ 'number' =>'4100000000000001',
56
+ 'expDate' =>'1210'
57
+ }}
58
+
59
+ batch = CnpBatchRequest.new
60
+ batch.create_new_batch('/usr/local/Batches/')
61
+
62
+ 2.times(){ batch.authorization(authHash) }
63
+ counts = batch.get_counts_and_amounts
64
+
65
+ assert_equal 2, counts[:auth][:numAuths]
66
+ assert_equal 212, counts[:auth][:authAmount]
67
+ end
68
+
69
+ def test_add_sale
70
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
71
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
72
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
73
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
74
+ File.expects(:directory?).returns(true).once
75
+
76
+ saleHash = {
77
+ 'reportGroup'=>'Planets',
78
+ 'id' => '006',
79
+ 'orderId'=>'12344',
80
+ 'amount'=>'6000',
81
+ 'orderSource'=>'ecommerce',
82
+ 'card'=>{
83
+ 'type'=>'VI',
84
+ 'number' =>'4100000000000001',
85
+ 'expDate' =>'1210'
86
+ }}
87
+
88
+ batch = CnpBatchRequest.new
89
+ batch.create_new_batch('D:\Batches\\')
90
+ batch.sale(saleHash)
91
+
92
+ counts = batch.get_counts_and_amounts
93
+ assert_equal 1, counts[:sale][:numSales]
94
+ assert_equal 6000, counts[:sale][:saleAmount]
95
+ end
96
+
97
+ def test_add_credit
98
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
99
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
100
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
101
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
102
+ File.expects(:directory?).returns(true).once
103
+
104
+ creditHash = {
105
+ 'merchantId' => '101',
106
+ 'version'=>'8.8',
107
+ 'reportGroup'=>'Planets',
108
+ 'orderId'=>'12344',
109
+ 'amount'=>'106',
110
+ 'orderSource'=>'ecommerce',
111
+ 'card'=>{
112
+ 'type'=>'VI',
113
+ 'number' =>'4100000000000001',
114
+ 'expDate' =>'1210'
115
+ }}
116
+
117
+ batch = CnpBatchRequest.new
118
+ batch.create_new_batch('D:\Batches\\')
119
+ batch.credit(creditHash)
120
+
121
+ counts = batch.get_counts_and_amounts
122
+ assert_equal 1, counts[:credit][:numCredits]
123
+ assert_equal 106, counts[:credit][:creditAmount]
124
+ end
125
+
126
+ def test_add_auth_reversal
127
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
128
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
129
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
130
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
131
+ File.expects(:directory?).returns(true).once
132
+
133
+ authReversalHash = {
134
+ 'merchantId' => '101',
135
+ 'version'=>'8.8',
136
+ 'reportGroup'=>'Planets',
137
+ 'cnpTxnId'=>'12345678000',
138
+ 'amount'=>'106',
139
+ 'payPalNotes'=>'Notes'
140
+ }
141
+
142
+ batch = CnpBatchRequest.new
143
+ batch.create_new_batch('D:\Batches\\')
144
+ batch.auth_reversal(authReversalHash)
145
+
146
+ counts = batch.get_counts_and_amounts
147
+ assert_equal 1, counts[:authReversal][:numAuthReversals]
148
+ assert_equal 106, counts[:authReversal][:authReversalAmount]
149
+ end
150
+
151
+ def test_add_register_token_request
152
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
153
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
154
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
155
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
156
+ File.expects(:directory?).returns(true).once
157
+
158
+ registerTokenHash = {
159
+ 'merchantId' => '101',
160
+ 'version'=>'8.8',
161
+ 'reportGroup'=>'Planets',
162
+ 'orderId'=>'12344',
163
+ 'accountNumber'=>'1233456789103801'
164
+ }
165
+
166
+ batch = CnpBatchRequest.new
167
+ batch.create_new_batch('D:\Batches\\')
168
+ batch.register_token_request(registerTokenHash)
169
+
170
+ counts = batch.get_counts_and_amounts
171
+ assert_equal 1, counts[:numTokenRegistrations]
172
+ end
173
+
174
+ def test_cancel_subscription
175
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
176
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
177
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
178
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
179
+ File.expects(:directory?).returns(true).once
180
+
181
+ hash = {
182
+ 'merchantId' => '101',
183
+ 'version'=>'8.8',
184
+ 'reportGroup'=>'Planets',
185
+ 'subscriptionId'=>'100'
186
+ }
187
+
188
+ batch = CnpBatchRequest.new
189
+ batch.create_new_batch('D:\Batches\\')
190
+ batch.cancel_subscription(hash)
191
+
192
+ counts = batch.get_counts_and_amounts
193
+ assert_equal 1, counts[:numCancelSubscriptions]
194
+ end
195
+
196
+ def test_update_subscription
197
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
198
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
199
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
200
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
201
+ File.expects(:directory?).returns(true).once
202
+
203
+ hash = {
204
+ 'merchantId' => '101',
205
+ 'version'=>'8.8',
206
+ 'reportGroup'=>'Planets',
207
+ 'subscriptionId'=>'100',
208
+ 'planCode'=>'planCodeString',
209
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'cnp.com'}
210
+ }
211
+
212
+ batch = CnpBatchRequest.new
213
+ batch.create_new_batch('D:\Batches\\')
214
+ batch.update_subscription(hash)
215
+
216
+ counts = batch.get_counts_and_amounts
217
+ assert_equal 1, counts[:numUpdateSubscriptions]
218
+ end
219
+
220
+ def test_add_update_card_validation_num_on_token
221
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
222
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
223
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
224
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
225
+ File.expects(:directory?).returns(true).once
226
+
227
+ updateCardHash = {
228
+ 'merchantId' => '101',
229
+ 'version'=>'8.8',
230
+ 'reportGroup'=>'Planets',
231
+ 'orderId'=>'12344',
232
+ 'cnpToken'=>'1233456789103801',
233
+ 'cardValidationNum'=>'123'
234
+ }
235
+
236
+ batch = CnpBatchRequest.new
237
+ batch.create_new_batch('D:\Batches\\')
238
+ batch.update_card_validation_num_on_token(updateCardHash)
239
+
240
+ counts = batch.get_counts_and_amounts
241
+ assert_equal 1, counts[:numUpdateCardValidationNumOnTokens]
242
+ end
243
+
244
+ def test_add_force_capture
245
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
246
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
247
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
248
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
249
+ File.expects(:directory?).returns(true).once
250
+
251
+ forceCaptHash = {
252
+ 'merchantId' => '101',
253
+ 'version'=>'8.8',
254
+ 'reportGroup'=>'Planets',
255
+ 'cnpTxnId'=>'123456',
256
+ 'orderId'=>'12344',
257
+ 'amount'=>'106',
258
+ 'orderSource'=>'ecommerce',
259
+ 'card'=>{
260
+ 'type'=>'VI',
261
+ 'number' =>'4100000000000001',
262
+ 'expDate' =>'1210'
263
+ }}
264
+
265
+ batch = CnpBatchRequest.new
266
+ batch.create_new_batch('D:\Batches\\')
267
+ batch.force_capture(forceCaptHash)
268
+
269
+ counts = batch.get_counts_and_amounts
270
+ assert_equal 1, counts[:forceCapture][:numForceCaptures]
271
+ assert_equal 106, counts[:forceCapture][:forceCaptureAmount]
272
+ end
273
+
274
+ def test_add_capture
275
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
276
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
277
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
278
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
279
+ File.expects(:directory?).returns(true).once
280
+
281
+ captHash = {
282
+ 'merchantId' => '101',
283
+ 'version'=>'8.8',
284
+ 'reportGroup'=>'Planets',
285
+ 'cnpTxnId'=>'123456000',
286
+ 'amount'=>'106',
287
+ }
288
+
289
+ batch = CnpBatchRequest.new
290
+ batch.create_new_batch('D:\Batches\\')
291
+ batch.capture(captHash)
292
+
293
+ counts = batch.get_counts_and_amounts
294
+ assert_equal 1, counts[:capture][:numCaptures]
295
+ assert_equal 106, counts[:capture][:captureAmount]
296
+ end
297
+
298
+ def test_add_capture_given_auth
299
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
300
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
301
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
302
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
303
+ File.expects(:directory?).returns(true).once
304
+
305
+ captGivenAuthHash = {
306
+ 'merchantId' => '101',
307
+ 'version'=>'8.8',
308
+ 'reportGroup'=>'Planets',
309
+ 'orderId'=>'12344',
310
+ 'amount'=>'106',
311
+ 'authInformation' => {
312
+ 'authDate'=>'2002-10-09','authCode'=>'543216',
313
+ 'authAmount'=>'12345'
314
+ },
315
+ 'orderSource'=>'ecommerce',
316
+ 'card'=>{
317
+ 'type'=>'VI',
318
+ 'number' =>'4100000000000000',
319
+ 'expDate' =>'1210'
320
+ }}
321
+
322
+ batch = CnpBatchRequest.new
323
+ batch.create_new_batch('D:\Batches\\')
324
+ batch.capture_given_auth(captGivenAuthHash)
325
+
326
+ counts = batch.get_counts_and_amounts
327
+ assert_equal 1, counts[:captureGivenAuth][:numCaptureGivenAuths]
328
+ assert_equal 106, counts[:captureGivenAuth][:captureGivenAuthAmount]
329
+ end
330
+
331
+ def test_add_echeck_verification
332
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
333
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
334
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
335
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
336
+ File.expects(:directory?).returns(true).once
337
+
338
+ echeckVerificationHash = {
339
+ 'merchantId' => '101',
340
+ 'version'=>'8.8',
341
+ 'reportGroup'=>'Planets',
342
+ 'amount'=>'123456',
343
+ 'orderId'=>'12345',
344
+ 'orderSource'=>'ecommerce',
345
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
346
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'cnp.com'}
347
+ }
348
+
349
+ batch = CnpBatchRequest.new
350
+ batch.create_new_batch('D:\Batches\\')
351
+ batch.echeck_verification(echeckVerificationHash)
352
+
353
+ counts = batch.get_counts_and_amounts
354
+ assert_equal 1, counts[:echeckVerification][:numEcheckVerification]
355
+ assert_equal 123456, counts[:echeckVerification][:echeckVerificationAmount]
356
+ end
357
+
358
+ def test_add_echeck_credit
359
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
360
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
361
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
362
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
363
+ File.expects(:directory?).returns(true).once
364
+
365
+ echeckCreditHash = {
366
+ 'merchantId' => '101',
367
+ 'version'=>'8.8',
368
+ 'reportGroup'=>'Planets',
369
+ 'cnpTxnId'=>'123456789101112',
370
+ 'amount'=>'12'
371
+ }
372
+
373
+ batch = CnpBatchRequest.new
374
+ batch.create_new_batch('D:\Batches\\')
375
+ batch.echeck_credit(echeckCreditHash)
376
+
377
+ counts = batch.get_counts_and_amounts
378
+ assert_equal 1, counts[:echeckCredit][:numEcheckCredit]
379
+ assert_equal 12, counts[:echeckCredit][:echeckCreditAmount]
380
+ end
381
+
382
+ def test_add_echeck_redeposit
383
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
384
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
385
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
386
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
387
+ File.expects(:directory?).returns(true).once
388
+
389
+ echeckRedeopsitHash = {
390
+ 'merchantId' => '101',
391
+ 'version'=>'8.8',
392
+ 'reportGroup'=>'Planets',
393
+ 'cnpTxnId'=>'123456'
394
+ }
395
+
396
+ batch = CnpBatchRequest.new
397
+ batch.create_new_batch('D:\Batches\\')
398
+ batch.echeck_redeposit(echeckRedeopsitHash)
399
+
400
+ counts = batch.get_counts_and_amounts
401
+ assert_equal 1, counts[:numEcheckRedeposit]
402
+ end
403
+
404
+ def test_add_echeck_sale
405
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
406
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
407
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
408
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
409
+ File.expects(:directory?).returns(true).once
410
+
411
+ echeckSaleHash = {
412
+ 'merchantId' => '101',
413
+ 'version'=>'8.8',
414
+ 'reportGroup'=>'Planets',
415
+ 'amount'=>'123456',
416
+ 'verify'=>'true',
417
+ 'orderId'=>'12345',
418
+ 'orderSource'=>'ecommerce',
419
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
420
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'cnp.com'}
421
+ }
422
+
423
+ batch = CnpBatchRequest.new
424
+ batch.create_new_batch('D:\Batches\\')
425
+ batch.echeck_sale(echeckSaleHash)
426
+
427
+ counts = batch.get_counts_and_amounts
428
+ assert_equal 1, counts[:echeckSale][:numEcheckSales]
429
+ assert_equal 123456, counts[:echeckSale][:echeckSalesAmount]
430
+ end
431
+
432
+ def test_close_batch
433
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
434
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
435
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
436
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
437
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
438
+ File.expects(:rename).once
439
+ File.expects(:delete).once
440
+ File.expects(:directory?).returns(true).once
441
+
442
+ saleHash = {
443
+ 'reportGroup'=>'Planets',
444
+ 'id' => '006',
445
+ 'orderId'=>'12344',
446
+ 'amount'=>'6000',
447
+ 'orderSource'=>'ecommerce',
448
+ 'card'=>{
449
+ 'type'=>'VI',
450
+ 'number' =>'4100000000000001',
451
+ 'expDate' =>'1210'
452
+ }}
453
+
454
+ batch = CnpBatchRequest.new
455
+ batch.create_new_batch('D:\Batches\\')
456
+
457
+ batch.sale(saleHash)
458
+ batch.close_batch()
459
+ end
460
+
461
+ def test_open_existing_batch
462
+
463
+ saleHash = {
464
+ 'reportGroup'=>'Planets',
465
+ 'id' => '006',
466
+ 'orderId'=>'12344',
467
+ 'amount'=>'6000',
468
+ 'orderSource'=>'ecommerce',
469
+ 'card'=>{
470
+ 'type'=>'VI',
471
+ 'number' =>'4100000000000001',
472
+ 'expDate' =>'1210'
473
+ }}
474
+
475
+ open = sequence('open')
476
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
477
+
478
+ File.expects(:file?).returns(false).once.in_sequence(open)
479
+ File.expects(:directory?).returns(true).in_sequence(open)
480
+ File.expects(:file?).returns(false).in_sequence(open)
481
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
482
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
483
+ File.expects(:file?).returns(true).in_sequence(open)
484
+
485
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
486
+ File.expects(:rename).once.in_sequence(open)
487
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
488
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
489
+ batch1 = CnpBatchRequest.new
490
+ batch2 = CnpBatchRequest.new
491
+ batch2.expects(:build_batch_header).returns("foo")
492
+ batch1.create_new_batch('/usr/local/Batches/')
493
+ batch2.open_existing_batch(batch1.get_batch_name)
494
+ batch2.close_batch()
495
+ end
496
+
497
+ def test_build_batch_header
498
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
499
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
500
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
501
+ File.expects(:rename).once
502
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
503
+ File.expects(:delete).once
504
+ File.expects(:directory?).returns(true).once
505
+
506
+ batch = CnpBatchRequest.new
507
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(25)
508
+ hash.expects(:[]).returns('a').at_least(20)
509
+
510
+ batch.create_new_batch('/usr/local/Batches')
511
+ batch.close_batch()
512
+ end
513
+
514
+ def test_create_new_batch_missing_separator
515
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
516
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
517
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
518
+
519
+ batch = CnpBatchRequest.new
520
+ batch.create_new_batch('/usr/local')
521
+
522
+ assert batch.get_batch_name.include?('/usr/local/')
523
+ end
524
+
525
+ def test_create_new_batch_name_collision
526
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
527
+
528
+ fileExists = sequence('fileExists')
529
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
530
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
531
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
532
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
533
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
534
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
535
+
536
+ batch = CnpBatchRequest.new
537
+ batch.create_new_batch('/usr/local/')
538
+ end
539
+
540
+ def test_create_new_batch_when_full
541
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
542
+
543
+ batch = CnpBatchRequest.new
544
+ addTxn = sequence('addTxn')
545
+
546
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
547
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
548
+ batch.create_new_batch('/usr/local')
549
+
550
+ batch.get_counts_and_amounts.expects(:[]).with(:sale).returns({:numSales => 10, :saleAmount => 20}).twice.in_sequence(addTxn)
551
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(499999).in_sequence(addTxn)
552
+
553
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
554
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
555
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
556
+
557
+ batch.expects(:close_batch).once.in_sequence(addTxn)
558
+ batch.expects(:initialize).once.in_sequence(addTxn)
559
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
560
+
561
+ saleHash = {
562
+ 'reportGroup'=>'Planets',
563
+ 'id' => '006',
564
+ 'orderId'=>'12344',
565
+ 'amount'=>'6000',
566
+ 'orderSource'=>'ecommerce',
567
+ 'card'=>{
568
+ 'type'=>'VI',
569
+ 'number' =>'4100000000000001',
570
+ 'expDate' =>'1210'
571
+ }}
572
+
573
+ batch.sale(saleHash)
574
+
575
+ end
576
+
577
+ def test_complete_batch
578
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
579
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(9)
580
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(7)
581
+ File.expects(:rename).once
582
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
583
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
584
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
585
+ File.expects(:directory?).returns(false).once
586
+
587
+ authHash = {
588
+ 'reportGroup'=>'Planets',
589
+ 'orderId'=>'12344',
590
+ 'amount'=>'106',
591
+ 'orderSource'=>'ecommerce',
592
+ 'card'=>{
593
+ 'type'=>'VI',
594
+ 'number' =>'4100000000000001',
595
+ 'expDate' =>'1210'
596
+ }}
597
+
598
+ saleHash = {
599
+ 'reportGroup'=>'Planets',
600
+ 'id' => '006',
601
+ 'orderId'=>'12344',
602
+ 'amount'=>'6000',
603
+ 'orderSource'=>'ecommerce',
604
+ 'card'=>{
605
+ 'type'=>'VI',
606
+ 'number' =>'4100000000000001',
607
+ 'expDate' =>'1210'
608
+ }}
609
+
610
+ updateCardHash = {
611
+ 'merchantId' => '101',
612
+ 'version'=>'8.8',
613
+ 'reportGroup'=>'Planets',
614
+ 'id'=>'12345',
615
+ 'customerId'=>'0987',
616
+ 'orderId'=>'12344',
617
+ 'cnpToken'=>'1233456789103801',
618
+ 'cardValidationNum'=>'123'
619
+ }
620
+
621
+ batch = CnpBatchRequest.new
622
+ batch.create_new_batch('/usr/local/Batches/')
623
+
624
+ 5.times(){ batch.authorization(authHash) }
625
+ 2.times(){ batch.sale(saleHash) }
626
+
627
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
628
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
629
+ batch.close_batch()
630
+ counts = batch.get_counts_and_amounts
631
+
632
+ assert_equal 5, counts[:auth][:numAuths]
633
+ #assert_equal 212, counts[:auth][:authAmount]
634
+ assert_equal 2, counts[:sale][:numSales]
635
+ #assert_equal 6000, counts[:sale][:saleAmount]
636
+ end
637
+
638
+ def test_PFIF_instruction_txn
639
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'9.3'}).once
640
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(13)
641
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(11)
642
+ File.expects(:rename).once
643
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
644
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
645
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
646
+ File.expects(:directory?).returns(false).once
647
+
648
+ submerchantCreditHash = {
649
+ 'reportGroup'=>'Planets',
650
+ 'orderId'=>'12344',
651
+ 'fundingSubmerchantId'=>'123456',
652
+ 'submerchantName'=>'001',
653
+ 'fundsTransferId'=>'1234567',
654
+ 'amount'=>'106',
655
+ 'accountInfo' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'}
656
+ }
657
+
658
+ vendorCreditHash = {
659
+ 'reportGroup'=>'Planets',
660
+ 'orderId'=>'12344',
661
+ 'fundingSubmerchantId'=>'123456',
662
+ 'vendorName'=>'001',
663
+ 'fundsTransferId'=>'1234567',
664
+ 'amount'=>'107',
665
+ 'accountInfo' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'}
666
+ }
667
+
668
+ payFacCreditHash = {
669
+ 'reportGroup'=>'Planets',
670
+ 'orderId'=>'12344',
671
+ 'fundingSubmerchantId'=>'123456',
672
+ 'fundsTransferId'=>'1234567',
673
+ 'amount'=>'108',
674
+ }
675
+
676
+ reserveCreditHash = {
677
+ 'reportGroup'=>'Planets',
678
+ 'orderId'=>'12344',
679
+ 'fundingSubmerchantId'=>'123456',
680
+ 'fundsTransferId'=>'1234567',
681
+ 'amount'=>'109',
682
+ }
683
+
684
+ physicalCheckCreditHash = {
685
+ 'reportGroup'=>'Planets',
686
+ 'orderId'=>'12344',
687
+ 'fundingSubmerchantId'=>'123456',
688
+ 'fundsTransferId'=>'1234567',
689
+ 'amount'=>'110',
690
+ }
691
+
692
+ submerchantDebitHash = {
693
+ 'reportGroup'=>'Planets',
694
+ 'orderId'=>'12344',
695
+ 'fundingSubmerchantId'=>'123456',
696
+ 'submerchantName'=>'001',
697
+ 'fundsTransferId'=>'1234567',
698
+ 'amount'=>'106',
699
+ 'accountInfo' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'}
700
+ }
701
+
702
+ vendorDebitHash = {
703
+ 'reportGroup'=>'Planets',
704
+ 'orderId'=>'12344',
705
+ 'fundingSubmerchantId'=>'123456',
706
+ 'vendorName'=>'001',
707
+ 'fundsTransferId'=>'1234567',
708
+ 'amount'=>'107',
709
+ 'accountInfo' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'}
710
+ }
711
+
712
+ payFacDebitHash = {
713
+ 'reportGroup'=>'Planets',
714
+ 'orderId'=>'12344',
715
+ 'fundingSubmerchantId'=>'123456',
716
+ 'fundsTransferId'=>'1234567',
717
+ 'amount'=>'108',
718
+ }
719
+
720
+ reserveDebitHash = {
721
+ 'reportGroup'=>'Planets',
722
+ 'orderId'=>'12344',
723
+ 'fundingSubmerchantId'=>'123456',
724
+ 'fundsTransferId'=>'1234567',
725
+ 'amount'=>'109',
726
+ }
727
+
728
+ physicalCheckDebitHash = {
729
+ 'reportGroup'=>'Planets',
730
+ 'orderId'=>'12344',
731
+ 'fundingSubmerchantId'=>'123456',
732
+ 'fundsTransferId'=>'1234567',
733
+ 'amount'=>'110',
734
+ }
735
+
736
+ fastAccessFundingHash = {
737
+ 'reportGroup'=>'Planets',
738
+ 'orderId'=>'12344',
739
+ 'fundingSubmerchantId'=>'123456',
740
+ 'submerchantName' => 'Colin',
741
+ 'fundsTransferId'=>'1234567',
742
+ 'amount'=>'111',
743
+ }
744
+
745
+ batch = CnpBatchRequest.new
746
+ batch.create_new_batch('/usr/local/Batches/')
747
+
748
+ batch.submerchant_credit(submerchantCreditHash)
749
+ batch.payFac_credit(payFacCreditHash)
750
+ batch.vendor_credit(vendorCreditHash)
751
+ batch.reserve_credit(reserveCreditHash)
752
+ batch.physical_check_credit(physicalCheckCreditHash)
753
+ batch.submerchant_debit(submerchantDebitHash)
754
+ batch.payFac_debit(payFacDebitHash)
755
+ batch.vendor_debit(vendorDebitHash)
756
+ batch.reserve_debit(reserveDebitHash)
757
+ batch.physical_check_debit(physicalCheckDebitHash)
758
+ batch.fast_access_funding(fastAccessFundingHash)
759
+
760
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
761
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
762
+ batch.close_batch()
763
+ counts = batch.get_counts_and_amounts
764
+
765
+ assert_equal 1, counts[:submerchantCredit ][:numSubmerchantCredit ]
766
+ assert_equal 1, counts[:payFacCredit ][:numPayFacCredit ]
767
+ assert_equal 1, counts[:reserveCredit ][:numReserveCredit ]
768
+ assert_equal 1, counts[:vendorCredit ][:numVendorCredit ]
769
+ assert_equal 1, counts[:physicalCheckCredit ][:numPhysicalCheckCredit ]
770
+ assert_equal 106, counts[:submerchantCredit ][:submerchantCreditAmount ]
771
+ assert_equal 108, counts[:payFacCredit ][:payFacCreditAmount ]
772
+ assert_equal 109, counts[:reserveCredit ][:reserveCreditAmount ]
773
+ assert_equal 107, counts[:vendorCredit ][:vendorCreditAmount ]
774
+ assert_equal 110, counts[:physicalCheckCredit ][:physicalCheckCreditAmount ]
775
+
776
+ assert_equal 1, counts[:submerchantDebit ][:numSubmerchantDebit ]
777
+ assert_equal 1, counts[:payFacDebit ][:numPayFacDebit ]
778
+ assert_equal 1, counts[:reserveDebit ][:numReserveDebit ]
779
+ assert_equal 1, counts[:vendorDebit ][:numVendorDebit ]
780
+ assert_equal 1, counts[:physicalCheckDebit ][:numPhysicalCheckDebit ]
781
+ assert_equal 106, counts[:submerchantDebit ][:submerchantDebitAmount ]
782
+ assert_equal 108, counts[:payFacDebit ][:payFacDebitAmount ]
783
+ assert_equal 109, counts[:reserveDebit ][:reserveDebitAmount ]
784
+ assert_equal 107, counts[:vendorDebit ][:vendorDebitAmount ]
785
+ assert_equal 110, counts[:physicalCheckDebit ][:physicalCheckDebitAmount ]
786
+
787
+ assert_equal 111, counts[:fastAccessFunding ][:fastAccessFundingAmount ]
788
+ assert_equal 1, counts[:fastAccessFunding ][:numFastAccessFunding ]
789
+ end
790
+ end
791
+ end