Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions authorizenet/apicontrollersbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import pyxb
import sys
import threading
import xml.dom.minidom
import requests
from lxml import objectify
Expand Down Expand Up @@ -75,6 +76,7 @@ class APIOperationBase(APIOperationBaseInterface):

__metaclass__ = abc.ABCMeta
__initialized = False
__environment_lock = threading.Lock()
__merchantauthentication = "null"
__environment = "null"

Expand Down Expand Up @@ -118,7 +120,12 @@ def getprettyxmlrequest(self):

def execute(self):

self.endpoint = APIOperationBase.__environment
# Read environment at execute time with lock to ensure consistency
with APIOperationBase.__environment_lock:
# Initialize class environment to SANDBOX if not already set
if APIOperationBase.__environment == "null":
APIOperationBase.__environment = constants.SANDBOX
self.endpoint = APIOperationBase.__environment

anetLogger.debug('Executing http post to url: %s', self.endpoint)

Expand Down Expand Up @@ -193,8 +200,8 @@ def beforeexecute(self):
return

@staticmethod
def getmerchantauthentication(self):
return self.__merchantauthentication
def getmerchantauthentication():
return APIOperationBase.__merchantauthentication

@staticmethod
def setmerchantauthentication(merchantauthentication):
Expand All @@ -204,20 +211,22 @@ def setmerchantauthentication(merchantauthentication):
def validateandsetmerchantauthentication(self):
anetapirequest = apicontractsv1.ANetApiRequest()
if (anetapirequest.merchantAuthentication == "null"):
if (self.getmerchantauthentication() != "null"):
anetapirequest.merchantAuthentication = self.getmerchantauthentication()
if (APIOperationBase.getmerchantauthentication() != "null"):
anetapirequest.merchantAuthentication = APIOperationBase.getmerchantauthentication()
else:
raise ValueError('Merchant Authentication can not be null')
return

@staticmethod
def getenvironment(self):
return APIOperationBase.__environment
def getenvironment():
with APIOperationBase.__environment_lock:
return APIOperationBase.__environment


@staticmethod
def setenvironment(userenvironment):
APIOperationBase.__environment = userenvironment
with APIOperationBase.__environment_lock:
APIOperationBase.__environment = userenvironment
return

def __init__(self, apiRequest):
Expand All @@ -233,9 +242,8 @@ def __init__(self, apiRequest):
raise ValueError('Input request cannot be null')

self._request = apiRequest
__merchantauthentication = apicontractsv1.merchantAuthenticationType()
APIOperationBase.__environment = constants.SANDBOX

__merchantauthentication = apicontractsv1.merchantAuthenticationType()
APIOperationBase.setmerchantauthentication(__merchantauthentication)
self.validate()

Expand Down