def _make_call(self, call): """Make a call to the Authorize.net server with the XML.""" try: request = urllib2.Request(self.config.environment, E.tostring(call)) request.add_header('Content-Type', 'text/xml') response = urllib2.urlopen(request).read() response = E.fromstring(response) result = parse_response(response) except urllib2.HTTPError: raise AuthorizeConnectionError('Error processing XML request.') # Throw an exception for invalid calls. This makes error handling easier. if result.messages[0].result_code != 'Ok': error = result.messages[0].message e = AuthorizeResponseError('%s: %s' % (error.code, error.text)) e.full_response = result raise e # Exception handling for transaction response errors. try: error = result.transaction_response.errors[0] e = AuthorizeResponseError('Response code %s: %s' % (error.error_code, error.error_text)) e.full_response = result raise e except KeyError: pass return result
def _make_call(self, call): """Make a call to the Authorize.net server with the XML.""" try: request = urllib2.Request(self.config.environment, E.tostring(call)) request.add_header('Content-Type', 'text/xml') response = urllib2.urlopen(request).read() response = E.fromstring(response) result = parse_response(response) except HTTPError, e: return AuthorizeConnectionError('Error processing XML request.')
def _make_call(self, call): """Make a call to the Authorize.net server with the XML.""" try: request = urllib2.Request(self.config.environment, E.tostring(call)) request.add_header('Content-Type', 'text/xml') response = urllib2.urlopen(request).read() response = E.fromstring(response) response_json = parse_response(response) except urllib2.HTTPError: raise AuthorizeConnectionError('Error processing XML request.') # Exception handling for transaction response errors. try: error = response_json.transaction_response.errors[0] raise AuthorizeResponseError(error.error_code, error.error_text, response_json) except (KeyError, AttributeError): # Attempt to access transaction response errors pass # Throw an exception for invalid calls. This makes error handling easier. if response_json.messages[0].result_code != 'Ok': error = response_json.messages[0].message raise AuthorizeResponseError(error.code, error.text, response_json) return response_json
def test_parse_transaction_list(self): response_element = E.fromstring(TRANSACTION_LIST_RESPONSE_XML.strip()) response = parse_response(response_element) self.assertEquals(TRANSACTION_LIST_RESPONSE, response)
def test_parse_direct_resonse(self): response_element = E.fromstring(DIRECT_RESPONSE_XML.strip()) response = parse_response(response_element) self.assertEquals(TRANSACTION_RESPONSE, response)
def test_parse_numeric_string_response(self): response_element = E.fromstring(NUMERIC_STRING_LIST_RESPONSE_XML.strip()) response = parse_response(response_element) self.assertEquals(NUMERIC_STRING_LIST_RESPONSE, response['payment_ids'])
def test_parse_multiple_line_item_response(self): response_element = E.fromstring(MULTIPLE_LIST_ITEM_RESPONSE_XML.strip()) response = parse_response(response_element) self.assertEquals(MULTIPLE_LIST_ITEM_RESPONSE, response)