@@ -19,130 +19,134 @@ namespace AuthorizeNet
19
19
public class Environment {
20
20
public static readonly Environment SANDBOX = new Environment ( "https://test.authorize.net" , "https://apitest.authorize.net" , "https://test.authorize.net" ) ;
21
21
public static readonly Environment PRODUCTION = new Environment ( "https://secure2.authorize.net" , "https://api2.authorize.net" , "https://cardpresent.authorize.net" ) ;
22
- public static readonly Environment LOCAL_VM = new Environment ( null , null , null ) ;
23
- public static readonly Environment HOSTED_VM = new Environment ( null , null , null ) ;
22
+ public static readonly Environment LOCAL_VM = new Environment ( null , null , null ) ;
23
+ public static readonly Environment HOSTED_VM = new Environment ( null , null , null ) ;
24
24
public static Environment CUSTOM = new Environment ( null , null , null ) ;
25
25
26
- private String _baseUrl ;
27
- private String _xmlBaseUrl ;
28
- private String _cardPresentUrl ;
29
-
30
- private Environment ( String baseUrl , String xmlBaseUrl , String cardPresentUrl ) {
31
- _baseUrl = baseUrl ;
32
- _xmlBaseUrl = xmlBaseUrl ;
33
- _cardPresentUrl = cardPresentUrl ;
34
- }
35
-
36
- /**
37
- * @return the baseUrl
38
- */
39
- public String getBaseUrl ( ) {
40
- return _baseUrl ;
41
- }
42
-
43
- /**
44
- * @return the xmlBaseUrl
45
- */
46
- public String getXmlBaseUrl ( ) {
47
- return _xmlBaseUrl ;
48
- }
49
-
50
- /**
51
- * @return the cardPresentUrl
52
- */
53
- public String getCardPresentUrl ( ) {
54
- return _cardPresentUrl ;
55
- }
56
-
57
- /**
58
- * If a custom environment needs to be supported, this convenience create
59
- * method can be used to pass in a custom baseUrl.
60
- *
61
- * @param baseUrl
62
- * @param xmlBaseUrl
63
- * @return Environment object
64
- */
65
- public static Environment createEnvironment ( String baseUrl , String xmlBaseUrl ) {
66
-
67
- return createEnvironment ( baseUrl , xmlBaseUrl , null ) ;
68
- }
69
-
70
- /**
71
- * If a custom environment needs to be supported, this convenience create
72
- * method can be used to pass in a custom baseUrl.
73
- *
74
- * @param baseUrl
75
- * @param xmlBaseUrl
76
- * @param cardPresentUrl
77
- *
78
- * @return Environment object
79
- */
80
- public static Environment createEnvironment ( String baseUrl , String xmlBaseUrl , String cardPresentUrl ) {
81
- var environment = Environment . CUSTOM ;
82
- environment . _baseUrl = baseUrl ;
83
- environment . _xmlBaseUrl = xmlBaseUrl ;
84
- environment . _cardPresentUrl = cardPresentUrl ;
85
-
86
- return environment ;
87
- }
88
-
89
- /**
90
- * Reads a integer value from property file and/or the environment
91
- * Values in property file supersede the values set in environment
92
- * @param propertyName name of the integer property to read
93
- * @return int property value
94
- */
95
- public static int getIntProperty ( String propertyName )
96
- {
97
- var stringValue = GetProperty ( propertyName ) ;
26
+ private String _baseUrl ;
27
+ private String _xmlBaseUrl ;
28
+ private String _cardPresentUrl ;
29
+
30
+ private Environment ( String baseUrl , String xmlBaseUrl , String cardPresentUrl ) {
31
+ _baseUrl = baseUrl ;
32
+ _xmlBaseUrl = xmlBaseUrl ;
33
+ _cardPresentUrl = cardPresentUrl ;
34
+ }
35
+
36
+ /**
37
+ * @return the baseUrl
38
+ */
39
+ public String getBaseUrl ( ) {
40
+ return _baseUrl ;
41
+ }
42
+
43
+ /**
44
+ * @return the xmlBaseUrl
45
+ */
46
+ public String getXmlBaseUrl ( ) {
47
+ return _xmlBaseUrl ;
48
+ }
49
+
50
+ /**
51
+ * @return the cardPresentUrl
52
+ */
53
+ public String getCardPresentUrl ( ) {
54
+ return _cardPresentUrl ;
55
+ }
56
+
57
+ /**
58
+ * If a custom environment needs to be supported, this convenience create
59
+ * method can be used to pass in a custom baseUrl.
60
+ *
61
+ * @param baseUrl
62
+ * @param xmlBaseUrl
63
+ * @return Environment object
64
+ */
65
+ public static Environment createEnvironment ( String baseUrl , String xmlBaseUrl ) {
66
+
67
+ return createEnvironment ( baseUrl , xmlBaseUrl , null ) ;
68
+ }
69
+
70
+ /**
71
+ * If a custom environment needs to be supported, this convenience create
72
+ * method can be used to pass in a custom baseUrl.
73
+ *
74
+ * @param baseUrl
75
+ * @param xmlBaseUrl
76
+ * @param cardPresentUrl
77
+ *
78
+ * @return Environment object
79
+ */
80
+ public static Environment createEnvironment ( String baseUrl , String xmlBaseUrl , String cardPresentUrl ) {
81
+ var environment = Environment . CUSTOM ;
82
+ environment . _baseUrl = baseUrl ;
83
+ environment . _xmlBaseUrl = xmlBaseUrl ;
84
+ environment . _cardPresentUrl = cardPresentUrl ;
85
+
86
+ return environment ;
87
+ }
88
+
89
+ /**
90
+ * Reads a integer value from property file and/or the environment
91
+ * Values in property file supersede the values set in environment
92
+ * @param propertyName name of the integer property to read
93
+ * @return int property value
94
+ */
95
+ public static int getIntProperty ( String propertyName )
96
+ {
97
+ var stringValue = GetProperty ( propertyName ) ;
98
98
var value = ( AuthorizeNet . Util . StringUtils . ParseInt ( stringValue ) ) ;
99
-
100
- return value ;
101
- }
102
-
103
- /**
104
- * Reads a boolean value from property file and/or the environment
105
- * Values in property file supersede the values set in environment
106
- * @param propertyName name of the boolean property to read
107
- * @return boolean property value
108
- */
109
- public static bool getBooleanProperty ( String propertyName )
110
- {
111
- var value = false ;
112
- var stringValue = GetProperty ( propertyName ) ;
113
- if ( null != stringValue )
114
- {
115
- Boolean . TryParse ( stringValue . Trim ( ) , out value ) ;
116
- }
117
-
118
- return value ;
119
- }
120
-
121
- /// <summary>
122
- /// Reads the value from property file and/or the environment
123
- /// Values in property file supersede the values set in environmen
124
- /// </summary>
99
+
100
+ return value ;
101
+ }
102
+
103
+ /**
104
+ * Reads a boolean value from property file and/or the environment
105
+ * Values in property file supersede the values set in environment
106
+ * @param propertyName name of the boolean property to read
107
+ * @return boolean property value
108
+ */
109
+ public static bool getBooleanProperty ( String propertyName )
110
+ {
111
+ var value = false ;
112
+ var stringValue = GetProperty ( propertyName ) ;
113
+ if ( null != stringValue )
114
+ {
115
+ Boolean . TryParse ( stringValue . Trim ( ) , out value ) ;
116
+ }
117
+
118
+ return value ;
119
+ }
120
+
121
+ private static object mutex = new object ( ) ;
122
+
123
+ /// <summary>
124
+ /// Reads the value from property file and/or the environment
125
+ /// Values in property file supersede the values set in environmen
126
+ /// </summary>
125
127
/// <param name="propertyName">propertyName name of the property to read</param>
126
128
/// <returns>String property value</returns>
127
- public static String GetProperty ( String propertyName ) {
128
- String stringValue = null ;
129
+ public static String GetProperty ( String propertyName ) {
130
+ String stringValue = null ;
131
+ String propValue = null ;
129
132
130
- String propValue = null ;
131
- if ( ConfigurationManager . AppSettings . AllKeys . Contains ( propertyName ) )
132
- {
133
- propValue = ConfigurationManager . AppSettings [ propertyName ] ;
134
- }
133
+ lock ( mutex ) {
134
+ if ( ! string . IsNullOrEmpty ( ConfigurationManager . AppSettings . Get ( propertyName ) ) )
135
+ {
136
+ propValue = ConfigurationManager . AppSettings . Get ( propertyName ) ;
137
+ }
138
+ }
135
139
136
140
var envValue = System . Environment . GetEnvironmentVariable ( propertyName ) ;
137
- if ( null != propValue && propValue . Trim ( ) . Length > 0 )
138
- {
139
- stringValue = propValue ;
140
- }
141
- else if ( null != envValue && envValue . Trim ( ) . Length > 0 )
142
- {
143
- stringValue = envValue ;
144
- }
145
- return stringValue ;
146
- }
141
+ if ( null != propValue && propValue . Trim ( ) . Length > 0 )
142
+ {
143
+ stringValue = propValue ;
144
+ }
145
+ else if ( null != envValue && envValue . Trim ( ) . Length > 0 )
146
+ {
147
+ stringValue = envValue ;
148
+ }
149
+ return stringValue ;
150
+ }
147
151
}
148
152
}
0 commit comments