Skip to content

Commit

Permalink
Merge pull request #37 from GregoryConrad/12.x
Browse files Browse the repository at this point in the history
Propagate 12.7.6 changes, refactor Communications
  • Loading branch information
VantivSDK authored Oct 15, 2020
2 parents d76065f + ab6c438 commit d5a5b4d
Show file tree
Hide file tree
Showing 41 changed files with 631 additions and 749 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

= Worldpay CNP CHANGELOG

==Version 12.15.1 (October 7, 2020)
* Feature: Added maxConnections config parameter to set the maximum number of http connections (defaults to ServicePointManager.DefaultConnectionLimit)
* Change: Propagated changes from 12.7.5-12.7.6, with some changes
* Change: The first CnpOnline object's config will now determine the proxy and timeout for the lifetime of the application
* BugFix: Tls 1.2 now the only available online encryption, specified for cnp-related connections only

==Version 12.15.0 (October 7, 2020)
* Feature: Added AuthenticationShopperID to cardTokenType
* Feature: Added copayAmount to healthcareAmounts
Expand Down Expand Up @@ -68,7 +74,12 @@

==Version 12.8.0 (June 20, 2019)
* Feature: Added new tokenURL element


==Version 12.7.6 (September 3, 2020)
* Feature: merchantId field added to CnpOnline class to allow changing merchantIds with same CnpOnline instance.
* Feature: keepAlive setting added to config for keeping the Async Http Request Alive
* BugFix: communication field is made static in CnpOnline to limit initializations

==Version 12.7.5 (July 17, 2019)
* BugFix: Refactor config code to limit direct property usage

Expand Down
6 changes: 3 additions & 3 deletions CnpSdkForNet/CnpSdkForNet/CnpBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public cnpRequest(Dictionary<string, string> config)
//
private void initializeRequest()
{
communication = new Communications();
communication = new Communications(config);

authentication = new authentication();
authentication.user = config["username"];
Expand Down Expand Up @@ -212,7 +212,7 @@ public string sendToCnp()
PgpHelper.EncryptFile(requestFilePath, finalRequestFilePath, vantivPublicKeyId);
}

communication.FtpDropOff(batchRequestDir, Path.GetFileName(finalRequestFilePath), config);
communication.FtpDropOff(batchRequestDir, Path.GetFileName(finalRequestFilePath));

return Path.GetFileName(finalRequestFilePath);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public cnpResponse receiveFromCnp(string batchFileName)
Path.Combine(batchResponseDir, batchFileName);
cnpFile.createDirectory(finalResponseFilePath);
}
communication.FtpPickUp(finalResponseFilePath, config, batchFileName);
communication.FtpPickUp(finalResponseFilePath, batchFileName);

