Skip to content

Commit 1dc6335

Browse files
committed
Merge pull request AuthorizeNet#26 from krgupta1/master
Providing set method to user to allow them to point to the sandbox or production env
2 parents 56dc055 + e8ffde4 commit 1dc6335

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

authorizenet/apicontrollersbase.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class APIOperationBase(APIOperationBaseInterface):
6969

7070
__initialized = False
7171
__merchantauthentication = "null"
72+
__environment = "null"
7273

7374
@staticmethod
7475
def __classinitialized():
@@ -80,22 +81,7 @@ def validaterequest(self):
8081

8182
def validate(self):
8283
anetapirequest = self._getrequest()
83-
84-
self.validateandsetmerchantauthentication()
85-
'''
86-
# make sure proper authentication elements are present and no extra elements are present
87-
merchantauthenticationtype = anetapirequest.merchantauthentication()
88-
if (merchantauthenticationtype.sessionToken != "null"):
89-
raise ValueError('sessionToken needs to be null')
90-
if (merchantauthenticationtype.password != "null"):
91-
raise ValueError('Password needs to be null')
92-
if (merchantauthenticationtype.mobileDeviceId != "null"):
93-
raise ValueError('MobileDeviceId needs to be null')
94-
95-
impersonationauthenticationtype = merchantauthenticationtype.impersonationAuthentication
96-
if (impersonationauthenticationtype != "null"):
97-
raise ValueError('ImpersonationAuthenticationType needs to be null')
98-
'''
84+
self.validateandsetmerchantauthentication()
9985
self.validaterequest()
10086

10187
return
@@ -121,7 +107,9 @@ def getprettyxmlrequest(self):
121107
return requestDom
122108

123109
def execute(self):
124-
self.endpoint = constants.SANDBOX_TESTMODE
110+
111+
self.endpoint = APIOperationBase.__environment
112+
125113
logging.debug('Executing http post to url: %s', self.endpoint)
126114

127115
self.beforeexecute()
@@ -201,28 +189,38 @@ def validateandsetmerchantauthentication(self):
201189
else:
202190
raise ValueError('Merchant Authentication can not be null')
203191
return
204-
205-
def __init__(self, apiRequest):
206-
self._httpResponse = "null"
207-
self._request = "null"
208-
self._response = "null"
209-
self.__endpoint = "null"
192+
193+
@staticmethod
194+
def getenvironment(self):
195+
return APIOperationBase.__environment
210196

211-
if "null" == apiRequest:
197+
198+
@staticmethod
199+
def setenvironment(userenvironment):
200+
APIOperationBase.__environment = userenvironment
201+
return
202+
203+
def __init__(self, apiRequest):
204+
self._httpResponse = None
205+
self._request = None
206+
self._response = None
207+
208+
if None == apiRequest:
212209
raise ValueError('Input request cannot be null')
213210

214211
self._request = apiRequest
215212
__merchantauthentication = apicontractsv1.merchantAuthenticationType()
213+
APIOperationBase.__environment = constants.SANDBOX_TESTMODE
216214

217215
APIOperationBase.setmerchantauthentication(__merchantauthentication)
218216

219217
if ( False == APIOperationBase.__classinitialized()):
220218
loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename)
221219
logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel)
222220

223-
if ("null" == loggingfilename):
221+
if (None == loggingfilename):
224222
loggingfilename = constants.defaultLogFileName
225-
if ("null" == logginglevel):
223+
if (None == logginglevel):
226224
logginglevel = constants.defaultLoggingLevel
227225

228226
logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)

authorizenet/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class constants(object):
1313

1414
'''Environments'''
1515
SANDBOX_TESTMODE = 'https://apitest.authorize.net/xml/v1/request.api'
16-
PRODUCTION = 'https://api.authorize.net/xml/v1/request.api'
16+
PRODUCTION = 'https://api2.authorize.net/xml/v1/request.api'
1717

1818
'''xml encoding'''
1919
xml_encoding = 'utf-8'

tests/testssample.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@author: krgupta
55
'''
66
from authorizenet import apicontractsv1
7+
from authorizenet import constants
78
from decimal import *
89
from authorizenet.apicontractsv1 import CTD_ANON
910
#from controller.CreateTransactionController import CreateTransactionController
@@ -20,16 +21,16 @@
2021
from authorizenet.apicontrollers import *
2122
import test
2223
from authorizenet import utility
24+
from authorizenet.apicontrollersbase import APIOperationBase
2325

2426
class test_ReadProperty(apitestbase.ApiTestBase):
2527
def testPropertyFromFile(self):
2628
login= utility.helper.getproperty("api_login_id")
2729
transactionkey = utility.helper.getproperty("transaction_key")
2830
self.assertIsNotNone(login)
2931
self.assertIsNotNone(transactionkey)
30-
32+
3133
class test_TransactionReportingUnitTest(apitestbase.ApiTestBase):
32-
3334
def testGetTransactionDetails(self):
3435

3536
gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest()
@@ -38,8 +39,8 @@ def testGetTransactionDetails(self):
3839
gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest)
3940
gettransactiondetailscontroller.execute()
4041
response = gettransactiondetailscontroller.getresponse()
41-
self.assertEquals('Ok', response.messages.resultCode)
42-
42+
self.assertEquals('Ok', response.messages.resultCode)
43+
4344
class test_RecurringBillingTest(apitestbase.ApiTestBase):
4445

4546
def testCreateSubscription(self):
@@ -120,6 +121,41 @@ def testauthOnlyContinueTransaction(self):
120121
response = createtransactioncontroller.getresponse()
121122
self.assertIsNotNone(response.transactionResponse)
122123
self.assertIsNotNone(response.transactionResponse.transId)
123-
124+
125+
'''
126+
class test_ProductionURL(apitestbase.ApiTestBase):
127+
'' '' ''Tests will run only with production credentials
128+
'' '' ''
129+
130+
def testGetSettledBatchList(self):
131+
settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
132+
settledBatchListRequest.merchantAuthentication = self.merchantAuthentication
133+
settledBatchListController = getSettledBatchListController(settledBatchListRequest)
134+
customEndpoint = constants.PRODUCTION
135+
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
136+
settledBatchListController.execute()
137+
response = settledBatchListController.getresponse()
138+
self.assertEquals('Ok', response.messages.resultCode)
139+
140+
def testGetListofSubscriptions(self):
141+
sorting = apicontractsv1.ARBGetSubscriptionListSorting()
142+
sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id
143+
sorting.orderDescending = "false"
144+
paging = apicontractsv1.Paging()
145+
paging.limit = 1000
146+
paging.offset = 1
147+
GetListofSubscriptionRequest = apicontractsv1.ARBGetSubscriptionListRequest()
148+
GetListofSubscriptionRequest.merchantAuthentication = self.merchantAuthentication
149+
GetListofSubscriptionRequest.refId = "Sample"
150+
GetListofSubscriptionRequest.searchType = apicontractsv1.ARBGetSubscriptionListSearchTypeEnum.subscriptionInactive
151+
GetListofSubscriptionRequest.sorting = sorting
152+
GetListofSubscriptionRequest.paging = paging
153+
arbgetsubscriptionlistcontroller = ARBGetSubscriptionListController(GetListofSubscriptionRequest)
154+
customEndpoint = constants.PRODUCTION
155+
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
156+
arbgetsubscriptionlistcontroller.execute()
157+
response = arbgetsubscriptionlistcontroller.getresponse()
158+
self.assertEquals('Ok', response.messages.resultCode)
159+
'''
124160
if __name__ =='__main__':
125161
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy