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,253 @@
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 TestCnpOnlineRequest < Test::Unit::TestCase
32
+ def test_set_merchant_id
33
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}})
34
+ cnp = CnpOnlineRequest.new
35
+ assert_equal '2', cnp.send(:get_merchant_id, {'merchantId'=>'2'})
36
+ assert_equal '1', cnp.send(:get_merchant_id, {'NotMerchantId'=>'2'})
37
+ end
38
+
39
+ def test_simple
40
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
41
+ hash = {
42
+ 'reportGroup'=>'Planets',
43
+ 'orderId'=>'12344',
44
+ 'amount'=>'106',
45
+ 'orderSource'=>'ecommerce',
46
+ 'card'=>{
47
+ 'type'=>'VI',
48
+ 'number' =>'4100000000000001',
49
+ 'expDate' =>'1210'
50
+ }}
51
+
52
+ CnpXmlMapper.expects(:request).with(regexp_matches(/<cnpOnlineRequest .*/m), is_a(Hash))
53
+ response = CnpOnlineRequest.new.authorization(hash)
54
+ end
55
+
56
+ def test_authorization_attributes
57
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
58
+ hash={
59
+ 'reportGroup'=>'Planets',
60
+ 'id' => '003',
61
+ 'orderId'=>'12344',
62
+ 'amount'=>'106',
63
+ 'orderSource'=>'ecommerce',
64
+ 'card'=>{
65
+ 'type'=>'VI',
66
+ 'number' =>'4100000000000001',
67
+ 'expDate' =>'1210'
68
+ }}
69
+
70
+ CnpXmlMapper.expects(:request).with(regexp_matches(/.*<authorization ((reportGroup="Planets" id="003")|(id="003" reportGroup="Planets")).*/m), is_a(Hash))
71
+ response = CnpOnlineRequest.new.authorization(hash)
72
+ end
73
+
74
+ def test_authorization_elements
75
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
76
+ hash={
77
+ 'reportGroup'=>'Planets',
78
+ 'id' => '004',
79
+ 'orderId'=>'12344',
80
+ 'amount'=>'106',
81
+ 'orderSource'=>'ecommerce',
82
+ 'card'=>{
83
+ 'type'=>'VI',
84
+ 'number' =>'4100000000000001',
85
+ 'expDate' =>'1210'
86
+ }}
87
+
88
+ CnpXmlMapper.expects(:request).with(regexp_matches(/.*<authorization.*<orderId>12344.*<amount>106.*<orderSource>ecommerce.*/m), is_a(Hash))
89
+ response = CnpOnlineRequest.new.authorization(hash)
90
+ end
91
+
92
+ def test_authorization_card_field
93
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
94
+ hash={
95
+ 'reportGroup'=>'Planets',
96
+ 'id' => '005',
97
+ 'orderId'=>'12344',
98
+ 'amount'=>'106',
99
+ 'orderSource'=>'ecommerce',
100
+ 'card'=>{
101
+ 'type'=>'VI',
102
+ 'number' =>'4100000000000001',
103
+ 'expDate' =>'1210'
104
+ }}
105
+
106
+ CnpXmlMapper.expects(:request).with(regexp_matches(/.*<authorization.*<card>.*<number>4100000000000001.*<expDate>1210.*/m), is_a(Hash))
107
+ response = CnpOnlineRequest.new.authorization(hash)
108
+ end
109
+
110
+ def test_sale_card_field
111
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
112
+ hash = {
113
+ 'reportGroup'=>'Planets',
114
+ 'id' => '006',
115
+ 'orderId'=>'12344',
116
+ 'amount'=>'106',
117
+ 'orderSource'=>'ecommerce',
118
+ 'card'=>{
119
+ 'type'=>'VI',
120
+ 'number' =>'4100000000000001',
121
+ 'expDate' =>'1210'
122
+ }}
123
+
124
+ CnpXmlMapper.expects(:request).with(regexp_matches(/<cnpOnlineRequest.*<sale.*<card>.*<number>4100000000000001.*<expDate>1210.*/m), is_a(Hash))
125
+ response = CnpOnlineRequest.new.sale(hash)
126
+ end
127
+
128
+ def test_capture_amount_unset_should_not_be_in_xml
129
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
130
+ hash={
131
+ 'id' => '006',
132
+ 'reportGroup'=>'Planets',
133
+ 'cnpTxnId'=>'123456789012345678'
134
+ }
135
+
136
+ CnpXmlMapper.expects(:request).with(Not(regexp_matches(/.*amount.*/m)), is_a(Hash))
137
+ response = CnpOnlineRequest.new.capture(hash)
138
+ end
139
+
140
+ def test_force_capture_amount_unset_should_not_be_in_xml
141
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
142
+ hash={
143
+ 'id' => '006',
144
+ 'orderId'=>'12344',
145
+ 'reportGroup'=>'Planets',
146
+ 'orderSource'=>'ecommerce',
147
+ 'cnpTxnId'=>'123456789012345678'
148
+ }
149
+
150
+ CnpXmlMapper.expects(:request).with(Not(regexp_matches(/.*amount.*/m)), is_a(Hash))
151
+ response = CnpOnlineRequest.new.force_capture(hash)
152
+ end
153
+
154
+ def test_amount_is_not_required_in_echeck_credit
155
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
156
+ hash={
157
+ 'id' => '006',
158
+ 'orderId'=>'12344',
159
+ 'reportGroup'=>'Planets',
160
+ 'orderSource'=>'ecommerce',
161
+ 'cnpTxnId'=>'123456789012345678',
162
+ }
163
+
164
+ CnpXmlMapper.expects(:request).with(Not(regexp_matches(/.*amount.*/m)), is_a(Hash))
165
+
166
+ response = CnpOnlineRequest.new.echeck_credit(hash)
167
+ end
168
+
169
+ def test_amount_is_not_required_in_echeck_sale
170
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
171
+ hash={
172
+ 'id' => '006',
173
+ 'orderId'=>'12344',
174
+ 'reportGroup'=>'Planets',
175
+ 'orderSource'=>'ecommerce',
176
+ 'cnpTxnId'=>'123456789012345678',
177
+ }
178
+
179
+ CnpXmlMapper.expects(:request).with(Not(regexp_matches(/.*amount.*/m)), is_a(Hash))
180
+ response = CnpOnlineRequest.new.echeck_sale(hash)
181
+ end
182
+
183
+ def test_choice_between_card_token
184
+ start_hash = {
185
+ 'orderId'=>'12344',
186
+ 'merchantId'=>'101',
187
+ 'reportGroup'=>'Planets',
188
+ 'amount'=>'101',
189
+ 'orderSource'=>'ecommerce'
190
+ }
191
+
192
+ card_only = {
193
+ 'card' => {
194
+ 'type' => 'VI',
195
+ 'number' => '1111222233334444'
196
+ }
197
+ }
198
+
199
+ CnpXmlMapper.expects(:request).with(regexp_matches(/.*card.*/m), is_a(Hash))
200
+ CnpOnlineRequest.new.authorization(start_hash.merge(card_only))
201
+ end
202
+
203
+ def test_choice_between_card_token2
204
+ start_hash = {
205
+ 'orderId'=>'12344',
206
+ 'merchantId'=>'101',
207
+ 'reportGroup'=>'Planets',
208
+ 'amount'=>'101',
209
+ 'orderSource'=>'ecommerce'
210
+ }
211
+
212
+ token_only = {
213
+ 'token'=> {
214
+ 'cnpToken' => '1111222233334444'
215
+ }
216
+ }
217
+
218
+ CnpXmlMapper.expects(:request).with(regexp_matches(/.*token.*/m), is_a(Hash))
219
+ CnpOnlineRequest.new.authorization(start_hash.merge(token_only))
220
+ end
221
+
222
+
223
+
224
+ def test_sale_paypal_order_complete_typo
225
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
226
+ hash={
227
+ 'reportGroup'=>'Planets',
228
+ 'id' => '006',
229
+ 'orderId'=>'12344',
230
+ 'amount'=>'106',
231
+ 'orderSource'=>'ecommerce',
232
+ 'payPalOrderComplete'=>'true',
233
+ 'card'=>{
234
+ 'type'=>'VI',
235
+ 'number' =>'4100000000000001',
236
+ 'expDate' =>'1210'
237
+ }}
238
+
239
+ CnpXmlMapper.expects(:request).with(regexp_matches(/<cnpOnlineRequest.*<sale.*<payPalOrderComplete>true<\/payPalOrderComplete>.*/m), is_a(Hash))
240
+ response = CnpOnlineRequest.new.sale(hash)
241
+ end
242
+
243
+ def test_version_matches_sdk_major_and_minor_version_ignoring_config
244
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'})
245
+ hash={
246
+ 'cnpTxnId' => '006'
247
+ }
248
+ CnpXmlMapper.expects(:request).with(regexp_matches(/<cnpOnlineRequest.*version="12\.3".*/m), is_a(Hash))
249
+ response = CnpOnlineRequest.new.void(hash)
250
+ end
251
+
252
+ end
253
+ end
@@ -0,0 +1,317 @@
1
+ =begin
2
+ Copyright (c) 2017 Vantiv eCommerce
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ OTHER DEALINGS IN THE SOFTWARE.
21
+ =end
22
+ require File.expand_path("../../../lib/CnpOnline",__FILE__)
23
+ require 'test/unit'
24
+ require 'mocha/setup'
25
+
26
+ module CnpOnline
27
+
28
+ class TestCnpRequest < Test::Unit::TestCase
29
+
30
+ def test_create_with_file
31
+ request = CnpRequest.new({'sessionId'=>'8675309',
32
+ 'user'=>'john',
33
+ 'password'=>'tinkleberry'})
34
+ message = ""
35
+ File.expects(:file?).with('/durrrrrr').returns(true).once
36
+ request.create_new_cnp_request('/durrrrrr')
37
+
38
+ rescue RuntimeError=> e
39
+ message = e.message
40
+
41
+ assert_equal "Entered a file not a path.",message
42
+ end
43
+
44
+ def test_create_with_no_sep
45
+ request = CnpRequest.new({'sessionId'=>'8675309',
46
+ 'user'=>'john',
47
+ 'password'=>'tinkleberry'})
48
+ File.expects(:open).twice
49
+ request.create_new_cnp_request('/usr/local')
50
+ assert request.get_path_to_batches.include?('/usr/local/')
51
+ end
52
+
53
+ def test_create_name_collision
54
+ request = CnpRequest.new({'sessionId'=>'8675309',
55
+ 'user'=>'john',
56
+ 'password'=>'tinkleberry'})
57
+
58
+ create_new = sequence('create_new')
59
+ File.expects(:file?).returns(false).in_sequence(create_new)
60
+ File.expects(:file?).returns(true).once.in_sequence(create_new) #yayay short circuiting
61
+ File.expects(:file?).returns(false).once.in_sequence(create_new)
62
+ File.expects(:file?).returns(false).twice.in_sequence(create_new) #or's don't quit
63
+ File.expects(:open).twice.in_sequence(create_new)
64
+
65
+ request.create_new_cnp_request('/usr/local')
66
+ end
67
+
68
+ def test_create_normal
69
+ request = CnpRequest.new({'sessionId'=>'8675309',
70
+ 'user'=>'john',
71
+ 'password'=>'tinkleberry'})
72
+
73
+ create_new = sequence('create_new')
74
+ File.expects(:file?).returns(false).once.in_sequence(create_new)
75
+ File.expects(:file?).returns(false).twice.in_sequence(create_new)
76
+ File.expects(:open).once.in_sequence(create_new)
77
+ File.expects(:open).once.in_sequence(create_new)
78
+
79
+ request.create_new_cnp_request('/usr/local')
80
+ end
81
+
82
+ def test_add_rfr_request_cnp_session
83
+ add_rfr = sequence('add_rfr')
84
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1).in_sequence(add_rfr)
85
+
86
+ File.expects(:file?).with('/usr/srv').returns(false).in_sequence(add_rfr)
87
+ File.expects(:directory?).with('/usr/srv/').returns(true).in_sequence(add_rfr)
88
+ File.expects(:open).with(regexp_matches(/request_\d+\z/), 'a+').in_sequence(add_rfr)
89
+ File.expects(:rename).with(regexp_matches(/request_\d+\z/), regexp_matches(/request_\d+.complete\z/)).in_sequence(add_rfr)
90
+
91
+ request = CnpRequest.new({'sessionId'=>'8675309',
92
+ 'user'=>'john',
93
+ 'password'=>'tinkleberry'})
94
+
95
+ request.add_rfr_request({'cnpSessionId' => '137813712'}, '/usr/srv')
96
+
97
+ end
98
+
99
+ def test_commit_batch_with_batch
100
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
101
+
102
+ request = CnpRequest.new({'sessionId'=>'8675309',
103
+ 'user'=>'john',
104
+ 'password'=>'tinkleberry'})
105
+ File.expects(:file?).returns(false).once
106
+ File.expects(:file?).returns(false).twice #or's don't quit
107
+ File.expects(:open).twice
108
+ File.expects(:directory?).returns(true).once
109
+ request.create_new_cnp_request("/usr/srv/batches")
110
+
111
+ batch = CnpBatchRequest.new
112
+ File.expects(:open).twice
113
+ File.expects(:file?).returns(false).twice
114
+ File.expects(:directory?).returns(true).once
115
+ batch.create_new_batch('/usr/srv/batches')
116
+ File.expects(:rename).once
117
+ File.expects(:open).once
118
+ File.expects(:delete).once
119
+ batch.close_batch()
120
+
121
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
122
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
123
+ request.commit_batch(batch)
124
+ end
125
+
126
+ def test_commit_batch_with_path
127
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
128
+
129
+ request = CnpRequest.new({'sessionId'=>'8675309',
130
+ 'user'=>'john',
131
+ 'password'=>'tinkleberry'})
132
+ File.expects(:file?).returns(false).once
133
+ File.expects(:file?).returns(false).twice #or's don't quit
134
+ File.expects(:open).twice
135
+ File.expects(:directory?).returns(true).once
136
+ request.create_new_cnp_request("/usr/srv/batches")
137
+
138
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+')
139
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/))
140
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
141
+ end
142
+
143
+ def test_add_bad_object
144
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
145
+ request = CnpRequest.new({})
146
+ request.commit_batch({:apple => "pear"})
147
+ test = ""
148
+ rescue RuntimeError => e
149
+ test = e.message
150
+ assert_equal "You entered neither a path nor a batch. Game over :(" ,test
151
+ end
152
+
153
+ def test_add_open_batch
154
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2)
155
+ File.expects(:open).with(regexp_matches(/\/usr\/srv\/.*/), 'a+').times(2)
156
+
157
+ Dir.expects(:mkdir).with('/usr/srv/batches/').once
158
+ batch = CnpBatchRequest.new
159
+ batch.create_new_batch('/usr/srv/batches')
160
+ request = CnpRequest.new({'sessionId'=>'8675309',
161
+ 'user'=>'john',
162
+ 'password'=>'tinkleberry'})
163
+
164
+ close_and_add = sequence('close_and_add')
165
+ batch.expects(:get_batch_name).returns("/usr/srv/batches/batch_123123131231").once.in_sequence(close_and_add)
166
+ batch.expects(:close_batch).once.in_sequence(close_and_add)
167
+ batch.expects(:get_batch_name).returns(str = "/usr/srv/batches/batch_123123131231.closed-1000").once.in_sequence(close_and_add)
168
+ str.expects(:index).returns(7).once.in_sequence(close_and_add)
169
+ File.expects(:open).once.in_sequence(close_and_add)
170
+ File.expects(:delete).once.in_sequence(close_and_add)
171
+ request.commit_batch(batch)
172
+ end
173
+
174
+ def test_batch_too_big
175
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(1)
176
+
177
+ request = CnpRequest.new({'sessionId'=>'8675309',
178
+ 'user'=>'john',
179
+ 'password'=>'tinkleberry'})
180
+ File.expects(:file?).returns(false).once
181
+ File.expects(:file?).returns(false).twice #or's don't quit
182
+ File.expects(:open).twice
183
+ File.expects(:directory?).returns(true).once
184
+ request.create_new_cnp_request("/usr/srv/batches")
185
+ create_new = sequence('create_new')
186
+
187
+ File.expects(:open).with(regexp_matches(/.*_batches.*/), 'a+').times(5)
188
+ File.expects(:delete).with(regexp_matches(/.*\.closed.*/)).times(5)
189
+ 5.times {
190
+
191
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
192
+ }
193
+
194
+ request.expects(:finish_request).once
195
+ request.expects(:initialize).once
196
+ request.expects(:create_new_cnp_request).once
197
+ request.commit_batch("/usr/srv/batches/batch_123123131231.closed-100000")
198
+ end
199
+
200
+ #TODO: see of we can get deeper with mocking the node returned
201
+ def test_process_response_success
202
+ xml = sequence("xml")
203
+ LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new).in_sequence(xml)
204
+ reader.expects(:read).once.in_sequence(xml)
205
+ reader.expects(:get_attribute).with('response').returns("0").in_sequence(xml)
206
+ reader.expects(:read).once.in_sequence(xml)
207
+ reader.expects(:node).returns(node = LibXML::XML::Node.new("cnpResponse")).twice.in_sequence(xml)
208
+
209
+ request = CnpRequest.new({})
210
+ request.process_response(Dir.pwd + '/responses/good_xml.xml' ,
211
+ DefaultCnpListener.new{|txn| puts txn["type"]} ,
212
+ DefaultCnpListener.new{|batch| } )
213
+ end
214
+
215
+ def test_process_response_xml_error
216
+ LibXML::XML::Reader.expects(:file).once.returns(reader = LibXML::XML::Reader.new)
217
+ reader.expects(:read).once
218
+ reader.expects(:get_attribute).with('response').twice.returns(4)
219
+ reader.expects(:get_attribute).with("message").returns("Error validating xml data against the schema")
220
+
221
+ request = CnpRequest.new({})
222
+ response = ''
223
+ begin
224
+ request.process_response(Dir.pwd + '/responses/bad_xml.xml' ,
225
+ DefaultCnpListener.new{|txn| puts txn["type"]} ,
226
+ DefaultCnpListener.new{|batch| } )
227
+ rescue Exception => e
228
+ response = e.message
229
+ end
230
+ assert_equal "Error parsing Cnp Request: Error validating xml data against the schema", response.to_s
231
+ end
232
+
233
+ def test_process_responses
234
+ request = CnpRequest.new({})
235
+ listener = DefaultCnpListener.new
236
+ args = {:transaction_listener=>listener,:path_to_responses=>"fake/path/"}
237
+ args.expects(:[]).with(:transaction_listener)
238
+ args.expects(:[]).with(:batch_listener).returns(nil)
239
+ args.expects(:[]).with(:path_to_responses).returns("fake/path/")
240
+ args.expects(:[]).twice.with(:deleteBatchFiles)
241
+ args.expects(:[]).with("deleteBatchFiles")
242
+ Dir.expects(:foreach).with("fake/path/")
243
+
244
+ request.process_responses(args)
245
+ end
246
+
247
+ def test_get_responses_from_server
248
+ request = CnpRequest.new({})
249
+ resp_seq = sequence("resp_seq")
250
+ args = {:responses_expected=>4, :response_path=>"new/path", :sftp_username=>"periwinkle",:sftp_password=>"password", :sftp_url=>"reddit.com"}
251
+
252
+ File.expects(:directory?).with("new/path/").returns(false).once.in_sequence(resp_seq)
253
+ Dir.expects(:mkdir).with("new/path/").once.in_sequence(resp_seq)
254
+ Net::SFTP.expects(:start).once.with("reddit.com", "periwinkle", :password=>"password")
255
+
256
+ request.get_responses_from_server(args)
257
+ end
258
+
259
+ def test_send_over_stream
260
+ request = CnpRequest.new({})
261
+ req_seq = sequence('request')
262
+
263
+ File.expects(:directory?).with(regexp_matches(/responses\//)).once.returns(false).in_sequence(req_seq)
264
+ Dir.expects(:mkdir).with(regexp_matches(/responses\//)).once.in_sequence(req_seq)
265
+ Dir.expects(:foreach).once.in_sequence(req_seq)
266
+
267
+ request.send_to_cnp_stream({:fast_url=>"www.redit.com", :fast_port=>"2313"})
268
+ end
269
+
270
+ def test_send_over_stream_bad_crds
271
+ request = CnpRequest.new({})
272
+
273
+ assert_raise ArgumentError do
274
+ request.send_to_cnp_stream({:fast_url=>"", :fast_port=>""})
275
+ end
276
+ end
277
+ #Outputs an example CnpRequest doc in the current directory
278
+ # def test_finish_request_xml! #that's why the name has a bang
279
+ # # see the bang up there ^^^ that means we ACTUALLY edit the file system
280
+ # # make sure to clear this; otherwise, you're gonna have a bad time.
281
+ # path = Dir.pwd
282
+ #
283
+ # saleHash = {
284
+ # 'reportGroup'=>'Planets',
285
+ # 'id' => '006',
286
+ # 'orderId'=>'12344',
287
+ # 'amount'=>'6000',
288
+ # 'orderSource'=>'ecommerce',
289
+ # 'card'=>{
290
+ # 'type'=>'VI',
291
+ # 'number' =>'4100000000000001',
292
+ # 'expDate' =>'1210'
293
+ # }}
294
+ #
295
+ # request = CnpRequest.new({'sessionId'=>'8675309',
296
+ # 'user'=>'john',
297
+ # 'password'=>'tinkleberry'})
298
+ # request.create_new_cnp_request(path)
299
+ #
300
+ #
301
+ # #5.times{
302
+ # batch = CnpBatchRequest.new
303
+ # batch.create_new_batch(path)
304
+ # puts "Batch is at: " + batch.get_batch_name
305
+ #
306
+ # #10.times{
307
+ # batch.sale(saleHash)
308
+ # #batch.update_card_validation_num_on_token(options)
309
+ # #}
310
+ #
311
+ # batch.close_batch()
312
+ # request.commit_batch(batch)
313
+ # #}
314
+ # request.finish_request
315
+ # end
316
+ end
317
+ end