diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index d27773a..5192e02 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -69,6 +69,7 @@ class APIOperationBase(APIOperationBaseInterface): __initialized = False __merchantauthentication = "null" + __environment = "null" @staticmethod def __classinitialized(): @@ -80,22 +81,7 @@ def validaterequest(self): def validate(self): anetapirequest = self._getrequest() - - self.validateandsetmerchantauthentication() - ''' - # make sure proper authentication elements are present and no extra elements are present - merchantauthenticationtype = anetapirequest.merchantauthentication() - if (merchantauthenticationtype.sessionToken != "null"): - raise ValueError('sessionToken needs to be null') - if (merchantauthenticationtype.password != "null"): - raise ValueError('Password needs to be null') - if (merchantauthenticationtype.mobileDeviceId != "null"): - raise ValueError('MobileDeviceId needs to be null') - - impersonationauthenticationtype = merchantauthenticationtype.impersonationAuthentication - if (impersonationauthenticationtype != "null"): - raise ValueError('ImpersonationAuthenticationType needs to be null') - ''' + self.validateandsetmerchantauthentication() self.validaterequest() return @@ -121,7 +107,9 @@ def getprettyxmlrequest(self): return requestDom def execute(self): - self.endpoint = constants.SANDBOX_TESTMODE + + self.endpoint = APIOperationBase.__environment + logging.debug('Executing http post to url: %s', self.endpoint) self.beforeexecute() @@ -201,18 +189,28 @@ def validateandsetmerchantauthentication(self): else: raise ValueError('Merchant Authentication can not be null') return - - def __init__(self, apiRequest): - self._httpResponse = "null" - self._request = "null" - self._response = "null" - self.__endpoint = "null" + + @staticmethod + def getenvironment(self): + return APIOperationBase.__environment - if "null" == apiRequest: + + @staticmethod + def setenvironment(userenvironment): + APIOperationBase.__environment = userenvironment + return + + def __init__(self, apiRequest): + self._httpResponse = None + self._request = None + self._response = None + + if None == apiRequest: raise ValueError('Input request cannot be null') self._request = apiRequest __merchantauthentication = apicontractsv1.merchantAuthenticationType() + APIOperationBase.__environment = constants.SANDBOX_TESTMODE APIOperationBase.setmerchantauthentication(__merchantauthentication) @@ -220,9 +218,9 @@ def __init__(self, apiRequest): loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) - if ("null" == loggingfilename): + if (None == loggingfilename): loggingfilename = constants.defaultLogFileName - if ("null" == logginglevel): + if (None == logginglevel): logginglevel = constants.defaultLoggingLevel logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) diff --git a/authorizenet/constants.py b/authorizenet/constants.py index a4fdb23..927d937 100644 --- a/authorizenet/constants.py +++ b/authorizenet/constants.py @@ -13,7 +13,7 @@ class constants(object): '''Environments''' SANDBOX_TESTMODE = 'https://apitest.authorize.net/xml/v1/request.api' - PRODUCTION = 'https://api.authorize.net/xml/v1/request.api' + PRODUCTION = 'https://api2.authorize.net/xml/v1/request.api' '''xml encoding''' xml_encoding = 'utf-8' diff --git a/tests/testssample.py b/tests/testssample.py index 263eae0..43363f0 100644 --- a/tests/testssample.py +++ b/tests/testssample.py @@ -4,6 +4,7 @@ @author: krgupta ''' from authorizenet import apicontractsv1 +from authorizenet import constants from decimal import * from authorizenet.apicontractsv1 import CTD_ANON #from controller.CreateTransactionController import CreateTransactionController @@ -20,6 +21,7 @@ from authorizenet.apicontrollers import * import test from authorizenet import utility +from authorizenet.apicontrollersbase import APIOperationBase class test_ReadProperty(apitestbase.ApiTestBase): def testPropertyFromFile(self): @@ -27,9 +29,8 @@ def testPropertyFromFile(self): transactionkey = utility.helper.getproperty("transaction_key") self.assertIsNotNone(login) self.assertIsNotNone(transactionkey) - + class test_TransactionReportingUnitTest(apitestbase.ApiTestBase): - def testGetTransactionDetails(self): gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest() @@ -38,8 +39,8 @@ def testGetTransactionDetails(self): gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest) gettransactiondetailscontroller.execute() response = gettransactiondetailscontroller.getresponse() - self.assertEquals('Ok', response.messages.resultCode) - + self.assertEquals('Ok', response.messages.resultCode) + class test_RecurringBillingTest(apitestbase.ApiTestBase): def testCreateSubscription(self): @@ -120,6 +121,41 @@ def testauthOnlyContinueTransaction(self): response = createtransactioncontroller.getresponse() self.assertIsNotNone(response.transactionResponse) self.assertIsNotNone(response.transactionResponse.transId) - + +''' +class test_ProductionURL(apitestbase.ApiTestBase): + '' '' ''Tests will run only with production credentials + '' '' '' + + def testGetSettledBatchList(self): + settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() + settledBatchListRequest.merchantAuthentication = self.merchantAuthentication + settledBatchListController = getSettledBatchListController(settledBatchListRequest) + customEndpoint = constants.PRODUCTION + apicontrollersbase.APIOperationBase.setenvironment(customEndpoint) + settledBatchListController.execute() + response = settledBatchListController.getresponse() + self.assertEquals('Ok', response.messages.resultCode) + + def testGetListofSubscriptions(self): + sorting = apicontractsv1.ARBGetSubscriptionListSorting() + sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id + sorting.orderDescending = "false" + paging = apicontractsv1.Paging() + paging.limit = 1000 + paging.offset = 1 + GetListofSubscriptionRequest = apicontractsv1.ARBGetSubscriptionListRequest() + GetListofSubscriptionRequest.merchantAuthentication = self.merchantAuthentication + GetListofSubscriptionRequest.refId = "Sample" + GetListofSubscriptionRequest.searchType = apicontractsv1.ARBGetSubscriptionListSearchTypeEnum.subscriptionInactive + GetListofSubscriptionRequest.sorting = sorting + GetListofSubscriptionRequest.paging = paging + arbgetsubscriptionlistcontroller = ARBGetSubscriptionListController(GetListofSubscriptionRequest) + customEndpoint = constants.PRODUCTION + apicontrollersbase.APIOperationBase.setenvironment(customEndpoint) + arbgetsubscriptionlistcontroller.execute() + response = arbgetsubscriptionlistcontroller.getresponse() + self.assertEquals('Ok', response.messages.resultCode) +''' if __name__ =='__main__': unittest.main()