Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding PayPalAPIResponseError, for errors coming back from PayPal.

  • Loading branch information...
commit f09ad8e142d670277c32c7923714c3d488ab8270 1 parent 14a8955
@gtaylor gtaylor authored committed
View
2  paypal/__init__.py
@@ -1,4 +1,4 @@
# coding=utf-8
from interface import PayPalInterface
from settings import PayPalConfig
-from exceptions import PayPalError
+from exceptions import PayPalError, PayPalConfigError
View
13 paypal/exceptions.py
@@ -18,3 +18,16 @@ class PayPalError(Error):
Used to denote some kind of generic error.
"""
pass
+
+
+class PayPalConfigError(Error):
+ """
+ Raised when a configuration problem arises.
+ """
+ pass
+
+class PayPalAPIResponseError(Error):
+ """
+ Raised when there is an error coming back with a PayPal NVP API response.
+ """
+ pass
View
4 paypal/interface.py
@@ -13,7 +13,7 @@
from settings import PayPalConfig
from response import PayPalResponse
-from exceptions import PayPalError
+from exceptions import PayPalError, PayPalAPIResponseError
class PayPalInterface(object):
"""
@@ -113,7 +113,7 @@ def _call(self, method, **kwargs):
if not response.success:
if self.config.DEBUG_LEVEL >= 1:
print response
- raise PayPalError(response)
+ raise PayPalAPIResponseError(response)
return response
View
8 paypal/settings.py
@@ -5,7 +5,7 @@
is instantiated by the PayPalInterface object.
"""
-from exceptions import *
+from exceptions import PayPalConfigError, PayPalError
class PayPalConfig(object):
"""
@@ -84,14 +84,14 @@ def __init__(self, **kwargs):
kwargs['API_ENVIRONMENT']= self.API_ENVIRONMENT
# Make sure the environment is one of the acceptable values.
if kwargs['API_ENVIRONMENT'] not in self._valid_['API_ENVIRONMENT']:
- raise PayPalError('Invalid API_ENVIRONMENT')
+ raise PayPalConfigError('Invalid API_ENVIRONMENT')
self.API_ENVIRONMENT = kwargs['API_ENVIRONMENT']
if 'API_AUTHENTICATION_MODE' not in kwargs:
kwargs['API_AUTHENTICATION_MODE']= self.API_AUTHENTICATION_MODE
# Make sure the auth mode is one of the known/implemented methods.
if kwargs['API_AUTHENTICATION_MODE'] not in self._valid_['API_AUTHENTICATION_MODE']:
- raise PayPalError("Not a supported auth mode. Use one of: %s" % \
+ raise PayPalConfigError("Not a supported auth mode. Use one of: %s" % \
", ".join(self._valid_['API_AUTHENTICATION_MODE']))
# Set the API endpoints, which is a cheesy way of saying API servers.
@@ -102,7 +102,7 @@ def __init__(self, **kwargs):
if self.API_AUTHENTICATION_MODE == '3TOKEN':
for arg in ('API_USERNAME','API_PASSWORD','API_SIGNATURE'):
if arg not in kwargs:
- raise PayPalError('Missing in PayPalConfig: %s ' % arg)
+ raise PayPalConfigError('Missing in PayPalConfig: %s ' % arg)
setattr(self, arg, kwargs[arg])
for arg in ('HTTP_TIMEOUT' , 'DEBUG_LEVEL' , 'RESPONSE_KEYERROR'):
Please sign in to comment.
Something went wrong with that request. Please try again.