Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SHA256 support, to work with newer Adyen merchant accounts. #24

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
max_line_length = 100

[*.rst]
indent_size = 2
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Edit your ``settings.py`` to set the following settings:
(e.g. 'https://test.adyen.com/hpp/select.shtml').
* ``ADYEN_IP_ADDRESS_HTTP_HEADER`` - Optional. The header in `META` to inspect to determine
the IP address of the request. Defaults to `REMOTE_ADDR`.
* ``ADYEN_HMAC_ALGORITHM`` - Optional. The algorithm to use when calculating the HMAC for
the merchant signature. Supports `'SHA1'` and `'SHA256'`. Defaults to `'SHA1'`.

You will likely need to specify different settings in your test environment
as opposed to your production environment.
Expand Down
7 changes: 7 additions & 0 deletions adyen/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.conf import settings
from django.utils.module_loading import import_string

# Defines the accepted algorithms. Subclasses should verify that values for ADYEN_HMAC_ALGORITHM
# are contained in this list.
HMAC_ALGORITHMS = ('SHA1', 'SHA256')


def get_config():
"""
Expand Down Expand Up @@ -33,3 +37,6 @@ def get_skin_secret(self, request):

def get_ip_address_header(self):
raise NotImplementedError

def get_hmac_algorithm(self, request):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of the config for that. Good point to keep.

19 changes: 4 additions & 15 deletions adyen/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

from django.http import HttpResponse

from .gateway import Constants, Gateway, PaymentNotification, PaymentRedirection
from .gateway import Constants, Gateway
from .models import AdyenTransaction
from .config import get_config

logger = logging.getLogger('adyen')


def get_gateway(request, config):
return Gateway({
return Gateway(request, {
Constants.IDENTIFIER: config.get_identifier(request),
Constants.SECRET_KEY: config.get_skin_secret(request),
Constants.ACTION_URL: config.get_action_url(request),
Constants.HMAC_ALGORITHM: config.get_hmac_algorithm(request),
})


Expand Down Expand Up @@ -144,20 +145,8 @@ def handle_payment_feedback(self, request):
Validate, process, optionally record audit trail and provide feedback
about the current payment response.
"""
# We must first find out whether this is a redirection or a notification.

if request.method == 'GET':
params = request.GET
response_class = PaymentRedirection
elif request.method == 'POST':
params = request.POST
response_class = PaymentNotification
else:
raise RuntimeError("Only GET and POST requests are supported.")

# Then we can instantiate the appropriate class from the gateway.
gateway = get_gateway(request, self.config)
response = response_class(gateway, params)
response = gateway.get_response()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the idea, but I'm not really happy with the gateway depending on request. I think we need something a bit different and more isolated to solve this issue.


# Note that this may raise an exception if the response is invalid.
# For example: MissingFieldException, UnexpectedFieldException, ...
Expand Down
Loading