Skip to content

Commit

Permalink
Merge pull request #293 from AuthorizeNet/environment-issue
Browse files Browse the repository at this point in the history
Adding mutex lock on Configuration Properties
  • Loading branch information
gnongsie authored Apr 7, 2022
2 parents 705b310 + 2f6ff45 commit c343d3e
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 122 deletions.
238 changes: 121 additions & 117 deletions Authorize.NET/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,130 +19,134 @@ namespace AuthorizeNet
public class Environment {
public static readonly Environment SANDBOX = new Environment("https://test.authorize.net", "https://apitest.authorize.net", "https://test.authorize.net");
public static readonly Environment PRODUCTION = new Environment("https://secure2.authorize.net","https://api2.authorize.net","https://cardpresent.authorize.net");
public static readonly Environment LOCAL_VM = new Environment(null, null, null);
public static readonly Environment HOSTED_VM = new Environment(null, null, null);
public static readonly Environment LOCAL_VM = new Environment(null, null, null);
public static readonly Environment HOSTED_VM = new Environment(null, null, null);
public static Environment CUSTOM = new Environment(null, null, null);

private String _baseUrl;
private String _xmlBaseUrl;
private String _cardPresentUrl;

private Environment(String baseUrl, String xmlBaseUrl, String cardPresentUrl) {
_baseUrl = baseUrl;
_xmlBaseUrl = xmlBaseUrl;
_cardPresentUrl = cardPresentUrl;
}

/**
* @return the baseUrl
*/
public String getBaseUrl() {
return _baseUrl;
}

/**
* @return the xmlBaseUrl
*/
public String getXmlBaseUrl() {
return _xmlBaseUrl;
}

/**
* @return the cardPresentUrl
*/
public String getCardPresentUrl() {
return _cardPresentUrl;
}

/**
* If a custom environment needs to be supported, this convenience create
* method can be used to pass in a custom baseUrl.
*
* @param baseUrl
* @param xmlBaseUrl
* @return Environment object
*/
public static Environment createEnvironment(String baseUrl, String xmlBaseUrl) {

return createEnvironment( baseUrl, xmlBaseUrl, null);
}

/**
* If a custom environment needs to be supported, this convenience create
* method can be used to pass in a custom baseUrl.
*
* @param baseUrl
* @param xmlBaseUrl
* @param cardPresentUrl
*
* @return Environment object
*/
public static Environment createEnvironment(String baseUrl, String xmlBaseUrl, String cardPresentUrl) {
var environment = Environment.CUSTOM;
environment._baseUrl = baseUrl;
environment._xmlBaseUrl = xmlBaseUrl;
environment._cardPresentUrl = cardPresentUrl;

return environment;
}
/**
* Reads a integer value from property file and/or the environment
* Values in property file supersede the values set in environment
* @param propertyName name of the integer property to read
* @return int property value
*/
public static int getIntProperty( String propertyName)
{
var stringValue = GetProperty(propertyName);
private String _baseUrl;
private String _xmlBaseUrl;
private String _cardPresentUrl;

private Environment(String baseUrl, String xmlBaseUrl, String cardPresentUrl) {
_baseUrl = baseUrl;
_xmlBaseUrl = xmlBaseUrl;
_cardPresentUrl = cardPresentUrl;
}

/**
* @return the baseUrl
*/
public String getBaseUrl() {
return _baseUrl;
}

/**
* @return the xmlBaseUrl
*/
public String getXmlBaseUrl() {
return _xmlBaseUrl;
}

/**
* @return the cardPresentUrl
*/
public String getCardPresentUrl() {
return _cardPresentUrl;
}

/**
* If a custom environment needs to be supported, this convenience create
* method can be used to pass in a custom baseUrl.
*
* @param baseUrl
* @param xmlBaseUrl
* @return Environment object
*/
public static Environment createEnvironment(String baseUrl, String xmlBaseUrl) {

return createEnvironment( baseUrl, xmlBaseUrl, null);
}

/**
* If a custom environment needs to be supported, this convenience create
* method can be used to pass in a custom baseUrl.
*
* @param baseUrl
* @param xmlBaseUrl
* @param cardPresentUrl
*
* @return Environment object
*/
public static Environment createEnvironment(String baseUrl, String xmlBaseUrl, String cardPresentUrl) {
var environment = Environment.CUSTOM;
environment._baseUrl = baseUrl;
environment._xmlBaseUrl = xmlBaseUrl;
environment._cardPresentUrl = cardPresentUrl;

return environment;
}
/**
* Reads a integer value from property file and/or the environment
* Values in property file supersede the values set in environment
* @param propertyName name of the integer property to read
* @return int property value
*/
public static int getIntProperty( String propertyName)
{
var stringValue = GetProperty(propertyName);
var value = (AuthorizeNet.Util.StringUtils.ParseInt(stringValue));

return value;
}

/**
* Reads a boolean value from property file and/or the environment
* Values in property file supersede the values set in environment
* @param propertyName name of the boolean property to read
* @return boolean property value
*/
public static bool getBooleanProperty( String propertyName)
{
var value = false;
var stringValue = GetProperty(propertyName);
if ( null != stringValue)
{
Boolean.TryParse(stringValue.Trim(), out value);
}

return value;
}

/// <summary>
/// Reads the value from property file and/or the environment
/// Values in property file supersede the values set in environmen
/// </summary>

return value;
}

/**
* Reads a boolean value from property file and/or the environment
* Values in property file supersede the values set in environment
* @param propertyName name of the boolean property to read
* @return boolean property value
*/
public static bool getBooleanProperty( String propertyName)
{
var value = false;
var stringValue = GetProperty(propertyName);
if ( null != stringValue)
{
Boolean.TryParse(stringValue.Trim(), out value);
}

return value;
}

private static object mutex = new object();

/// <summary>
/// Reads the value from property file and/or the environment
/// Values in property file supersede the values set in environmen
/// </summary>
/// <param name="propertyName">propertyName name of the property to read</param>
/// <returns>String property value</returns>
public static String GetProperty(String propertyName) {
String stringValue = null;
public static String GetProperty(String propertyName) {
String stringValue = null;
String propValue = null;

String propValue = null;
if ( ConfigurationManager.AppSettings.AllKeys.Contains(propertyName))
{
propValue = ConfigurationManager.AppSettings[propertyName];
}
lock(mutex) {
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get(propertyName)))
{
propValue = ConfigurationManager.AppSettings.Get(propertyName);
}
}

var envValue = System.Environment.GetEnvironmentVariable(propertyName);
if ( null != propValue && propValue.Trim().Length > 0 )
{
stringValue = propValue;
}
else if ( null != envValue && envValue.Trim().Length > 0 )
{
stringValue = envValue;
}
return stringValue;
}
if ( null != propValue && propValue.Trim().Length > 0 )
{
stringValue = propValue;
}
else if ( null != envValue && envValue.Trim().Length > 0 )
{
stringValue = envValue;
}
return stringValue;
}
}
}
6 changes: 3 additions & 3 deletions Authorize.NET/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Revision
//
// See AssemblyFileVersion.cs for Product and Assembly Version
//[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.2.0")]
[assembly: AssemblyVersion("2.0.2.0")]
//[assembly: AssemblyVersion("2.0.2.0")]
[assembly: AssemblyFileVersion("2.0.3.0")]
[assembly: AssemblyVersion("2.0.3.0")]

2 changes: 1 addition & 1 deletion Authorize.NET/Util/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class Constants {
public const int HttpConnectionDefaultTimeout = 30000;
public const int HttpReadWriteDefaultTimeout = 30000;

public const string SDKVersion = "2.0.2";
public const string SDKVersion = "2.0.3";

}
#pragma warning restore 1591
Expand Down
2 changes: 1 addition & 1 deletion AuthorizeNet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>AuthorizeNet</id>
<version>2.0.2</version>
<version>2.0.3</version>
<title>AuthorizeNet</title>
<authors>Authorize.Net</authors>
<owners>AuthorizeNet</owners>
Expand Down

0 comments on commit c343d3e

Please sign in to comment.