99import sys
1010import xml .dom .minidom
1111from pip ._vendor import requests
12- from _pyio import __metaclass__
1312from lxml import objectify
1413
1514from authorizenet .constants import constants
@@ -87,8 +86,11 @@ def validate(self):
8786 self .validateandsetmerchantauthentication ()
8887 self .validaterequest ()
8988
90- return
91-
89+ return
90+
91+ def setClientId (self ): #protected method
92+ self ._request .clientId = constants .clientId
93+
9294 def _getrequest (self ): #protected method
9395 return self ._request
9496
@@ -97,9 +99,9 @@ def buildrequest(self):
9799
98100 xmlRequest = self ._request .toxml (encoding = constants .xml_encoding , element_name = self .getrequesttype ())
99101 #remove namespaces that toxml() generates
100- xmlRequest = xmlRequest .replace (constants .nsNamespace1 , '' )
101- xmlRequest = xmlRequest .replace (constants .nsNamespace2 , '' )
102-
102+ xmlRequest = xmlRequest .replace (constants .nsNamespace1 , b '' )
103+ xmlRequest = xmlRequest .replace (constants .nsNamespace2 , b '' )
104+
103105 return xmlRequest
104106
105107 def getprettyxmlrequest (self ):
@@ -123,6 +125,7 @@ def execute(self):
123125
124126 #requests is http request
125127 try :
128+ self .setClientId ()
126129 xmlRequest = self .buildrequest ()
127130 self ._httpResponse = requests .post (self .endpoint , data = xmlRequest , headers = constants .headers , proxies = proxyDictionary )
128131 except Exception as httpException :
@@ -138,8 +141,8 @@ def execute(self):
138141 self ._response = apicontractsv1 .CreateFromDocument (self ._httpResponse )
139142 #objectify code
140143 xmlResponse = self ._response .toxml (encoding = constants .xml_encoding , element_name = self .getrequesttype ())
141- xmlResponse = xmlResponse .replace (constants .nsNamespace1 , '' )
142- xmlResponse = xmlResponse .replace (constants .nsNamespace2 , '' )
144+ xmlResponse = xmlResponse .replace (constants .nsNamespace1 , b '' )
145+ xmlResponse = xmlResponse .replace (constants .nsNamespace2 , b '' )
143146 self ._mainObject = objectify .fromstring (xmlResponse )
144147
145148 except Exception as objectifyexception :
@@ -148,21 +151,21 @@ def execute(self):
148151 self ._response = apicontractsv1 .CreateFromDocument (self ._httpResponse )
149152 #objectify code
150153 xmlResponse = self ._response .toxml (encoding = constants .xml_encoding , element_name = self .getrequesttype ())
151- xmlResponse = xmlResponse .replace (constants .nsNamespace1 , '' )
152- xmlResponse = xmlResponse .replace (constants .nsNamespace2 , '' )
154+ xmlResponse = xmlResponse .replace (constants .nsNamespace1 , b '' )
155+ xmlResponse = xmlResponse .replace (constants .nsNamespace2 , b '' )
153156 self ._mainObject = objectify .fromstring (xmlResponse )
154157 else :
155158 #if type(self.getresponseclass()) == type(self._response):
156159 if type (self .getresponseclass ()) != type (self ._mainObject ):
157160 if self ._response .messages .resultCode == "Error" :
158- print "Response error"
161+ logging . debug ( "Response error" )
159162 domResponse = xml .dom .minidom .parseString (self ._httpResponse )
160163 logging .debug ('Received response: %s' % domResponse .toprettyxml ())
161164 else :
162165 #Need to handle ErrorResponse
163166 logging .debug ('Error retrieving response for request: %s' % self ._request )
164167 else :
165- print "Did not receive http response"
168+ logging . debug ( "Did not receive http response" )
166169 return
167170
168171 def getresponse (self ):
0 commit comments