diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index 336b86a..d27773a 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -6,8 +6,6 @@ import abc import logging import xml.dom.minidom -import ConfigParser -from ConfigParser import SafeConfigParser from pip._vendor import requests from _pyio import __metaclass__ @@ -69,7 +67,7 @@ def beforeexecute(self): class APIOperationBase(APIOperationBaseInterface): __metaclass__ = abc.ABCMeta - __initialized = "False" + __initialized = False __merchantauthentication = "null" @staticmethod @@ -83,7 +81,7 @@ def validaterequest(self): def validate(self): anetapirequest = self._getrequest() - #self.validateandsetmerchantauthentication() + self.validateandsetmerchantauthentication() ''' # make sure proper authentication elements are present and no extra elements are present merchantauthenticationtype = anetapirequest.merchantauthentication() @@ -197,9 +195,9 @@ def setmerchantauthentication(merchantauthentication): def validateandsetmerchantauthentication(self): anetapirequest = apicontractsv1.ANetApiRequest() - if (anetapirequest.getmerchantauthentication() == "null"): + if (anetapirequest.merchantAuthentication == "null"): if (self.getmerchantauthentication() != "null"): - anetapirequest.setmerchantauthentication(self.getmerchantauthentication()) + anetapirequest.merchantAuthentication = self.getmerchantauthentication() else: raise ValueError('Merchant Authentication can not be null') return @@ -218,12 +216,9 @@ def __init__(self, apiRequest): APIOperationBase.setmerchantauthentication(__merchantauthentication) - if ( 'False' == APIOperationBase.__classinitialized()): - loggingfilename = utility.helper.getpropertyfile() - logginglevel = utility.helper.getproperty("executionlogginglevel") - - #print ("logging level %s" %logginglevel) - + if ( False == APIOperationBase.__classinitialized()): + loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) + logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) if ("null" == loggingfilename): loggingfilename = constants.defaultLogFileName @@ -231,7 +226,7 @@ def __init__(self, apiRequest): logginglevel = constants.defaultLoggingLevel logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) - __initialized = "True" + __initialized = True self.validate() diff --git a/authorizenet/constants.py b/authorizenet/constants.py index 15b4d21..a4fdb23 100644 --- a/authorizenet/constants.py +++ b/authorizenet/constants.py @@ -52,5 +52,10 @@ class constants(object): '''default log format''' defaultlogformat = '%(asctime)s %(message)s' + + propertiesloggingfilename = "loggingfilename" + + propertiesexecutionlogginglevel = "executionlogginglevel" + '''eof''' diff --git a/authorizenet/utility.py b/authorizenet/utility.py index f2b90e7..4a4fcb1 100644 --- a/authorizenet/utility.py +++ b/authorizenet/utility.py @@ -12,25 +12,25 @@ #from authorizenet.constants import constants class helper(): - __parser = SafeConfigParser({"http":"","https":"","ftp":""}) + __parser = "null" __propertyfilename = "null" - __initialized = 'False' + __initialized = False - @staticmethod - def getpropertyfile(): - return helper.__propertyfilename - @staticmethod def getparser(): return helper.__parser + @staticmethod + def getpropertyfile(): + return helper.__propertyfilename + @staticmethod def setpropertyfile(propertyfilename): - if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == 'False'): - raise ValueError('properties '%propertyfilename%' file not found') - - helper.__propertyfilename = propertyfilename + if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False): + helper.__propertyfilename = 'null' + else: + helper.__propertyfilename = propertyfilename return @staticmethod @@ -39,26 +39,23 @@ def __classinitialized(): @staticmethod def getproperty(propertyname): - - if ( 'False' == helper.__classinitialized()): - helper.getparser().read(helper.__propertyfilename) - __initialized = 'True' - stringvalue = "null" - if ("null" != helper.getparser()): - try: - stringvalue = helper.getparser().get("properties", propertyname) - except NoSectionError as nse: - print (" properties section does not exist") - stringvalue = "" - - else : - print (" property file does not exist, will read from environment") - stringvalue = os.getenv[propertyname] - - return stringvalue - - @staticmethod - def setproperty(propertyname): - helper.getparser().add_option("properties", propertyname) - return + temp = propertyname + if ('null' != helper.getpropertyfile()): + helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""}) + if ('null' != helper.getparser()): + try: + if ( False == helper.__classinitialized()): + helper.getparser().read(helper.__propertyfilename) + __initialized = True + except: + print ("helper class not initialized") + if (__initialized == True): + print (" Reading %s from property file %s" % (propertyname, helper.__propertyfilename)) + stringvalue = helper.getparser().get("properties", propertyname) + + if ( "null" == stringvalue): + print (" Reading %s from environment" %propertyname) + stringvalue = os.getenv(temp) + print (" Read propertyvalue %s from environment" %stringvalue) + return stringvalue \ No newline at end of file diff --git a/tests/anet_python_sdk_properties.ini b/tests/anet_python_sdk_properties.ini deleted file mode 100644 index 9f88ed9..0000000 --- a/tests/anet_python_sdk_properties.ini +++ /dev/null @@ -1,20 +0,0 @@ -[properties] - -#sandbox cradentials -api_login_id : 5KP3u95bQpv -transaction_key : 4Ktq966gC55GAX7S -md5.hash.key : MD5_HASH_KEY - -#log -logfilename : logFile.log - -#proxy setup -http://internet.visa.com:80 -https://internet.visa.com:443 - -#environments -sandbox : https://apitest.authorize.net/xml/v1/request.api -production : https://api.authorize.net/xml/v1/request.api - -#level -executionlogginglevel : WARNING diff --git a/tests/apitestbase.py b/tests/apitestbase.py index 6bb1e20..94f1080 100644 --- a/tests/apitestbase.py +++ b/tests/apitestbase.py @@ -19,7 +19,7 @@ class ApiTestBase(unittest.TestCase): def setUp(self): - utility.helper.setpropertyfile( 'anet_python_sdk_properties.ini') + utility.helper.setpropertyfile('anet_python_sdk_properties.ini') self.amount = str(round(random.random()*100, 2))
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: