From 1e1790eef418aff7c3c9d626a160b1c3d16fceb6 Mon Sep 17 00:00:00 2001 From: akshunyaInfy Date: Fri, 11 Jan 2019 10:44:37 +0530 Subject: [PATCH 01/11] second draft - include req resp statements --- cybersource-rest-samples-csharp.sln | 6 ++ src/SampleCode.csproj | 12 ++-- src/Samples/Flex/CoreServices/GenerateKey.cs | 53 ++++++++++++++++-- src/Samples/Flex/CoreServices/TokenizeCard.cs | 56 +++++++++++++++++-- 4 files changed, 111 insertions(+), 16 deletions(-) diff --git a/cybersource-rest-samples-csharp.sln b/cybersource-rest-samples-csharp.sln index 962d440..20cd80f 100644 --- a/cybersource-rest-samples-csharp.sln +++ b/cybersource-rest-samples-csharp.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCode", "src\SampleCode.csproj", "{4CF837FF-237D-4B5B-B922-71CCC654D718}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cybersource-rest-client-dotnet", "..\cybersource-rest-client-dotnet\cybersource-rest-client-dotnet.csproj", "{B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {4CF837FF-237D-4B5B-B922-71CCC654D718}.Debug|Any CPU.Build.0 = Debug|Any CPU {4CF837FF-237D-4B5B-B922-71CCC654D718}.Release|Any CPU.ActiveCfg = Release|Any CPU {4CF837FF-237D-4B5B-B922-71CCC654D718}.Release|Any CPU.Build.0 = Release|Any CPU + {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/SampleCode.csproj b/src/SampleCode.csproj index e7afb68..4d398a8 100644 --- a/src/SampleCode.csproj +++ b/src/SampleCode.csproj @@ -39,10 +39,6 @@ ..\packages\CyberSource.Authentication.0.0.0.3\lib\AuthenticationSdk.dll True - - ..\packages\CyberSource.Rest.Client.0.0.0.4\lib\cybersource-rest-client-dotnet.dll - True - ..\packages\CyberSource.Flex.Server.0.2.1\lib\FlexServerSDK.dll True @@ -146,6 +142,12 @@ + + + {b0b5bddb-e666-47ef-95b9-2bf8e88a51e4} + cybersource-rest-client-dotnet + + - + \ No newline at end of file diff --git a/src/Samples/Flex/CoreServices/GenerateKey.cs b/src/Samples/Flex/CoreServices/GenerateKey.cs index fbf19af..d1cc89a 100644 --- a/src/Samples/Flex/CoreServices/GenerateKey.cs +++ b/src/Samples/Flex/CoreServices/GenerateKey.cs @@ -8,23 +8,66 @@ public class GenerateKey { public static FlexV1KeysPost200Response Run() { + Console.WriteLine($"\n[BEGIN] EXECUTION OF SAMPLE CODE: {nameof(GenerateKey)}"); + + CyberSource.Client.Configuration clientConfig = null; + FlexV1KeysPost200Response result = null; + var requestObj = new GeneratePublicKeyRequest("None"); try { var configDictionary = new Configuration().GetConfiguration(); - var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); + clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); var apiInstance = new KeyGenerationApi(clientConfig); - var result = apiInstance.GeneratePublicKey(requestObj); - Console.WriteLine(result); + result = apiInstance.GeneratePublicKey(requestObj); return result; } catch (Exception e) { - Console.WriteLine("Exception on calling the API: " + e.Message); + Console.WriteLine($"Exception on calling the Sample Code({nameof(GenerateKey)}):{e.Message}"); return null; } + finally + { + if (clientConfig != null) + { + + Console.WriteLine("\nAPI REQUEST HEADERS:"); + + foreach (var requestHeader in clientConfig.ApiClient.ApiRequest.Headers) + { + Console.WriteLine(requestHeader); + } + + Console.WriteLine("\nAPI REQUEST BODY:"); + Console.WriteLine(clientConfig.ApiClient.ApiRequest.Data); + + Console.WriteLine($"\nAPI RESPONSE CODE: {clientConfig.ApiClient.ApiResponse.StatusCode}"); + + Console.WriteLine("\nAPI RESPONSE HEADERS:"); + + foreach (var responseHeader in clientConfig.ApiClient.ApiResponse.HeadersList) + { + Console.WriteLine(responseHeader); + } + + Console.WriteLine("\nAPI RESPONSE BODY:"); + Console.WriteLine(clientConfig.ApiClient.ApiResponse.Data); + + if (result != null) + { + Console.WriteLine("\nAPI RESPONSE DATA OBJECT:"); + Console.WriteLine(result); + } + + Console.WriteLine($"\n[END] EXECUTION OF SAMPLE CODE: {nameof(GenerateKey)}"); + } + + clientConfig = null; + result = null; + } } } -} +} \ No newline at end of file diff --git a/src/Samples/Flex/CoreServices/TokenizeCard.cs b/src/Samples/Flex/CoreServices/TokenizeCard.cs index 71f4d72..cb01273 100644 --- a/src/Samples/Flex/CoreServices/TokenizeCard.cs +++ b/src/Samples/Flex/CoreServices/TokenizeCard.cs @@ -14,6 +14,12 @@ public class TokenizeCard { public static void Run() { + Console.WriteLine($"\n[BEGIN] EXECUTION OF SAMPLE CODE: {nameof(TokenizeCard)}"); + + CyberSource.Client.Configuration clientConfig = null; + FlexV1TokensPost200Response result = null; + bool tokenVerificationResult = false; + var generateKeyResult = GenerateKey.Run(); var keyId = generateKeyResult.KeyId; var derFormat = generateKeyResult.Der.Format; @@ -35,11 +41,10 @@ public static void Run() try { var configDictionary = new Configuration().GetConfiguration(); - var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); + clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); var apiInstance = new FlexTokenApi(clientConfig); - var result = apiInstance.Tokenize(requestObj); - Console.WriteLine(result); + result = apiInstance.Tokenize(requestObj); var flexPublicKey = new FlexPublicKey(keyId, new FlexServerSDK.Model.DerPublicKey(derFormat, derAlgo, derPublicKey), null); var flexToken = new FlexToken() @@ -63,12 +68,51 @@ public static void Run() postParameters["token"] = flexToken.token; postParameters["timestamp"] = Convert.ToString(flexToken.timestamp); - var tokenVerificationResult = Verify(flexPublicKey, postParameters); - Console.WriteLine(tokenVerificationResult); + tokenVerificationResult = Verify(flexPublicKey, postParameters); } catch (Exception e) { - Console.WriteLine("Exception on calling the API: " + e.Message); + Console.WriteLine($"Exception on calling the Sample Code({nameof(TokenizeCard)}):{e.Message}"); + } + finally + { + if (clientConfig != null) + { + Console.WriteLine("\nAPI REQUEST HEADERS:"); + + foreach (var requestHeader in clientConfig.ApiClient.ApiRequest.Headers) + { + Console.WriteLine(requestHeader); + } + + Console.WriteLine("\nAPI REQUEST BODY:"); + Console.WriteLine(clientConfig.ApiClient.ApiRequest.Data); + + Console.WriteLine($"\nAPI RESPONSE CODE: {clientConfig.ApiClient.ApiResponse.StatusCode}"); + + Console.WriteLine("\nAPI RESPONSE HEADERS:"); + + foreach (var responseHeader in clientConfig.ApiClient.ApiResponse.HeadersList) + { + Console.WriteLine(responseHeader); + } + + Console.WriteLine("\nAPI RESPONSE BODY:"); + Console.WriteLine(clientConfig.ApiClient.ApiResponse.Data); + + if (result != null) + { + Console.WriteLine("\nAPI RESPONSE DATA OBJECT:"); + Console.WriteLine(result); + } + + Console.WriteLine($"\nToken Verification Result: {tokenVerificationResult}"); + + Console.WriteLine($"\n[END] EXECUTION OF SAMPLE CODE: {nameof(TokenizeCard)}"); + } + + clientConfig = null; + result = null; } } From 54503a20c474da9fe373cd00eefed7dbeabad60f Mon Sep 17 00:00:00 2001 From: akshunyaInfy Date: Thu, 17 Jan 2019 13:13:36 +0530 Subject: [PATCH 02/11] removing null setters in finally --- src/Samples/Flex/CoreServices/GenerateKey.cs | 3 --- src/Samples/Flex/CoreServices/TokenizeCard.cs | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/Samples/Flex/CoreServices/GenerateKey.cs b/src/Samples/Flex/CoreServices/GenerateKey.cs index d1cc89a..45f4247 100644 --- a/src/Samples/Flex/CoreServices/GenerateKey.cs +++ b/src/Samples/Flex/CoreServices/GenerateKey.cs @@ -64,9 +64,6 @@ public static FlexV1KeysPost200Response Run() Console.WriteLine($"\n[END] EXECUTION OF SAMPLE CODE: {nameof(GenerateKey)}"); } - - clientConfig = null; - result = null; } } } diff --git a/src/Samples/Flex/CoreServices/TokenizeCard.cs b/src/Samples/Flex/CoreServices/TokenizeCard.cs index cb01273..37794fc 100644 --- a/src/Samples/Flex/CoreServices/TokenizeCard.cs +++ b/src/Samples/Flex/CoreServices/TokenizeCard.cs @@ -110,9 +110,6 @@ public static void Run() Console.WriteLine($"\n[END] EXECUTION OF SAMPLE CODE: {nameof(TokenizeCard)}"); } - - clientConfig = null; - result = null; } } From 9bc7377470d2742721fea4d4508a272d53fd44b2 Mon Sep 17 00:00:00 2001 From: akshunyaInfy Date: Fri, 25 Jan 2019 18:50:22 +0530 Subject: [PATCH 03/11] remove project ref of client sdk --- cybersource-rest-samples-csharp.sln | 6 ------ src/SampleCode.csproj | 10 ++++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cybersource-rest-samples-csharp.sln b/cybersource-rest-samples-csharp.sln index 20cd80f..962d440 100644 --- a/cybersource-rest-samples-csharp.sln +++ b/cybersource-rest-samples-csharp.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCode", "src\SampleCode.csproj", "{4CF837FF-237D-4B5B-B922-71CCC654D718}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cybersource-rest-client-dotnet", "..\cybersource-rest-client-dotnet\cybersource-rest-client-dotnet.csproj", "{B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {4CF837FF-237D-4B5B-B922-71CCC654D718}.Debug|Any CPU.Build.0 = Debug|Any CPU {4CF837FF-237D-4B5B-B922-71CCC654D718}.Release|Any CPU.ActiveCfg = Release|Any CPU {4CF837FF-237D-4B5B-B922-71CCC654D718}.Release|Any CPU.Build.0 = Release|Any CPU - {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B0B5BDDB-E666-47EF-95B9-2BF8E88A51E4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/SampleCode.csproj b/src/SampleCode.csproj index 4d398a8..ad4e1ea 100644 --- a/src/SampleCode.csproj +++ b/src/SampleCode.csproj @@ -39,6 +39,10 @@ ..\packages\CyberSource.Authentication.0.0.0.3\lib\AuthenticationSdk.dll True + + ..\packages\CyberSource.Rest.Client.0.0.0.4\lib\cybersource-rest-client-dotnet.dll + True + ..\packages\CyberSource.Flex.Server.0.2.1\lib\FlexServerSDK.dll True @@ -142,12 +146,6 @@ - - - {b0b5bddb-e666-47ef-95b9-2bf8e88a51e4} - cybersource-rest-client-dotnet - -