@@ -20,6 +20,8 @@ module CyberSource
2020 class ApiClient
2121 # The Configuration object holding settings to be used in the API client.
2222 attr_accessor :config
23+
24+ attr_accessor :merchantconfig
2325
2426 # Defines the headers to be used in HTTP requests of all API calls by default.
2527 #
@@ -115,13 +117,13 @@ def build_request(http_method, path, opts = {})
115117 end
116118
117119 headers = opts [ :header_params ]
118- if $merchantconfig_obj . authenticationType . upcase != Constants ::AUTH_TYPE_MUTUAL_AUTH
120+ if @merchantconfig . authenticationType . upcase != Constants ::AUTH_TYPE_MUTUAL_AUTH
119121 headers = CallAuthenticationHeader ( http_method , path , body_params , headers , query_params )
120122 end
121123 http_method = http_method . to_sym . downcase
122124 header_params = headers . merge ( @default_headers )
123- if $merchantconfig_obj . defaultCustomHeaders
124- header_params = header_params . merge ( $merchantconfig_obj . defaultCustomHeaders )
125+ if @merchantconfig . defaultCustomHeaders
126+ header_params = header_params . merge ( @merchantconfig . defaultCustomHeaders )
125127 end
126128 form_params = opts [ :form_params ] || { }
127129
@@ -130,9 +132,9 @@ def build_request(http_method, path, opts = {})
130132 _verify_ssl_host = @config . verify_ssl_host ? 2 : 0
131133
132134 # client cert
133- if $merchantconfig_obj . enableClientCert
134- @config . cert_file = File . join ( $merchantconfig_obj . clientCertDirectory , $merchantconfig_obj . sslClientCert )
135- @config . key_file = File . join ( $merchantconfig_obj . clientCertDirectory , $merchantconfig_obj . privateKey )
135+ if @merchantconfig . enableClientCert
136+ @config . cert_file = File . join ( @merchantconfig . clientCertDirectory , @merchantconfig . sslClientCert )
137+ @config . key_file = File . join ( @merchantconfig . clientCertDirectory , @merchantconfig . privateKey )
136138 end
137139
138140 req_opts = {
@@ -144,7 +146,7 @@ def build_request(http_method, path, opts = {})
144146 :ssl_verifypeer => @config . verify_ssl ,
145147 :ssl_verifyhost => _verify_ssl_host ,
146148 :sslcert => @config . cert_file ,
147- :sslkeypasswd => $merchantconfig_obj . sslKeyPassword || "" ,
149+ :sslkeypasswd => @merchantconfig . sslKeyPassword || "" ,
148150 :sslkey => @config . key_file ,
149151 :verbose => @config . debugging
150152 }
@@ -172,13 +174,13 @@ def build_request(http_method, path, opts = {})
172174 # set merchantConfig
173175 def set_configuration ( config )
174176 require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
175- $merchantconfig_obj = Merchantconfig . new ( config )
176- @config . host = $merchantconfig_obj . requestHost
177- if $merchantconfig_obj . intermediateHost
178- @config . host = $merchantconfig_obj . intermediateHost
179- if $merchantconfig_obj . intermediateHost . start_with? ( Constants ::HTTPS_URI_PREFIX )
177+ @merchantconfig = Merchantconfig . new ( config )
178+ @config . host = @merchantconfig . requestHost
179+ if @merchantconfig . intermediateHost
180+ @config . host = @merchantconfig . intermediateHost
181+ if @merchantconfig . intermediateHost . start_with? ( Constants ::HTTPS_URI_PREFIX )
180182 @config . scheme = 'https'
181- elsif $merchantconfig_obj . intermediateHost . start_with? ( Constants ::HTTP_URI_PREFIX )
183+ elsif @merchantconfig . intermediateHost . start_with? ( Constants ::HTTP_URI_PREFIX )
182184 @config . scheme = 'http'
183185 end
184186 end
@@ -190,44 +192,44 @@ def CallAuthenticationHeader(http_method, path, body_params, header_params, quer
190192 request_target = get_query_param ( path , query_params )
191193 # Request Type. [Non-Editable]
192194 request_type = http_method . to_s
193- log_obj = Log . new $merchantconfig_obj . log_config , "ApiClient"
195+ log_obj = Log . new @merchantconfig . log_config , "ApiClient"
194196 # Set Request Type into the merchant config object.
195- $merchantconfig_obj . requestType = request_type
197+ @merchantconfig . requestType = request_type
196198 # Set Request Target into the merchant config object.
197- $merchantconfig_obj . requestTarget = request_target
199+ @merchantconfig . requestTarget = request_target
198200 # Construct the URL.
199- url = Constants ::HTTPS_URI_PREFIX + $merchantconfig_obj . requestHost + $merchantconfig_obj . requestTarget
201+ url = Constants ::HTTPS_URI_PREFIX + @merchantconfig . requestHost + @merchantconfig . requestTarget
200202 # set Request Json to Merchant config object
201- $merchantconfig_obj . requestJsonData = body_params
203+ @merchantconfig . requestJsonData = body_params
202204 # Set URL into the merchant config object.
203- $merchantconfig_obj . requestUrl = url
205+ @merchantconfig . requestUrl = url
204206 # Calling APISDK, Apisdk.controller.
205207 gmtDateTime = DateTime . now . httpdate
206- token = Authorization . new . getToken ( $merchantconfig_obj , gmtDateTime )
208+ token = Authorization . new . getToken ( @merchantconfig , gmtDateTime )
207209
208210 # Adding client ID header
209211 header_params [ 'v-c-client-id' ] = @client_id
210212
211213 # Adding solution ID header
212- # header_params['v-c-solution-id'] = $merchantconfig_obj .solutionId if !$merchantconfig_obj .solutionId.nil? && !$merchantconfig_obj .solutionId.empty?
214+ # header_params['v-c-solution-id'] = @merchantconfig .solutionId if !@merchantconfig .solutionId.nil? && !@merchantconfig .solutionId.empty?
213215 # HTTP header 'Accept' (if needed)
214- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_HTTP
216+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_HTTP
215217 # Appending headers for Get Connection
216- header_params [ 'v-c-merchant-id' ] = $merchantconfig_obj . merchantId
218+ header_params [ 'v-c-merchant-id' ] = @merchantconfig . merchantId
217219 header_params [ 'Date' ] = gmtDateTime
218- header_params [ 'Host' ] = $merchantconfig_obj . requestHost
220+ header_params [ 'Host' ] = @merchantconfig . requestHost
219221 header_params [ 'Signature' ] = token
220222 if request_type == Constants ::POST_REQUEST_TYPE || request_type == Constants ::PUT_REQUEST_TYPE || request_type == Constants ::PATCH_REQUEST_TYPE
221223 digest = DigestGeneration . new . generateDigest ( body_params )
222224 digest_payload = Constants ::SHA256 + digest
223225 header_params [ 'Digest' ] = digest_payload
224226 end
225227 end
226- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_JWT
228+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_JWT
227229 token = "Bearer " + token
228230 header_params [ 'Authorization' ] = token
229231 end
230- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_OAUTH
232+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_OAUTH
231233 token = "Bearer " + token
232234 header_params [ 'Authorization' ] = token
233235 end
0 commit comments