-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from oscaro/feature/variable-config
Allow altering config values based on request
- Loading branch information
Showing
9 changed files
with
244 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.conf import settings | ||
from django.utils.module_loading import import_string | ||
|
||
|
||
def get_config(): | ||
""" | ||
Returns an instance of the configured config class. | ||
""" | ||
|
||
try: | ||
config_class_string = settings.ADYEN_CONFIG_CLASS | ||
except AttributeError: | ||
config_class_string = 'adyen.settings_config.FromSettingsConfig' | ||
return import_string(config_class_string)() | ||
|
||
|
||
class AbstractAdyenConfig: | ||
""" | ||
The base implementation for a config class. | ||
""" | ||
|
||
def get_identifier(self, request): | ||
raise NotImplementedError | ||
|
||
def get_action_url(self, request): | ||
raise NotImplementedError | ||
|
||
def get_skin_code(self, request): | ||
raise NotImplementedError | ||
|
||
def get_skin_secret(self, request): | ||
raise NotImplementedError | ||
|
||
def get_ip_address_header(self): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from .config import AbstractAdyenConfig | ||
|
||
|
||
class FromSettingsConfig(AbstractAdyenConfig): | ||
""" | ||
This config class is enabled by default and useful in simple deployments. | ||
One can just set all needed values in the Django settings. It also | ||
exists for backwards-compatibility with previous deployments. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
We complain as early as possible when Django settings are missing. | ||
""" | ||
required_settings = [ | ||
'ADYEN_IDENTIFIER', 'ADYEN_ACTION_URL', 'ADYEN_SKIN_CODE', 'ADYEN_SECRET_KEY'] | ||
missing_settings = [ | ||
setting for setting in required_settings if not hasattr(settings, setting)] | ||
if missing_settings: | ||
raise ImproperlyConfigured( | ||
"You are using the FromSettingsConfig config class, but haven't set the " | ||
"the following required settings: %s" % missing_settings) | ||
|
||
def get_identifier(self, request): | ||
return settings.ADYEN_IDENTIFIER | ||
|
||
def get_action_url(self, request): | ||
return settings.ADYEN_ACTION_URL | ||
|
||
def get_skin_code(self, request): | ||
return settings.ADYEN_SKIN_CODE | ||
|
||
def get_skin_secret(self, request): | ||
return settings.ADYEN_SECRET_KEY | ||
|
||
def get_ip_address_header(self): | ||
try: | ||
return settings.ADYEN_IP_ADDRESS_HTTP_HEADER | ||
except AttributeError: | ||
return 'REMOTE_ADDR' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
bleach==1.4 | ||
iptools==0.6.1 | ||
requests>=2.0.0,<3.0 | ||
freezegun==0.1.18 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.