@@ -20,6 +20,8 @@ module CyberSource
20
20
class ApiClient
21
21
# The Configuration object holding settings to be used in the API client.
22
22
attr_accessor :config
23
+
24
+ attr_accessor :merchantconfig
23
25
24
26
# Defines the headers to be used in HTTP requests of all API calls by default.
25
27
#
@@ -115,13 +117,13 @@ def build_request(http_method, path, opts = {})
115
117
end
116
118
117
119
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
119
121
headers = CallAuthenticationHeader ( http_method , path , body_params , headers , query_params )
120
122
end
121
123
http_method = http_method . to_sym . downcase
122
124
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 )
125
127
end
126
128
form_params = opts [ :form_params ] || { }
127
129
@@ -130,9 +132,9 @@ def build_request(http_method, path, opts = {})
130
132
_verify_ssl_host = @config . verify_ssl_host ? 2 : 0
131
133
132
134
# 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 )
136
138
end
137
139
138
140
req_opts = {
@@ -144,7 +146,7 @@ def build_request(http_method, path, opts = {})
144
146
:ssl_verifypeer => @config . verify_ssl ,
145
147
:ssl_verifyhost => _verify_ssl_host ,
146
148
:sslcert => @config . cert_file ,
147
- :sslkeypasswd => $merchantconfig_obj . sslKeyPassword || "" ,
149
+ :sslkeypasswd => @merchantconfig . sslKeyPassword || "" ,
148
150
:sslkey => @config . key_file ,
149
151
:verbose => @config . debugging
150
152
}
@@ -172,13 +174,13 @@ def build_request(http_method, path, opts = {})
172
174
# set merchantConfig
173
175
def set_configuration ( config )
174
176
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 )
180
182
@config . scheme = 'https'
181
- elsif $merchantconfig_obj . intermediateHost . start_with? ( Constants ::HTTP_URI_PREFIX )
183
+ elsif @merchantconfig . intermediateHost . start_with? ( Constants ::HTTP_URI_PREFIX )
182
184
@config . scheme = 'http'
183
185
end
184
186
end
@@ -190,44 +192,44 @@ def CallAuthenticationHeader(http_method, path, body_params, header_params, quer
190
192
request_target = get_query_param ( path , query_params )
191
193
# Request Type. [Non-Editable]
192
194
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"
194
196
# Set Request Type into the merchant config object.
195
- $merchantconfig_obj . requestType = request_type
197
+ @merchantconfig . requestType = request_type
196
198
# Set Request Target into the merchant config object.
197
- $merchantconfig_obj . requestTarget = request_target
199
+ @merchantconfig . requestTarget = request_target
198
200
# 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
200
202
# set Request Json to Merchant config object
201
- $merchantconfig_obj . requestJsonData = body_params
203
+ @merchantconfig . requestJsonData = body_params
202
204
# Set URL into the merchant config object.
203
- $merchantconfig_obj . requestUrl = url
205
+ @merchantconfig . requestUrl = url
204
206
# Calling APISDK, Apisdk.controller.
205
207
gmtDateTime = DateTime . now . httpdate
206
- token = Authorization . new . getToken ( $merchantconfig_obj , gmtDateTime )
208
+ token = Authorization . new . getToken ( @merchantconfig , gmtDateTime )
207
209
208
210
# Adding client ID header
209
211
header_params [ 'v-c-client-id' ] = @client_id
210
212
211
213
# 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?
213
215
# HTTP header 'Accept' (if needed)
214
- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_HTTP
216
+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_HTTP
215
217
# Appending headers for Get Connection
216
- header_params [ 'v-c-merchant-id' ] = $merchantconfig_obj . merchantId
218
+ header_params [ 'v-c-merchant-id' ] = @merchantconfig . merchantId
217
219
header_params [ 'Date' ] = gmtDateTime
218
- header_params [ 'Host' ] = $merchantconfig_obj . requestHost
220
+ header_params [ 'Host' ] = @merchantconfig . requestHost
219
221
header_params [ 'Signature' ] = token
220
222
if request_type == Constants ::POST_REQUEST_TYPE || request_type == Constants ::PUT_REQUEST_TYPE || request_type == Constants ::PATCH_REQUEST_TYPE
221
223
digest = DigestGeneration . new . generateDigest ( body_params )
222
224
digest_payload = Constants ::SHA256 + digest
223
225
header_params [ 'Digest' ] = digest_payload
224
226
end
225
227
end
226
- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_JWT
228
+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_JWT
227
229
token = "Bearer " + token
228
230
header_params [ 'Authorization' ] = token
229
231
end
230
- if $merchantconfig_obj . authenticationType . upcase == Constants ::AUTH_TYPE_OAUTH
232
+ if @merchantconfig . authenticationType . upcase == Constants ::AUTH_TYPE_OAUTH
231
233
token = "Bearer " + token
232
234
header_params [ 'Authorization' ] = token
233
235
end
0 commit comments