Skip to content

Commit

Permalink
Merge pull request #66 from Vantiv/US268420-Add-Timeout-Setting-11.0
Browse files Browse the repository at this point in the history
Us268420 add timeout setting 11.0
  • Loading branch information
VantivSDK authored Oct 25, 2019
2 parents 31eb769 + 963a8bd commit f73c6a1
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
= LitleOnline CHANGELOG

== Version 11.4.9 (October 25, 2019)
* BugFix: Fixed timeout not being used in non-async methods

== Version 11.4.8 (August 22, 2019)
* BugFix: merchantSdk field in generated xml request is synced.

Expand Down
113 changes: 103 additions & 10 deletions LitleSdkForNet/LitleSdkForNet/Communications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,109 @@ public virtual Task<string> HttpPostAsync(string xmlRequest, Dictionary<string,

public virtual string HttpPost(string xmlRequest, Dictionary<string, string> config)
{
return HttpPostCoreAsync(xmlRequest, config, isAsync: false).GetAwaiter().GetResult();
string logFile = null;
if (config.ContainsKey("logFile"))
{
logFile = config["logFile"];
}

var uri = config["url"];

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
var req = (HttpWebRequest)WebRequest.Create(uri);

var neuterAccNums = false;
if (config.ContainsKey("neuterAccountNums"))
{
neuterAccNums = ("true".Equals(config["neuterAccountNums"]));
}

var neuterCreds = false;
if (config.ContainsKey("neuterUserCredentials"))
{
neuterCreds = ("true".Equals(config["neuterUserCredentials"]));
}

var printxml = false;
if (config.ContainsKey("printxml"))
{
if ("true".Equals(config["printxml"]))
{
printxml = true;
}
}

if (printxml)
{
Console.WriteLine(xmlRequest);
Console.WriteLine(logFile);
Console.WriteLine(logFile);
}

//log request
if (logFile != null)
{
Log(xmlRequest, logFile, neuterAccNums, neuterCreds);
}

req.ContentType = ContentTypeTextXmlUTF8;
req.Method = "POST";
req.ServicePoint.MaxIdleTime = 8000;
req.ServicePoint.Expect100Continue = false;
req.KeepAlive = false;

if (config.ContainsKey("timeout")) {
try {
req.Timeout = Convert.ToInt32(config["timeout"]);
}
catch (FormatException e) {
// If timeout setting contains non-numeric
// characters, we will fall back to 1 minute
// default timeout.
req.Timeout = 60000;
}
}


if (IsProxyOn(config))
{
var myproxy = new WebProxy(config["proxyHost"], int.Parse(config["proxyPort"]))
{
BypassProxyOnLocal = true
};
req.Proxy = myproxy;
}

OnHttpAction(RequestType.Request, xmlRequest, neuterAccNums, neuterCreds);

// submit http request
using (var writer = new StreamWriter(req.GetRequestStream()))
{
writer.Write(xmlRequest);
}

// read response
var response = req.GetResponse();

string xmlResponse;
using (var reader = new StreamReader(response.GetResponseStream()))
{
xmlResponse = reader.ReadToEnd().Trim();
}
if (printxml)
{
Console.WriteLine(xmlResponse);
}

OnHttpAction(RequestType.Response, xmlResponse, neuterAccNums, neuterCreds);

//log response
if (logFile != null)
{
Log(xmlResponse, logFile, neuterAccNums, neuterCreds);
}

return xmlResponse;
}

private async Task<string> HttpPostCoreAsync(string xmlRequest, Dictionary<string, string> config, bool isAsync, CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -170,15 +272,6 @@ public virtual string HttpPost(string xmlRequest, Dictionary<string, string> con
req.ServicePoint.MaxIdleTime = 8000;
req.ServicePoint.Expect100Continue = false;
req.KeepAlive = false;

//set timeout for request if available. #Issue 58
//connection timeout is increased 3 times on successful establishment.
if(config.ContainsKey("timeout") && config["timeout"] != null && int.Parse(config["timeout"]) > 0)
{
var timeOut = int.Parse(config["timeout"]);
req.Timeout = timeOut;
req.ReadWriteTimeout = 3*timeOut;
}


if (IsProxyOn(config))
Expand Down
2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ public string generateXmlHeader()
xmlHeader += "sameDayFunding=\"" + sameDayFunding.ToString().ToLower() + "\"\r\n";
}

xmlHeader += "merchantSdk=\"DotNet;11.4.8\"\r\n";
xmlHeader += "merchantSdk=\"DotNet;11.4.9\"\r\n";

xmlHeader += "merchantId=\"" + config["merchantId"] + "\">\r\n";
return xmlHeader;
Expand Down
2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNet/LitleOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ private litleOnlineRequest CreateLitleOnlineRequest()
{
var request = new litleOnlineRequest();
request.merchantId = _config["merchantId"];
request.merchantSdk = "DotNet;11.4.8";
request.merchantSdk = "DotNet;11.4.9";
var authentication = new authentication();
authentication.password = _config["password"];
authentication.user = _config["username"];
Expand Down
4 changes: 2 additions & 2 deletions LitleSdkForNet/LitleSdkForNet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("11.4.8")]
[assembly: AssemblyFileVersion("11.4.8")]
[assembly: AssemblyVersion("11.4.9")]
[assembly: AssemblyFileVersion("11.4.9")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNet/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Value Profile="(Default)">true</Value>
</Setting>
<Setting Name="timeout" Type="System.String" Scope="User">
<Value Profile="(Default)">500</Value>
<Value Profile="(Default)">5000</Value>
</Setting>
<Setting Name="sftpUrl" Type="System.String" Scope="User">
<Value Profile="(Default)">payments.vantivprelive.com</Value>
Expand Down
106 changes: 106 additions & 0 deletions LitleSdkForNet/LitleSdkForNetTest/Functional/TestTimeout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Collections.Generic;
using System.Net;
using NUnit.Framework;

namespace Litle.Sdk.Test.Functional {
[TestFixture]
internal class TestTimeout
{
private LitleOnline _cnp;
private Dictionary<string, string> _config;

[Test]
public void TestTimeoutNotDefined()
{
_config = new Dictionary<string, string>
{
{"url", Properties.Settings.Default.url},
{"reportGroup", "Default Report Group"},
{"username", "DOTNET"},
{"version", "11.0"},
{"merchantId", "101"},
{"password", "TESTCASE"},
{"printxml", "true"},
{"proxyHost", Properties.Settings.Default.proxyHost},
{"proxyPort", Properties.Settings.Default.proxyPort},
{"logFile", Properties.Settings.Default.logFile},
{"neuterAccountNums", "true"}
};

_cnp = new LitleOnline(_config);

var registerTokenRequest = new registerTokenRequestType
{
id = "1",
reportGroup = "Planets",
orderId = "12344",
accountNumber = "1233456789103801",
};

var rtokenResponse = _cnp.RegisterToken(registerTokenRequest);
StringAssert.AreEqualIgnoringCase("Account number was successfully registered", rtokenResponse.message);
}

[Test]
public void TestTimeoutNotParsable()
{
_config = new Dictionary<string, string>
{
{"url", Properties.Settings.Default.url},
{"reportGroup", "Default Report Group"},
{"username", "DOTNET"},
{"version", "11.0"},
{"timeout", "notparsableasint"},
{"merchantId", "101"},
{"password", "TESTCASE"},
{"printxml", "true"},
{"proxyHost", Properties.Settings.Default.proxyHost},
{"proxyPort", Properties.Settings.Default.proxyPort},
{"logFile", Properties.Settings.Default.logFile},
{"neuterAccountNums", "true"}
};

_cnp = new LitleOnline(_config);

var registerTokenRequest = new registerTokenRequestType
{
id = "1",
reportGroup = "Planets",
orderId = "12344",
accountNumber = "1233456789103801",
};

var rtokenResponse = _cnp.RegisterToken(registerTokenRequest);
StringAssert.AreEqualIgnoringCase("Account number was successfully registered", rtokenResponse.message);
}

[Test]
public void TestTimeoutReached() {
_config = new Dictionary<string, string> {
{"url", Properties.Settings.Default.url},
{"reportGroup", "Default Report Group"},
{"username", "DOTNET"},
{"version", "11.0"},
{"timeout", "0"},
{"merchantId", "101"},
{"password", "TESTCASE"},
{"printxml", "true"},
{"proxyHost", Properties.Settings.Default.proxyHost},
{"proxyPort", Properties.Settings.Default.proxyPort},
{"logFile", Properties.Settings.Default.logFile},
{"neuterAccountNums", "true"}
};

_cnp = new LitleOnline(_config);

var registerTokenRequest = new registerTokenRequestType {
id = "1",
reportGroup = "Planets",
orderId = "12344",
accountNumber = "1233456789103801",
};

Assert.Throws<WebException>(() => { _cnp.RegisterToken(registerTokenRequest); });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Functional\TestReserve.cs" />
<Compile Include="Functional\TestSubmerchant.cs" />
<Compile Include="Functional\TestSubscriptionTxns.cs" />
<Compile Include="Functional\TestTimeout.cs" />
<Compile Include="Functional\TestUnload.cs" />
<Compile Include="Functional\TestLoad.cs" />
<Compile Include="Functional\TestDeactivate.cs" />
Expand Down
2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testBatchRequestContainsMerchantSdkAttribute()
var actual = batchRequest.generateXmlHeader();
var expected = @"
<batchRequest id=""""
merchantSdk=""DotNet;11.4.8""
merchantSdk=""DotNet;11.4.9""
merchantId=""01234"">
";

Expand Down

0 comments on commit f73c6a1

Please sign in to comment.