if ("true".Equals(useEncryption))
{
Expand Down
67 changes: 35 additions & 32 deletions CnpSdkForNet/CnpSdkForNet/CnpOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,24 @@

namespace Cnp.Sdk
{


// Represent an online request.
// Defining all transactions supported for online processing.
public class CnpOnline : ICnpOnline
{
// Configuration object containing credentials and settings.
private Dictionary<string, string> _config;
//

// The object used for communicating with the server
private Communications _communication;

// exposed merchantId for organizations with multiple Merchant Ids.
private string _merchantId;

/**
* Construct a Cnp online using the configuration specified in CnpSdkForNet.dll.config
*/
public CnpOnline()
{
ConfigManager configManager = new ConfigManager();
_config = configManager.getConfig();

//_config["url"] = Properties.Settings.Default.url;
//_config["reportGroup"] = Properties.Settings.Default.reportGroup;
//_config["username"] = Properties.Settings.Default.username;
//_config["printxml"] = Properties.Settings.Default.printxml;
//_config["timeout"] = Properties.Settings.Default.timeout;
//_config["proxyHost"] = Properties.Settings.Default.proxyHost;
//_config["merchantId"] = Properties.Settings.Default.merchantId;
//_config["password"] = Properties.Settings.Default.password;
//_config["proxyPort"] = Properties.Settings.Default.proxyPort;
//_config["logFile"] = Properties.Settings.Default.logFile;
//_config["neuterAccountNums"] = Properties.Settings.Default.neuterAccountNums;
_communication = new Communications();

}
public CnpOnline() : this(new ConfigManager().getConfig()) { }

/**
* Construct a CnpOnline specifying the configuration in code. This should be used by integration that have another way
Expand All @@ -58,24 +43,42 @@ public CnpOnline()
* proxyHost
* proxyPort
* printxml (possible values "true" and "false" - defaults to false)
* maxConnections (max amount of connections used for HTTP requests)
*
* NOTE: The config of the first CnpOnline object created will determine the following
* for the entire lifespan of the application:
* - proxyHost
* - proxyPort
* - timeout
* - maxConnections
* These values *cannot* be changed for the lifetime of the application
*/
public CnpOnline(Dictionary<string, string> config)
{
this._config = config;
_communication = new Communications();
_config = config;
SetCommunication(new Communications(_config));
}

public event EventHandler HttpAction
public void SetCommunication(Communications communication)
{
add { _communication.HttpAction += value; }
remove { _communication.HttpAction -= value; }
_communication = communication;
}

public void SetCommunication(Communications communication)
public string GetMerchantId()
{
this._communication = communication;
return _merchantId;
}

public void SetMerchantId(string merchantId)
{
_merchantId = merchantId;
}

public event EventHandler HttpAction
{
add { _communication.HttpAction += value; }
remove { _communication.HttpAction -= value; }
}


public Task<authorizationResponse> AuthorizeAsync(authorization auth, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -1022,8 +1025,8 @@ public Task<customerDebitResponse> CustomerDebitAsync(customerDebit customerDebi
private cnpOnlineRequest CreateCnpOnlineRequest()
{
var request = new cnpOnlineRequest();
request.merchantId = _config["merchantId"];
request.merchantSdk = "DotNet;" + CnpVersion.CurrentCNPSDKVersion;
request.merchantId = _merchantId ?? _config["merchantId"];
var authentication = new authentication();
authentication.password = _config["password"];
authentication.user = _config["username"];
Expand All @@ -1034,7 +1037,7 @@ private cnpOnlineRequest CreateCnpOnlineRequest()
private cnpOnlineResponse SendToCnp(cnpOnlineRequest request)
{
var xmlRequest = request.Serialize();
var xmlResponse = _communication.HttpPost(xmlRequest, _config);
var xmlResponse = _communication.HttpPost(xmlRequest);
if (xmlResponse == null)
{
throw new WebException("Could not retrieve response from server for given request");
Expand Down Expand Up @@ -1086,7 +1089,7 @@ private async Task<T> SendRequestAsync<T>(Func<cnpOnlineResponse, T> getResponse
private async Task<cnpOnlineResponse> SendToCnpAsync(cnpOnlineRequest request, CancellationToken cancellationToken)
{
string xmlRequest = request.Serialize();
string xmlResponse = await _communication.HttpPostAsync(xmlRequest, _config, cancellationToken).ConfigureAwait(false);
string xmlResponse = await _communication.HttpPostAsync(xmlRequest, cancellationToken).ConfigureAwait(false);
return DeserializeResponse(xmlResponse);
}

Expand Down
2 changes: 1 addition & 1 deletion CnpSdkForNet/CnpSdkForNet/CnpSdkForNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>dotNetSDKKey.snk</AssemblyOriginatorKeyFile>
<PackageVersion>12.15.0</PackageVersion>
<PackageVersion>12.15.1</PackageVersion>
<Title>Vantiv.CnpSdkForNet</Title>
<Authors>Worldpay</Authors>
<Copyright>Copyright © Worldpay 2020</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion CnpSdkForNet/CnpSdkForNet/CnpVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Cnp.Sdk
public class CnpVersion
{
public const String CurrentCNPXMLVersion = "12.15";
public const String CurrentCNPSDKVersion = "12.15.0";
public const String CurrentCNPSDKVersion = "12.15.1";
}
}
Loading

0 comments on commit d5a5b4d

Please sign in to comment.