Skip to content

Commit 0eb523f

Browse files
authored
Merge pull request #1 from CyberSource/main
First Release (.NET Standard Authentication SDK)
2 parents 0daa1bc + 5aae76e commit 0eb523f

File tree

2,302 files changed

+345966
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,302 files changed

+345966
-1
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,10 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
.swagger-codegen
352+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/.swagger-codegen-ignore
353+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/.travis.yml
354+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/build.bat
355+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/build.sh
356+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/git_push.sh
357+
/cybersource-rest-client-netstandard/cybersource-rest-client-netstandard/mono_nunit_test.sh

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# .NET Standard Client SDK for the CyberSource REST API
2-
.NET Standard client library for the CyberSource REST API
2+
3+
The CyberSource .NET Standard client provides convenient access to the [CyberSource REST API](https://developer.cybersource.com/api/reference/api-reference.html) from your .NET application.
4+
5+
This repository also contains the code for the Authentication SDK written in .NET Standard.
6+
7+
For a more detailed explanation of these libraries, refer to
8+
9+
* [CyberSource REST Client SDK README.md](./cybersource-rest-client-netstandard/README.md)
10+
11+
* [CyberSource Authentication SDK README.md](./cybersource-rest-auth-netstandard/README.md)
12+
13+
## License
14+
15+
This repository is distributed under a proprietary license.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30517.126
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiSdk", "ApiSdk\ApiSdk.csproj", "{23C047B9-8597-4A5F-82B7-A2F97555AD9F}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiSdkTests.NetCore", "ApiSdkTests.NetCore\ApiSdkTests.NetCore.csproj", "{B3F426A5-7324-4147-8992-7C50B1902C73}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{23C047B9-8597-4A5F-82B7-A2F97555AD9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{23C047B9-8597-4A5F-82B7-A2F97555AD9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{23C047B9-8597-4A5F-82B7-A2F97555AD9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{23C047B9-8597-4A5F-82B7-A2F97555AD9F}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B3F426A5-7324-4147-8992-7C50B1902C73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B3F426A5-7324-4147-8992-7C50B1902C73}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B3F426A5-7324-4147-8992-7C50B1902C73}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B3F426A5-7324-4147-8992-7C50B1902C73}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {A4D25916-F2C3-471F-8B4B-86CD58B767D7}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
8+
<DebugType>full</DebugType>
9+
<DebugSymbols>true</DebugSymbols>
10+
<OutputPath>bin\Debug</OutputPath>
11+
<DefineConstants>DEBUG;TRACE</DefineConstants>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
15+
<DebugType>pdbonly</DebugType>
16+
<DebugSymbols>true</DebugSymbols>
17+
<OutputPath>bin\Release</OutputPath>
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
22+
<PackageReference Include="NLog" Version="4.7.4" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Reference Include="Cybersource.Authentication.NetStandard">
27+
<HintPath>..\..\AuthenticationSdk\AuthenticationSdk\bin\Debug\netstandard2.1\Cybersource.Authentication.NetStandard.dll</HintPath>
28+
</Reference>
29+
</ItemGroup>
30+
31+
</Project>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System.Net.Http;
2+
using System.Net.Http.Headers;
3+
using ApiSdk.util;
4+
using AuthenticationSdk.core;
5+
6+
namespace ApiSdk.connection
7+
{
8+
public class HTTPConnection : IConnection
9+
{
10+
public HttpClient GetConnectionForGet(MerchantConfig merchantConfig)
11+
{
12+
var signature = AuthenticationHelper.GetSignature(merchantConfig);
13+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
14+
var client = httpConnUtility.GetHttpClient();
15+
16+
client.DefaultRequestHeaders
17+
.Accept
18+
.Add(new MediaTypeWithQualityHeaderValue(Constants.MediaTypeHalAndJson));
19+
20+
client.DefaultRequestHeaders.Add("v-c-merchant-id", signature.MerchantId);
21+
22+
client.DefaultRequestHeaders.Add("Date", signature.GmtDateTime);
23+
24+
client.DefaultRequestHeaders.Add("Host", signature.HostName);
25+
26+
client.DefaultRequestHeaders.Add("Signature", signature.SignatureParam);
27+
28+
return client;
29+
}
30+
31+
public HttpClient GetConnectionForPost(MerchantConfig merchantConfig)
32+
{
33+
var signature = AuthenticationHelper.GetSignature(merchantConfig);
34+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
35+
var client = httpConnUtility.GetHttpClient();
36+
37+
client.DefaultRequestHeaders.Add("v-c-merchant-id", signature.MerchantId);
38+
39+
client.DefaultRequestHeaders.Add("Date", signature.GmtDateTime);
40+
41+
client.DefaultRequestHeaders.Add("Host", signature.HostName);
42+
43+
client.DefaultRequestHeaders.Add("Digest", signature.Digest);
44+
45+
client.DefaultRequestHeaders.Add("Signature", signature.SignatureParam);
46+
47+
return client;
48+
}
49+
50+
public HttpClient GetConnectionForPut(MerchantConfig merchantConfig)
51+
{
52+
var signature = AuthenticationHelper.GetSignature(merchantConfig);
53+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
54+
var client = httpConnUtility.GetHttpClient();
55+
56+
client.DefaultRequestHeaders.Add("v-c-merchant-id", signature.MerchantId);
57+
58+
client.DefaultRequestHeaders.Add("Date", signature.GmtDateTime);
59+
60+
client.DefaultRequestHeaders.Add("Host", signature.HostName);
61+
62+
client.DefaultRequestHeaders.Add("Digest", signature.Digest);
63+
64+
client.DefaultRequestHeaders.Add("Signature", signature.SignatureParam);
65+
66+
return client;
67+
}
68+
69+
public HttpClient GetConnectionForDelete(MerchantConfig merchantConfig)
70+
{
71+
var signature = AuthenticationHelper.GetSignature(merchantConfig);
72+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
73+
var client = httpConnUtility.GetHttpClient();
74+
75+
client.DefaultRequestHeaders
76+
.Accept
77+
.Add(new MediaTypeWithQualityHeaderValue(Constants.MediaTypeHalAndJson));
78+
79+
client.DefaultRequestHeaders.Add("v-c-merchant-id", signature.MerchantId);
80+
81+
client.DefaultRequestHeaders.Add("Date", signature.GmtDateTime);
82+
83+
client.DefaultRequestHeaders.Add("Host", signature.HostName);
84+
85+
client.DefaultRequestHeaders.Add("Signature", signature.SignatureParam);
86+
87+
return client;
88+
}
89+
}
90+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Net.Http;
2+
using AuthenticationSdk.core;
3+
4+
namespace ApiSdk.connection
5+
{
6+
public interface IConnection
7+
{
8+
HttpClient GetConnectionForGet(MerchantConfig merchantConfig);
9+
10+
HttpClient GetConnectionForPost(MerchantConfig merchantConfig);
11+
12+
HttpClient GetConnectionForPut(MerchantConfig merchantConfig);
13+
14+
HttpClient GetConnectionForDelete(MerchantConfig merchantConfig);
15+
}
16+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Net.Http;
2+
using System.Net.Http.Headers;
3+
using ApiSdk.util;
4+
using AuthenticationSdk.core;
5+
6+
namespace ApiSdk.connection
7+
{
8+
public class JWTConnection : IConnection
9+
{
10+
public HttpClient GetConnectionForGet(MerchantConfig merchantConfig)
11+
{
12+
var token = AuthenticationHelper.GetToken(merchantConfig);
13+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
14+
var client = httpConnUtility.GetHttpClient();
15+
16+
client.DefaultRequestHeaders
17+
.Accept
18+
.Add(new MediaTypeWithQualityHeaderValue(Constants.MediaTypeHalAndJson));
19+
20+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.Bearer, token.BearerToken);
21+
22+
return client;
23+
}
24+
25+
public HttpClient GetConnectionForPost(MerchantConfig merchantConfig)
26+
{
27+
var token = AuthenticationHelper.GetToken(merchantConfig);
28+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
29+
var client = httpConnUtility.GetHttpClient();
30+
31+
var content = new StringContent(merchantConfig.RequestJsonData);
32+
content.Headers.ContentType = new MediaTypeHeaderValue(Constants.MediaTypeJson);
33+
34+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.Bearer, token.BearerToken);
35+
36+
return client;
37+
}
38+
39+
public HttpClient GetConnectionForPut(MerchantConfig merchantConfig)
40+
{
41+
var token = AuthenticationHelper.GetToken(merchantConfig);
42+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
43+
var client = httpConnUtility.GetHttpClient();
44+
45+
var content = new StringContent(merchantConfig.RequestJsonData);
46+
content.Headers.ContentType = new MediaTypeHeaderValue(Constants.MediaTypeJson);
47+
48+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.Bearer, token.BearerToken);
49+
50+
return client;
51+
}
52+
53+
public HttpClient GetConnectionForDelete(MerchantConfig merchantConfig)
54+
{
55+
var token = AuthenticationHelper.GetToken(merchantConfig);
56+
var httpConnUtility = new HttpConnUtility(merchantConfig.ProxyAddress, merchantConfig.ProxyPort, merchantConfig.TimeOut);
57+
var client = httpConnUtility.GetHttpClient();
58+
59+
client.DefaultRequestHeaders
60+
.Accept
61+
.Add(new MediaTypeWithQualityHeaderValue(Constants.MediaTypeHalAndJson));
62+
63+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Constants.Bearer, token.BearerToken);
64+
65+
return client;
66+
}
67+
}
68+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using ApiSdk.model;
3+
using ApiSdk.service;
4+
using AuthenticationSdk.core;
5+
using AuthenticationSdk.util;
6+
using NLog;
7+
8+
namespace ApiSdk.controller
9+
{
10+
/*================================================================================
11+
* Provides Methods to Make HTTP Requests (GET/POST/PUT/DELETE) to CYBS REST API's
12+
*===============================================================================*/
13+
public class APIController
14+
{
15+
private readonly Logger _logger;
16+
private readonly PaymentRequestService _paymentRequestService;
17+
18+
public APIController(MerchantConfig merchantConfig)
19+
{
20+
_logger = LogManager.GetCurrentClassLogger();
21+
Enumerations.ValidateRequestType(merchantConfig.RequestType);
22+
Enumerations.SetRequestType(merchantConfig);
23+
_paymentRequestService = new PaymentRequestService(merchantConfig);
24+
}
25+
26+
/**
27+
* @return a Response object (HTTP Response) for the HTTP GET Request
28+
* based on the Merchant Configuration passed to the Constructor of ApiController Class
29+
*/
30+
public Response GetPayment()
31+
{
32+
try
33+
{
34+
// Call the Service to Get the Response Object
35+
var response = _paymentRequestService.GetResponse();
36+
LogResponseDetails(response);
37+
38+
return response;
39+
}
40+
catch (Exception e)
41+
{
42+
ExceptionUtility.Exception(e.Message, e.StackTrace);
43+
return null;
44+
}
45+
}
46+
47+
/**
48+
* @return a Response object (HTTP Response) for the HTTP POST Request
49+
* based on the Merchant Configuration passed to the Constructor of ApiController Class
50+
*/
51+
public Response PostPayment()
52+
{
53+
try
54+
{
55+
// Call the Service to Get the Response Object
56+
var response = _paymentRequestService.PostResponse();
57+
LogResponseDetails(response);
58+
59+
return response;
60+
}
61+
catch (Exception e)
62+
{
63+
ExceptionUtility.Exception(e.Message, e.StackTrace);
64+
return null;
65+
}
66+
}
67+
68+
/**
69+
* @return a Response object (HTTP Response) for the HTTP PUT Request
70+
* based on the Merchant Configuration passed to the Constructor of ApiController Class
71+
*/
72+
public Response PutPayment()
73+
{
74+
try
75+
{
76+
// Call the Service to Get the Response Object
77+
var response = _paymentRequestService.PutResponse();
78+
LogResponseDetails(response);
79+
80+
return response;
81+
}
82+
catch (Exception e)
83+
{
84+
ExceptionUtility.Exception(e.Message, e.StackTrace);
85+
return null;
86+
}
87+
}
88+
89+
/**
90+
* @return a Response object (HTTP Response) for the HTTP DELETE Request
91+
* based on the Merchant Configuration passed to the Constructor of ApiController Class
92+
*/
93+
public Response DeletePayment()
94+
{
95+
try
96+
{
97+
// Call the Service to Get the Response Object
98+
var response = _paymentRequestService.DeleteResponse();
99+
LogResponseDetails(response);
100+
101+
return response;
102+
}
103+
catch (Exception e)
104+
{
105+
ExceptionUtility.Exception(e.Message, e.StackTrace);
106+
return null;
107+
}
108+
}
109+
110+
private void LogResponseDetails(Response response)
111+
{
112+
_logger.Info("v-c-correlation-id:{0}", response.GetResponseHeaderValue(response.Headers, "v-c-correlation-id"));
113+
_logger.Info("Response Code:{0}", response.StatusCode);
114+
_logger.Info("Response Message:{0}", response.Data);
115+
_logger.Info("Status Information:{0}", response.StatusInfo);
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)