1515using RestSharp ;
1616using CyberSource . Client ;
1717using CyberSource . Model ;
18+ using NLog ;
19+ using AuthenticationSdk . util ;
1820
1921namespace CyberSource . Api
2022{
@@ -76,22 +78,28 @@ public interface ICreditApi : IApiAccessor
7678 /// </summary>
7779 public partial class CreditApi : ICreditApi
7880 {
79- private CyberSource . Client . ExceptionFactory _exceptionFactory = ( name , response ) => null ;
81+ private static Logger logger ;
82+ private ExceptionFactory _exceptionFactory = ( name , response ) => null ;
8083
8184 /// <summary>
8285 /// Initializes a new instance of the <see cref="CreditApi"/> class.
8386 /// </summary>
8487 /// <returns></returns>
85- public CreditApi ( String basePath )
88+ public CreditApi ( string basePath )
8689 {
87- this . Configuration = new Configuration ( new ApiClient ( basePath ) ) ;
90+ Configuration = new Configuration ( new ApiClient ( basePath ) ) ;
8891
89- ExceptionFactory = CyberSource . Client . Configuration . DefaultExceptionFactory ;
92+ ExceptionFactory = Configuration . DefaultExceptionFactory ;
9093
9194 // ensure API client has configuration ready
9295 if ( Configuration . ApiClient . Configuration == null )
9396 {
94- this . Configuration . ApiClient . Configuration = this . Configuration ;
97+ Configuration . ApiClient . Configuration = Configuration ;
98+ }
99+
100+ if ( logger == null )
101+ {
102+ logger = LogManager . GetCurrentClassLogger ( ) ;
95103 }
96104 }
97105
@@ -104,30 +112,35 @@ public CreditApi(String basePath)
104112 public CreditApi ( Configuration configuration = null )
105113 {
106114 if ( configuration == null ) // use the default one in Configuration
107- this . Configuration = Configuration . Default ;
115+ Configuration = Configuration . Default ;
108116 else
109- this . Configuration = configuration ;
117+ Configuration = configuration ;
118+
119+ ExceptionFactory = Configuration . DefaultExceptionFactory ;
110120
111- ExceptionFactory = CyberSource . Client . Configuration . DefaultExceptionFactory ;
121+ Configuration . ApiClient . Configuration = Configuration ;
112122
113- this . Configuration . ApiClient . Configuration = this . Configuration ;
123+ if ( logger == null )
124+ {
125+ logger = LogManager . GetCurrentClassLogger ( ) ;
126+ }
114127 }
115128
116129 /// <summary>
117130 /// Gets the base path of the API client.
118131 /// </summary>
119132 /// <value>The base path</value>
120- public String GetBasePath ( )
133+ public string GetBasePath ( )
121134 {
122- return this . Configuration . ApiClient . RestClient . BaseUrl . ToString ( ) ;
135+ return Configuration . ApiClient . RestClient . BaseUrl . ToString ( ) ;
123136 }
124137
125138 /// <summary>
126139 /// Sets the base path of the API client.
127140 /// </summary>
128141 /// <value>The base path</value>
129142 [ Obsolete ( "SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\" http://new-path\" )' instead." ) ]
130- public void SetBasePath ( String basePath )
143+ public void SetBasePath ( string basePath )
131144 {
132145 // do nothing
133146 }
@@ -136,17 +149,18 @@ public void SetBasePath(String basePath)
136149 /// Gets or sets the configuration object
137150 /// </summary>
138151 /// <value>An instance of the Configuration</value>
139- public Configuration Configuration { get ; set ; }
152+ public Configuration Configuration { get ; set ; }
140153
141154 /// <summary>
142155 /// Provides a factory method hook for the creation of exceptions.
143156 /// </summary>
144- public CyberSource . Client . ExceptionFactory ExceptionFactory
157+ public ExceptionFactory ExceptionFactory
145158 {
146159 get
147160 {
148161 if ( _exceptionFactory != null && _exceptionFactory . GetInvocationList ( ) . Length > 1 )
149162 {
163+ logger . Error ( "InvalidOperationException : Multicast delegate for ExceptionFactory is unsupported." ) ;
150164 throw new InvalidOperationException ( "Multicast delegate for ExceptionFactory is unsupported." ) ;
151165 }
152166 return _exceptionFactory ;
@@ -159,9 +173,9 @@ public CyberSource.Client.ExceptionFactory ExceptionFactory
159173 /// </summary>
160174 /// <returns>Dictionary of HTTP header</returns>
161175 [ Obsolete ( "DefaultHeader is deprecated, please use Configuration.DefaultHeader instead." ) ]
162- public Dictionary < String , String > DefaultHeader ( )
176+ public Dictionary < string , string > DefaultHeader ( )
163177 {
164- return this . Configuration . DefaultHeader ;
178+ return Configuration . DefaultHeader ;
165179 }
166180
167181 /// <summary>
@@ -173,7 +187,7 @@ public Dictionary<String, String> DefaultHeader()
173187 [ Obsolete ( "AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead." ) ]
174188 public void AddDefaultHeader ( string key , string value )
175189 {
176- this . Configuration . AddDefaultHeader ( key , value ) ;
190+ Configuration . AddDefaultHeader ( key , value ) ;
177191 }
178192
179193 /// <summary>
@@ -184,8 +198,10 @@ public void AddDefaultHeader(string key, string value)
184198 /// <returns>PtsV2CreditsPost201Response</returns>
185199 public PtsV2CreditsPost201Response CreateCredit ( CreateCreditRequest createCreditRequest )
186200 {
187- ApiResponse < PtsV2CreditsPost201Response > localVarResponse = CreateCreditWithHttpInfo ( createCreditRequest ) ;
188- return localVarResponse . Data ;
201+ logger . Debug ( "CALLING API \" CreateCredit\" STARTED" ) ;
202+ ApiResponse < PtsV2CreditsPost201Response > localVarResponse = CreateCreditWithHttpInfo ( createCreditRequest ) ;
203+ logger . Debug ( "CALLING API \" CreateCredit\" ENDED" ) ;
204+ return localVarResponse . Data ;
189205 }
190206
191207 /// <summary>
@@ -198,29 +214,34 @@ public ApiResponse< PtsV2CreditsPost201Response > CreateCreditWithHttpInfo (Crea
198214 {
199215 // verify the required parameter 'createCreditRequest' is set
200216 if ( createCreditRequest == null )
217+ {
218+ logger . Error ( "ApiException : Missing required parameter 'createCreditRequest' when calling CreditApi->CreateCredit" ) ;
201219 throw new ApiException ( 400 , "Missing required parameter 'createCreditRequest' when calling CreditApi->CreateCredit" ) ;
220+ }
202221
203222 var localVarPath = $ "/pts/v2/credits";
204- var localVarPathParams = new Dictionary < String , String > ( ) ;
205- var localVarQueryParams = new Dictionary < String , String > ( ) ;
206- var localVarHeaderParams = new Dictionary < String , String > ( Configuration . DefaultHeader ) ;
207- var localVarFormParams = new Dictionary < String , String > ( ) ;
208- var localVarFileParams = new Dictionary < String , FileParameter > ( ) ;
209- Object localVarPostBody = null ;
223+ var localVarPathParams = new Dictionary < string , string > ( ) ;
224+ var localVarQueryParams = new Dictionary < string , string > ( ) ;
225+ var localVarHeaderParams = new Dictionary < string , string > ( Configuration . DefaultHeader ) ;
226+ var localVarFormParams = new Dictionary < string , string > ( ) ;
227+ var localVarFileParams = new Dictionary < string , FileParameter > ( ) ;
228+ object localVarPostBody = null ;
210229
211230 // to determine the Content-Type header
212- String [ ] localVarHttpContentTypes = new String [ ] {
231+ string [ ] localVarHttpContentTypes = new string [ ] {
213232 "application/json;charset=utf-8"
214233 } ;
215- String localVarHttpContentType = Configuration . ApiClient . SelectHeaderContentType ( localVarHttpContentTypes ) ;
234+ string localVarHttpContentType = Configuration . ApiClient . SelectHeaderContentType ( localVarHttpContentTypes ) ;
216235
217236 // to determine the Accept header
218- String [ ] localVarHttpHeaderAccepts = new String [ ] {
237+ string [ ] localVarHttpHeaderAccepts = new string [ ] {
219238 "application/hal+json;charset=utf-8"
220239 } ;
221- String localVarHttpHeaderAccept = Configuration . ApiClient . SelectHeaderAccept ( localVarHttpHeaderAccepts ) ;
240+ string localVarHttpHeaderAccept = Configuration . ApiClient . SelectHeaderAccept ( localVarHttpHeaderAccepts ) ;
222241 if ( localVarHttpHeaderAccept != null )
242+ {
223243 localVarHeaderParams . Add ( "Accept" , localVarHttpHeaderAccept ) ;
244+ }
224245
225246 if ( createCreditRequest != null && createCreditRequest . GetType ( ) != typeof ( byte [ ] ) )
226247 {
@@ -231,6 +252,15 @@ public ApiResponse< PtsV2CreditsPost201Response > CreateCreditWithHttpInfo (Crea
231252 localVarPostBody = createCreditRequest ; // byte array
232253 }
233254
255+ if ( LogUtility . IsMaskingEnabled ( logger ) )
256+ {
257+ logger . Debug ( $ "HTTP Request Body :\n { LogUtility . MaskSensitiveData ( localVarPostBody . ToString ( ) ) } ") ;
258+ }
259+ else
260+ {
261+ logger . Debug ( $ "HTTP Request Body :\n { localVarPostBody } ") ;
262+ }
263+
234264
235265 // make the HTTP request
236266 IRestResponse localVarResponse = ( IRestResponse ) Configuration . ApiClient . CallApi ( localVarPath ,
@@ -242,7 +272,11 @@ public ApiResponse< PtsV2CreditsPost201Response > CreateCreditWithHttpInfo (Crea
242272 if ( ExceptionFactory != null )
243273 {
244274 Exception exception = ExceptionFactory ( "CreateCredit" , localVarResponse ) ;
245- if ( exception != null ) throw exception ;
275+ if ( exception != null )
276+ {
277+ logger . Error ( $ "Exception : { exception . Message } ") ;
278+ throw exception ;
279+ }
246280 }
247281
248282 return new ApiResponse < PtsV2CreditsPost201Response > ( localVarStatusCode ,
@@ -258,8 +292,10 @@ public ApiResponse< PtsV2CreditsPost201Response > CreateCreditWithHttpInfo (Crea
258292 /// <returns>Task of PtsV2CreditsPost201Response</returns>
259293 public async System . Threading . Tasks . Task < PtsV2CreditsPost201Response > CreateCreditAsync ( CreateCreditRequest createCreditRequest )
260294 {
261- ApiResponse < PtsV2CreditsPost201Response > localVarResponse = await CreateCreditAsyncWithHttpInfo ( createCreditRequest ) ;
262- return localVarResponse . Data ;
295+ logger . Debug ( "CALLING API \" CreateCreditAsync\" STARTED" ) ;
296+ ApiResponse < PtsV2CreditsPost201Response > localVarResponse = await CreateCreditAsyncWithHttpInfo ( createCreditRequest ) ;
297+ logger . Debug ( "CALLING API \" CreateCreditAsync\" STARTED" ) ;
298+ return localVarResponse . Data ;
263299
264300 }
265301
@@ -273,29 +309,34 @@ public async System.Threading.Tasks.Task<ApiResponse<PtsV2CreditsPost201Response
273309 {
274310 // verify the required parameter 'createCreditRequest' is set
275311 if ( createCreditRequest == null )
312+ {
313+ logger . Error ( "ApiException : Missing required parameter 'createCreditRequest' when calling CreditApi->CreateCredit" ) ;
276314 throw new ApiException ( 400 , "Missing required parameter 'createCreditRequest' when calling CreditApi->CreateCredit" ) ;
315+ }
277316
278317 var localVarPath = $ "/pts/v2/credits";
279- var localVarPathParams = new Dictionary < String , String > ( ) ;
280- var localVarQueryParams = new Dictionary < String , String > ( ) ;
281- var localVarHeaderParams = new Dictionary < String , String > ( Configuration . DefaultHeader ) ;
282- var localVarFormParams = new Dictionary < String , String > ( ) ;
283- var localVarFileParams = new Dictionary < String , FileParameter > ( ) ;
284- Object localVarPostBody = null ;
318+ var localVarPathParams = new Dictionary < string , string > ( ) ;
319+ var localVarQueryParams = new Dictionary < string , string > ( ) ;
320+ var localVarHeaderParams = new Dictionary < string , string > ( Configuration . DefaultHeader ) ;
321+ var localVarFormParams = new Dictionary < string , string > ( ) ;
322+ var localVarFileParams = new Dictionary < string , FileParameter > ( ) ;
323+ object localVarPostBody = null ;
285324
286325 // to determine the Content-Type header
287- String [ ] localVarHttpContentTypes = new String [ ] {
326+ string [ ] localVarHttpContentTypes = new string [ ] {
288327 "application/json;charset=utf-8"
289328 } ;
290- String localVarHttpContentType = Configuration . ApiClient . SelectHeaderContentType ( localVarHttpContentTypes ) ;
329+ string localVarHttpContentType = Configuration . ApiClient . SelectHeaderContentType ( localVarHttpContentTypes ) ;
291330
292331 // to determine the Accept header
293- String [ ] localVarHttpHeaderAccepts = new String [ ] {
332+ string [ ] localVarHttpHeaderAccepts = new string [ ] {
294333 "application/hal+json;charset=utf-8"
295334 } ;
296- String localVarHttpHeaderAccept = Configuration . ApiClient . SelectHeaderAccept ( localVarHttpHeaderAccepts ) ;
335+ string localVarHttpHeaderAccept = Configuration . ApiClient . SelectHeaderAccept ( localVarHttpHeaderAccepts ) ;
297336 if ( localVarHttpHeaderAccept != null )
337+ {
298338 localVarHeaderParams . Add ( "Accept" , localVarHttpHeaderAccept ) ;
339+ }
299340
300341 if ( createCreditRequest != null && createCreditRequest . GetType ( ) != typeof ( byte [ ] ) )
301342 {
@@ -306,24 +347,36 @@ public async System.Threading.Tasks.Task<ApiResponse<PtsV2CreditsPost201Response
306347 localVarPostBody = createCreditRequest ; // byte array
307348 }
308349
350+ if ( LogUtility . IsMaskingEnabled ( logger ) )
351+ {
352+ logger . Debug ( $ "HTTP Request Body :\n { LogUtility . MaskSensitiveData ( localVarPostBody . ToString ( ) ) } ") ;
353+ }
354+ else
355+ {
356+ logger . Debug ( $ "HTTP Request Body :\n { localVarPostBody } ") ;
357+ }
358+
309359
310360 // make the HTTP request
311- IRestResponse localVarResponse = ( IRestResponse ) await Configuration . ApiClient . CallApiAsync ( localVarPath ,
361+ IRestResponse localVarResponse = ( IRestResponse ) await Configuration . ApiClient . CallApiAsync ( localVarPath ,
312362 Method . POST , localVarQueryParams , localVarPostBody , localVarHeaderParams , localVarFormParams , localVarFileParams ,
313363 localVarPathParams , localVarHttpContentType ) ;
314364
315- int localVarStatusCode = ( int ) localVarResponse . StatusCode ;
365+ int localVarStatusCode = ( int ) localVarResponse . StatusCode ;
316366
317367 if ( ExceptionFactory != null )
318368 {
319369 Exception exception = ExceptionFactory ( "CreateCredit" , localVarResponse ) ;
320- if ( exception != null ) throw exception ;
370+ if ( exception != null )
371+ {
372+ logger . Error ( $ "Exception : { exception . Message } ") ;
373+ throw exception ;
374+ }
321375 }
322376
323377 return new ApiResponse < PtsV2CreditsPost201Response > ( localVarStatusCode ,
324378 localVarResponse . Headers . ToDictionary ( x => x . Name , x => x . Value . ToString ( ) ) ,
325379 ( PtsV2CreditsPost201Response ) Configuration . ApiClient . Deserialize ( localVarResponse , typeof ( PtsV2CreditsPost201Response ) ) ) ; // Return statement
326380 }
327-
328381 }
329382}
0 commit comments