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,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
|
+
|
26
|
+
require 'logger'
|
27
|
+
|
28
|
+
#
|
29
|
+
# Handles round trip of transactions
|
30
|
+
# Maps the request to Cnp XML -> Sends XML payload to Cnp via HTTP(S) -> formats XML response into a Ruby hash and returns it
|
31
|
+
#
|
32
|
+
module CnpOnline
|
33
|
+
class CnpXmlMapper
|
34
|
+
def CnpXmlMapper.request(request_xml, config_hash)
|
35
|
+
logger = initialize_logger(config_hash)
|
36
|
+
|
37
|
+
logger.debug request_xml
|
38
|
+
# get the Cnp Online Response from the API server over HTTP
|
39
|
+
response_xml = Communications.http_post(request_xml,config_hash)
|
40
|
+
logger.debug response_xml
|
41
|
+
|
42
|
+
# create response object from xml returned form the Cnp API
|
43
|
+
response_object = XMLObject.new(response_xml)
|
44
|
+
|
45
|
+
# Check if the response xml is valid.
|
46
|
+
if (response_object.response == "0")
|
47
|
+
return response_object
|
48
|
+
else
|
49
|
+
raise("Error with http response, code: " + response_object.response + ", message: " + response_object.message)
|
50
|
+
end
|
51
|
+
|
52
|
+
return response_object
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def self.initialize_logger(config_hash)
|
58
|
+
# Sadly, this needs to be static (the alternative would be to change the CnpXmlMapper.request API
|
59
|
+
# to accept a Configuration instance instead of the config_hash)
|
60
|
+
Configuration.logger ||= default_logger config_hash['printxml'] ? Logger::DEBUG : Logger::INFO
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.default_logger(level) # :nodoc:
|
64
|
+
logger = Logger.new(STDOUT)
|
65
|
+
logger.level = level
|
66
|
+
# Backward compatible logging format for pre 8.16
|
67
|
+
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
|
68
|
+
logger
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,185 @@
|
|
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
|
+
|
27
|
+
module CnpOnline
|
28
|
+
class CommManager
|
29
|
+
attr_reader :REQUEST_RESULT_RESPONSE_RECEIVED, :REQUEST_RESULT_CONNECTION_FAILED, :REQUEST_RESULT_RESPONSE_TIMEOUT,
|
30
|
+
:multiSite, :legacyUrl, :multiSiteThreshold, :multiSiteUrls, :maxHoursWithoutSwitch, :currentMultiSiteUrlIndex,
|
31
|
+
:errorCount, :lastSiteSwitchTime
|
32
|
+
attr_writer :lastSiteSwitchTime
|
33
|
+
|
34
|
+
@@manager = nil
|
35
|
+
|
36
|
+
def manager
|
37
|
+
@@manager
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.manager
|
41
|
+
@@manager
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(config)
|
46
|
+
@REQUEST_RESULT_RESPONSE_RECEIVED = 1
|
47
|
+
@REQUEST_RESULT_CONNECTION_FAILED = 2
|
48
|
+
@REQUEST_RESULT_RESPONSE_TIMEOUT = 3
|
49
|
+
|
50
|
+
@config_hash = config
|
51
|
+
@multiSite = @config_hash['multiSite'] != nil ? @config_hash['multiSite'] : false
|
52
|
+
@legacyUrl = @config_hash['url']
|
53
|
+
@multiSiteUrls = Array.new
|
54
|
+
@errorCount = 0
|
55
|
+
@currentMultiSiteUrlIndex = 0
|
56
|
+
@multiSiteThreshold = 5
|
57
|
+
@lastSiteSwitchTime = 0
|
58
|
+
# @maxHoursWithoutSwitch = @config_hash['maxsHoursWithoutSwitch']
|
59
|
+
@maxHoursWithoutSwitch = 48
|
60
|
+
@printDebug = @config_hash['printMultiSiteDebug'] #get false as default
|
61
|
+
|
62
|
+
|
63
|
+
if (to_boolean(@multiSite))
|
64
|
+
|
65
|
+
for i in 1..2 do
|
66
|
+
@siteUrl = @config_hash["multSiteUrl" + i.to_s]
|
67
|
+
if (@siteUrl == '' || @siteUrl == nil)
|
68
|
+
break
|
69
|
+
end
|
70
|
+
@multiSiteUrls << @siteUrl
|
71
|
+
end
|
72
|
+
|
73
|
+
if (@multiSiteUrls.length == 0)
|
74
|
+
@multiSite = false
|
75
|
+
else
|
76
|
+
@multiSiteUrls.shuffle
|
77
|
+
@currentMultiSiteUrlIndex = 0
|
78
|
+
@errorCount = 0
|
79
|
+
|
80
|
+
_threshold = @config_hash['multiSiteThreshold']
|
81
|
+
if (_threshold != nil)
|
82
|
+
if (_threshold > 0 && _threshold < 100)
|
83
|
+
@multiSiteThreshold = _threshold
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
_maxHours = @config_hash['maxsHoursWithoutSwitch']
|
88
|
+
if (_maxHours != nil)
|
89
|
+
if (_maxHours >= 0 && _maxHours < 300)
|
90
|
+
@maxHoursWithoutSwitch = _maxHours
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
@lastSiteSwitchTime = Time.now.to_i * 1000
|
95
|
+
end
|
96
|
+
# end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def self.instance(config)
|
102
|
+
if (@@manager == nil)
|
103
|
+
@@manager = CommManager.new(config)
|
104
|
+
end
|
105
|
+
return @@manager
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.reset
|
109
|
+
@@manager = nil
|
110
|
+
end
|
111
|
+
|
112
|
+
def findUrl()
|
113
|
+
|
114
|
+
_url = @legacyUrl
|
115
|
+
if (to_boolean(@multiSite))
|
116
|
+
_switchSite = false
|
117
|
+
_switchReason = ''
|
118
|
+
_currentUrl = @multiSiteUrls.at(@currentMultiSiteUrlIndex)
|
119
|
+
|
120
|
+
if (@errorCount < @multiSiteThreshold)
|
121
|
+
if (@maxHoursWithoutSwitch > 0)
|
122
|
+
_diffSinceSwitch = ((Time.now.to_i * 1000) - @lastSiteSwitchTime) / 3600
|
123
|
+
if (_diffSinceSwitch > @maxHoursWithoutSwitch)
|
124
|
+
_switchReason = " more than " + @maxHoursWithoutSwitch.to_s + " hours since last switch"
|
125
|
+
_switchSite = true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
else
|
129
|
+
_switchReason = " consecutive error count has reach threshold of " + @multiSiteThreshold.to_s
|
130
|
+
_switchSite = true
|
131
|
+
end
|
132
|
+
|
133
|
+
if (_switchSite)
|
134
|
+
@currentMultiSiteUrlIndex += 1
|
135
|
+
if (@currentMultiSiteUrlIndex >= @multiSiteUrls.length)
|
136
|
+
@currentMultiSiteUrlIndex = 0
|
137
|
+
end
|
138
|
+
|
139
|
+
_url = @multiSiteUrls.at(@currentMultiSiteUrlIndex)
|
140
|
+
@errorCount = 0
|
141
|
+
|
142
|
+
if (@printDebug)
|
143
|
+
#print debug here
|
144
|
+
end
|
145
|
+
else
|
146
|
+
_url = _currentUrl
|
147
|
+
end
|
148
|
+
|
149
|
+
if (@printDebug)
|
150
|
+
#print some debug
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
return RequestTarget.new(_url, @currentMultiSiteUrlIndex)
|
155
|
+
end
|
156
|
+
|
157
|
+
def reportResult(target, result, statusCode)
|
158
|
+
if (target.requestTime < @lastSiteSwitchTime || !@multiSite)
|
159
|
+
return
|
160
|
+
end
|
161
|
+
|
162
|
+
case(result)
|
163
|
+
when @REQUEST_RESULT_RESPONSE_RECEIVED
|
164
|
+
if (statusCode == 200)
|
165
|
+
@errorCount = 0
|
166
|
+
elsif (statusCode >= 400)
|
167
|
+
@errorCount += 1
|
168
|
+
end
|
169
|
+
when @REQUEST_RESULT_CONNECTION_FAILED
|
170
|
+
@errorCount += 1
|
171
|
+
when @REQUEST_RESULT_RESPONSE_TIMEOUT
|
172
|
+
@errorCount += 1
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
def to_boolean(str)
|
178
|
+
if str.instance_of? String
|
179
|
+
str == 'true'
|
180
|
+
else
|
181
|
+
return str
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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
|
+
#
|
27
|
+
# Used for all transmission to Cnp over HTTP or HTTPS
|
28
|
+
# works with or without an HTTP proxy
|
29
|
+
#
|
30
|
+
# URL and proxy server settings are derived from the configuration file
|
31
|
+
#
|
32
|
+
|
33
|
+
module CnpOnline
|
34
|
+
class Communications
|
35
|
+
##For http or https post with or without a proxy
|
36
|
+
def Communications.http_post(post_data,config_hash)
|
37
|
+
|
38
|
+
proxy_addr = config_hash['proxy_addr']
|
39
|
+
proxy_port = config_hash['proxy_port']
|
40
|
+
_commManager = CommManager.instance(Configuration.new.config)
|
41
|
+
_requestTarget = _commManager.findUrl
|
42
|
+
|
43
|
+
#cnp_url = config_hash['url']
|
44
|
+
|
45
|
+
# setup https or http post
|
46
|
+
url = URI.parse(_requestTarget.targetUrl)
|
47
|
+
|
48
|
+
response_xml = nil
|
49
|
+
https = Net::HTTP.new(url.host, url.port, proxy_addr, proxy_port)
|
50
|
+
if(url.scheme == 'https')
|
51
|
+
https.use_ssl = url.scheme=='https'
|
52
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
53
|
+
https.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
|
54
|
+
end
|
55
|
+
https.start { |http|
|
56
|
+
response = http.request_post(url.path, post_data.to_s, {'Content-Type'=>'text/xml; charset=UTF-8','Connection'=>'close'})
|
57
|
+
response_xml = response
|
58
|
+
CommManager.instance(Configuration.new.config).reportResult(_requestTarget, _commManager.REQUEST_RESULT_RESPONSE_RECEIVED, response.code)
|
59
|
+
}
|
60
|
+
|
61
|
+
# validate response, only an HTTP 200 will work, redirects are not followed
|
62
|
+
case response_xml
|
63
|
+
when Net::HTTPOK
|
64
|
+
return response_xml.body
|
65
|
+
else
|
66
|
+
raise("Error with http http_post_request, code:" + response_xml.header.code)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
=begin
|
73
|
+
NOTES ON HTTP TIMEOUT
|
74
|
+
|
75
|
+
Vantiv eCommerce optimizes our systems to ensure the return of responses as quickly as possible, some portions of the process are beyond our control.
|
76
|
+
The round-trip time of an Authorization can be broken down into three parts, as follows:
|
77
|
+
1. Transmission time (across the internet) to Vantiv eCommerce and back to the merchant
|
78
|
+
2. Processing time by the authorization provider
|
79
|
+
3. Processing time by Cnp
|
80
|
+
Under normal operating circumstances, the transmission time to and from Cnp does not exceed 0.6 seconds
|
81
|
+
and processing overhead by Cnp occurs in 0.1 seconds.
|
82
|
+
Typically, the processing time by the card association or authorization provider can take between 0.5 and 3 seconds,
|
83
|
+
but some percentage of transactions may take significantly longer.
|
84
|
+
|
85
|
+
Because the total processing time can vary due to a number of factors, Vantiv eCommerce recommends using a minimum timeout setting of
|
86
|
+
60 seconds to accomodate Sale transactions and 30 seconds if you are not utilizing Sale tranactions.
|
87
|
+
|
88
|
+
These settings should ensure that you do not frequently disconnect prior to receiving a valid authorization causing dropped orders
|
89
|
+
and/or re-auths and duplicate auths.
|
90
|
+
=end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2017 Vantiv eCommerce
|
2
|
+
#
|
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
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
require 'yaml'
|
25
|
+
require_relative 'EnvironmentVariables'
|
26
|
+
|
27
|
+
#
|
28
|
+
# Loads the configuration from a file
|
29
|
+
#
|
30
|
+
module CnpOnline
|
31
|
+
class Configuration
|
32
|
+
class << self
|
33
|
+
# External logger, if specified
|
34
|
+
attr_accessor :logger
|
35
|
+
end
|
36
|
+
|
37
|
+
def config
|
38
|
+
if !ENV['CNP_CONFIG_DIR'].nil?
|
39
|
+
config_file = ENV['CNP_CONFIG_DIR'] + '/.cnp_SDK_config.yml'
|
40
|
+
else
|
41
|
+
config_file = ENV['HOME'] + '/.cnp_SDK_config.yml'
|
42
|
+
end
|
43
|
+
|
44
|
+
datas = {}
|
45
|
+
# if Env variable exist, then just override the data from config file
|
46
|
+
if File.exist?(config_file)
|
47
|
+
datas = YAML.load_file(config_file)
|
48
|
+
end
|
49
|
+
|
50
|
+
environments = EnvironmentVariables.new
|
51
|
+
environments.instance_variables.each do |var|
|
52
|
+
if datas[var.to_s.delete('@')].nil?
|
53
|
+
datas[var.to_s.delete('@')] = environments.instance_variable_get(var)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
datas.each { |key, _value| setENV(key, datas) }
|
57
|
+
return datas
|
58
|
+
rescue
|
59
|
+
return {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def setENV(key, datas)
|
63
|
+
val = ENV['cnp_' + key]
|
64
|
+
if !val.nil?
|
65
|
+
if val == 'true'
|
66
|
+
datas[key] = true
|
67
|
+
elsif val == 'false'
|
68
|
+
datas[key] = false
|
69
|
+
else
|
70
|
+
datas[key] = val
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CnpOnline
|
2
|
+
class EnvironmentVariables
|
3
|
+
def initialize
|
4
|
+
# load configuration data
|
5
|
+
@user = ''
|
6
|
+
@password = ''
|
7
|
+
@currency_merchant_map = ''
|
8
|
+
@default_report_group = 'Default Report Group'
|
9
|
+
@url = ''
|
10
|
+
@proxy_addr = nil
|
11
|
+
@proxy_port = nil
|
12
|
+
@sftp_username = ''
|
13
|
+
@sftp_password = ''
|
14
|
+
@sftp_url = ''
|
15
|
+
@fast_url = ''
|
16
|
+
@fast_port = ''
|
17
|
+
@printxml = false
|
18
|
+
@timeout = 65
|
19
|
+
@deleteBatchFiles = false
|
20
|
+
@useEncryption = false
|
21
|
+
@vantivPublicKeyID = ''
|
22
|
+
@passphrase = ''
|
23
|
+
@multiSiteUrl1 = ''
|
24
|
+
@multiSiteUrl2 = ''
|
25
|
+
@multiSite = false
|
26
|
+
@printMultiSiteDebug = false
|
27
|
+
@multiSiteErrorThreshold = 5
|
28
|
+
@maxsHoursWithoutSwitch = 48
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|