Exemple #1
0
    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
Exemple #2
0
 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, service, *args):
     # Provides standard API call error handling
     method = getattr(self.client.service, service)
     try:
         response = method(self.client_auth, *args)
     except (WebFault, SSLError) as e:
         raise AuthorizeConnectionError(e)
     if response.resultCode != 'Ok':
         error = response.messages[0][0]
         raise AuthorizeResponseError('%s: %s' % (error.code, error.text))
     return response
 def _make_call(self, params):
     params = urllib.urlencode(params)
     url = '{0}?{1}'.format(self.url, params)
     try:
         response = urllib.urlopen(url).read()
     except IOError as e:
         raise AuthorizeConnectionError(e)
     fields = parse_response(response)
     if fields['response_code'] != '1':
         e = AuthorizeResponseError(fields['response_reason_text'])
         e.full_response = fields
         raise e
     return fields
 def _make_call(self, service, *args):
     # Provides standard API call error handling
     method = getattr(self.client.service, service)
     try:
         response = method(self.client_auth, *args)
     except WebFault as e:
         raise AuthorizeConnectionError('Error contacting SOAP API.')
     if response.resultCode != 'Ok':
         error = response.messages[0][0]
         e = AuthorizeResponseError('%s: %s' % (error.code, error.text))
         e.full_response = {
             'response_code': error.code,
             'response_text': error.text,
         }
         raise e
     return response
Exemple #6
0
 def _make_call(self, params):
     params = convert_params_to_byte_str(params)
     params = urlencode(params)
     try:
         resource = urlopen(self.url, data=b(params))
         response = resource.read().decode(
             get_content_charset(resource) or DEFAULT_CHARSET)
     except IOError as e:
         raise AuthorizeConnectionError(e)
     fields = parse_response(response)
     if fields['response_code'] != '1':
         e = AuthorizeResponseError('{0} full_response={1!r}'.format(
             fields['response_reason_text'], fields))
         e.full_response = fields
         raise e
     return fields
Exemple #7
0
    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