From 2abe05d5fa5cae896b8cc36c416729ed4c141474 Mon Sep 17 00:00:00 2001 From: Jorik Kraaikamp Date: Tue, 13 Sep 2022 11:55:16 +0200 Subject: [PATCH 1/7] Updated the version --- .../commands/sync_payment_methods.py | 7 +++++++ djadyen/settings.py | 3 ++- djadyen/templatetags/adyen_tags.py | 8 ++++++++ djadyen/views.py | 18 +++++++++++++++++- setup.cfg | 2 +- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/djadyen/management/commands/sync_payment_methods.py b/djadyen/management/commands/sync_payment_methods.py index 891f3d3..d50fa54 100644 --- a/djadyen/management/commands/sync_payment_methods.py +++ b/djadyen/management/commands/sync_payment_methods.py @@ -38,10 +38,17 @@ class Command(BaseCommand): def handle(self, *args, **options): ady = Adyen.Adyen() + if not settings.DJADYEN_ENVIRONMENT: + assert False, "Please provide an environment." + + if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: + assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT ady.payment.client.xapikey = settings.DJADYEN_SERVER_KEY ady.payment.client.app_name = settings.DJADYEN_APPNAME + ady.payment.client.live_endpoint_prefix = settings.DJADYEN_LIVE_URL_PREFIX # Setting request data. request = { diff --git a/djadyen/settings.py b/djadyen/settings.py index c2ecc3a..eab0e8f 100644 --- a/djadyen/settings.py +++ b/djadyen/settings.py @@ -2,7 +2,7 @@ DJADYEN_SERVER_KEY = getattr(dj_settings, "DJADYEN_SERVER_KEY") DJADYEN_CLIENT_KEY = getattr(dj_settings, "DJADYEN_CLIENT_KEY") -DJADYEN_ENVIRONMENT = getattr(dj_settings, "DJADYEN_ENVIRONMENT", "test") +DJADYEN_ENVIRONMENT = getattr(dj_settings, "DJADYEN_ENVIRONMENT") DJADYEN_APPNAME = getattr(dj_settings, "DJADYEN_APPNAME", "Djadyen Payment") DJADYEN_MERCHANT_ACCOUNT = getattr(dj_settings, "DJADYEN_MERCHANT_ACCOUNT") DJADYEN_CURRENCYCODE = getattr(dj_settings, "DJADYEN_CURRENCYCODE", "EUR") @@ -15,3 +15,4 @@ DJADYEN_DEFAULT_COUNTRY_CODE = getattr( dj_settings, "DJADYEN_DEFAULT_COUNTRY_CODE", "nl" ) +DJADYEN_LIVE_URL_PREFIX = getattr(dj_settings, "DJADYEN_LIVE_URL_PREFIX", None) diff --git a/djadyen/templatetags/adyen_tags.py b/djadyen/templatetags/adyen_tags.py index 97967ec..d5b2e68 100644 --- a/djadyen/templatetags/adyen_tags.py +++ b/djadyen/templatetags/adyen_tags.py @@ -24,10 +24,18 @@ def adyen_payment_component( logger.info("Start new payment for {}".format(str(order.reference))) ady = Adyen.Adyen() + if not settings.DJADYEN_ENVIRONMENT: + assert False, "Please provide an environment." + + if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: + assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT ady.payment.client.xapikey = settings.DJADYEN_SERVER_KEY ady.payment.client.app_name = settings.DJADYEN_APPNAME + ady.payment.client.live_endpoint_prefix = settings.DJADYEN_LIVE_URL_PREFIX + # Setting request data. request = { "amount": { diff --git a/djadyen/views.py b/djadyen/views.py index 7d2ad7b..4629971 100644 --- a/djadyen/views.py +++ b/djadyen/views.py @@ -41,10 +41,19 @@ def get(self, request, *args, **kwargs): resultRedirect = request.GET.get("redirectResult") if resultRedirect: ady = Adyen.Adyen() + + if not settings.DJADYEN_ENVIRONMENT: + assert False, "Please provide an environment." + + if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: + assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT ady.payment.client.xapikey = settings.DJADYEN_SERVER_KEY ady.payment.client.app_name = settings.DJADYEN_APPNAME + ady.payment.client.live_endpoint_prefix = settings.DJADYEN_LIVE_URL_PREFIX + # Setting request data. request = { "details": { @@ -53,13 +62,20 @@ def get(self, request, *args, **kwargs): } # Requesting the status. result = ady.checkout.payments_details(request) - if result.message.get("resultCode") == "Authorised": + result_code = result.message.get("resultCode") + if result_code == "Authorised": self.handle_authorised(self.object) + elif result_code != "Pending": + self.handle_error(self.object) return super(AdyenResponseView, self).get(request, *args, **kwargs) def handle_authorised(self, order): raise NotImplementedError() + def handle_error(self, order): + order.status = Status.Error + order.save() + class AdyenOrderStatusView(DetailView): slug_field = "reference" diff --git a/setup.cfg b/setup.cfg index 7875cf8..f5cd4cd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ # see http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files [metadata] name = djadyen -version = 2.0.4 +version = 2.0.5 description = Django adyen payment integration long_description = file: README.rst url = https://github.com/maykinmedia/djadyen From 97421889cce50e87f0bc5c00ad009646bc7e418a Mon Sep 17 00:00:00 2001 From: Jorik Kraaikamp Date: Tue, 20 Sep 2022 08:24:11 +0200 Subject: [PATCH 2/7] added the shopper email --- djadyen/templatetags/adyen_tags.py | 5 +++++ javascript/djadyen.js | 4 ---- setup.cfg | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/djadyen/templatetags/adyen_tags.py b/djadyen/templatetags/adyen_tags.py index d5b2e68..7085221 100644 --- a/djadyen/templatetags/adyen_tags.py +++ b/djadyen/templatetags/adyen_tags.py @@ -50,6 +50,11 @@ def adyen_payment_component( if country_code else settings.DJADYEN_DEFAULT_COUNTRY_CODE, } + try: + request["shopperEmail"] = order.email + except Exception: + pass + logger.info(request) # Starting the checkout. result = ady.checkout.sessions(request) diff --git a/javascript/djadyen.js b/javascript/djadyen.js index 93ff341..b4c353c 100644 --- a/javascript/djadyen.js +++ b/javascript/djadyen.js @@ -20,10 +20,6 @@ document.addEventListener("DOMContentLoaded", async () => { sessionData: config.dataset.sessionData, }, onPaymentCompleted: (result) => { - console.log("onPaymentCompleted", "result", result); - console.log("onPaymentCompleted", "checkout", checkout); - console.log("onPaymentCompleted", "component", component); - window.location = config.dataset.redirectUrl; }, onError: (error, component) => { diff --git a/setup.cfg b/setup.cfg index f5cd4cd..78a3083 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ # see http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files [metadata] name = djadyen -version = 2.0.5 +version = 2.0.6 description = Django adyen payment integration long_description = file: README.rst url = https://github.com/maykinmedia/djadyen From 7ae6c7b52490f76687f2bbd9c2e49e6e0b17e241 Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Wed, 7 Aug 2024 12:01:47 +0200 Subject: [PATCH 3/7] fix Adyen dependency --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 78a3083..3ca7b99 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ zip_safe = False include_package_data = True packages = find: install_requires = - Adyen>=6.0.0<7.0.0 + Adyen>7.0.0 django>=1.10 django-choices requests From 6cd238c7717c0b437e282dc27300c108eb481087 Mon Sep 17 00:00:00 2001 From: bart-maykin Date: Wed, 15 Jan 2025 16:22:57 +0100 Subject: [PATCH 4/7] :bug: added missing setting and limited the adyan version. --- setup.cfg | 2 +- testapp/settings.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 3ca7b99..d130d47 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ zip_safe = False include_package_data = True packages = find: install_requires = - Adyen>7.0.0 + Adyen>7.0.0,<8.0.0 django>=1.10 django-choices requests diff --git a/testapp/settings.py b/testapp/settings.py index d551c76..0d03ce3 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -69,6 +69,7 @@ ] # New settings +DJADYEN_ENVIRONMENT = "test" DJADYEN_SERVER_KEY = "test_server_key" DJADYEN_CLIENT_KEY = "test_client_key" DJADYEN_APPNAME = "Djadyen testapp" From e80b8e7b3517783f15acaa60cb083a572d88a8f2 Mon Sep 17 00:00:00 2001 From: bart-maykin Date: Wed, 15 Jan 2025 16:42:35 +0100 Subject: [PATCH 5/7] :art: made the code flake8, isort and black compliant --- djadyen/constants.py | 2 ++ .../commands/sync_payment_methods.py | 8 ++++++-- djadyen/templatetags/adyen_tags.py | 18 +++++++++++------- djadyen/views.py | 10 +++++++--- testapp/settings.py | 4 +++- testapp/urls.py | 2 +- testapp/views.py | 2 -- tests/factories.py | 1 - tests/test_notification_views.py | 1 + 9 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 djadyen/constants.py diff --git a/djadyen/constants.py b/djadyen/constants.py new file mode 100644 index 0000000..b326941 --- /dev/null +++ b/djadyen/constants.py @@ -0,0 +1,2 @@ +LIVE_URL_PREFIX_ERROR = "Please provide the live_url_prefix. " +"https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" diff --git a/djadyen/management/commands/sync_payment_methods.py b/djadyen/management/commands/sync_payment_methods.py index d50fa54..ec34891 100644 --- a/djadyen/management/commands/sync_payment_methods.py +++ b/djadyen/management/commands/sync_payment_methods.py @@ -4,6 +4,7 @@ from djadyen import settings +from ...constants import LIVE_URL_PREFIX_ERROR from ...models import AdyenIssuer, AdyenPaymentOption @@ -41,8 +42,11 @@ def handle(self, *args, **options): if not settings.DJADYEN_ENVIRONMENT: assert False, "Please provide an environment." - if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: - assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + if ( + settings.DJADYEN_ENVIRONMENT == "live" + and not settings.DJADYEN_LIVE_URL_PREFIX + ): + assert False, LIVE_URL_PREFIX_ERROR # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT diff --git a/djadyen/templatetags/adyen_tags.py b/djadyen/templatetags/adyen_tags.py index 7085221..3027d19 100644 --- a/djadyen/templatetags/adyen_tags.py +++ b/djadyen/templatetags/adyen_tags.py @@ -1,4 +1,5 @@ import logging + from django import template from django.utils.translation import get_language @@ -6,6 +7,7 @@ from djadyen import settings from djadyen.choices import Status +from djadyen.constants import LIVE_URL_PREFIX_ERROR register = template.Library() logger = logging.getLogger("adyen") @@ -28,7 +30,7 @@ def adyen_payment_component( assert False, "Please provide an environment." if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: - assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + assert False, LIVE_URL_PREFIX_ERROR # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT @@ -46,9 +48,11 @@ def adyen_payment_component( "merchantAccount": merchant_account, "returnUrl": order.get_return_url(), "shopperLocale": language.lower(), - "countryCode": country_code.lower() - if country_code - else settings.DJADYEN_DEFAULT_COUNTRY_CODE, + "countryCode": ( + country_code.lower() + if country_code + else settings.DJADYEN_DEFAULT_COUNTRY_CODE + ), } try: request["shopperEmail"] = order.email @@ -67,9 +71,9 @@ def adyen_payment_component( "environment": settings.DJADYEN_ENVIRONMENT, "redirect_url": order.get_return_url, "language": get_language(), - "payment_type": order.payment_option.adyen_name - if order.payment_option - else "", + "payment_type": ( + order.payment_option.adyen_name if order.payment_option else "" + ), "issuer": order.issuer.adyen_id if order.issuer else "", } return {} diff --git a/djadyen/views.py b/djadyen/views.py index 4629971..801e53b 100644 --- a/djadyen/views.py +++ b/djadyen/views.py @@ -1,12 +1,13 @@ import logging -from django.http import JsonResponse, HttpResponseRedirect +from django.http import HttpResponseRedirect, JsonResponse from django.views.generic.detail import DetailView import Adyen from djadyen import settings from djadyen.choices import Status +from djadyen.constants import LIVE_URL_PREFIX_ERROR logger = logging.getLogger("adyen") @@ -45,8 +46,11 @@ def get(self, request, *args, **kwargs): if not settings.DJADYEN_ENVIRONMENT: assert False, "Please provide an environment." - if settings.DJADYEN_ENVIRONMENT == "live" and not settings.DJADYEN_LIVE_URL_PREFIX: - assert False, "Please provide the live_url_prefix. https://docs.adyen.com/development-resources/live-endpoints#live-url-prefix" + if ( + settings.DJADYEN_ENVIRONMENT == "live" + and not settings.DJADYEN_LIVE_URL_PREFIX + ): + assert False, LIVE_URL_PREFIX_ERROR # Setting global values ady.payment.client.platform = settings.DJADYEN_ENVIRONMENT diff --git a/testapp/settings.py b/testapp/settings.py index 0d03ce3..d0e9a91 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -75,4 +75,6 @@ DJADYEN_APPNAME = "Djadyen testapp" DJADYEN_MERCHANT_ACCOUNT = "Djadyen_merchant_account" DJADYEN_ORDER_MODELS = ["testapp.Order"] -DJADYEN_NOTIFICATION_KEY = "3424242342353453422435626342654643645624564526436435643542364365" +DJADYEN_NOTIFICATION_KEY = ( + "3424242342353453422435626342654643645624564526436435643542364365" +) diff --git a/testapp/urls.py b/testapp/urls.py index fb0ee96..782959b 100644 --- a/testapp/urls.py +++ b/testapp/urls.py @@ -1,5 +1,5 @@ try: - from django.urls import path, include + from django.urls import include, path except Exception: from django.conf.urls import url as path, include diff --git a/testapp/views.py b/testapp/views.py index 9966c5e..323b7da 100644 --- a/testapp/views.py +++ b/testapp/views.py @@ -1,5 +1,3 @@ -from django.views.generic import TemplateView - from djadyen.choices import Status from djadyen.views import AdyenResponseView diff --git a/tests/factories.py b/tests/factories.py index 1075548..d4baa90 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -2,7 +2,6 @@ from djadyen.choices import Status from djadyen.models import AdyenIssuer, AdyenNotification, AdyenPaymentOption - from testapp.models import Order diff --git a/tests/test_notification_views.py b/tests/test_notification_views.py index fcf3917..13ae949 100644 --- a/tests/test_notification_views.py +++ b/tests/test_notification_views.py @@ -1,4 +1,5 @@ import json + from django.urls import reverse from django_webtest import WebTest From f93843fa2f07c055dfb21f3556f12e6c7bff7d1f Mon Sep 17 00:00:00 2001 From: bart-maykin Date: Wed, 15 Jan 2025 18:06:15 +0100 Subject: [PATCH 6/7] :arrow_up: updated Adyen to 8.0.0 --- djadyen/management/commands/sync_payment_methods.py | 2 +- setup.cfg | 2 +- tests/test_management_command.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/djadyen/management/commands/sync_payment_methods.py b/djadyen/management/commands/sync_payment_methods.py index ec34891..413cbe0 100644 --- a/djadyen/management/commands/sync_payment_methods.py +++ b/djadyen/management/commands/sync_payment_methods.py @@ -59,7 +59,7 @@ def handle(self, *args, **options): "merchantAccount": settings.DJADYEN_MERCHANT_ACCOUNT, } # Starting the checkout. - result = ady.checkout.payment_methods(request) + result = ady.checkout.payments_api.payment_methods(request) payment_methods = result.message.get("paymentMethods") for payment_method in payment_methods: diff --git a/setup.cfg b/setup.cfg index d130d47..bcbcf63 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ zip_safe = False include_package_data = True packages = find: install_requires = - Adyen>7.0.0,<8.0.0 + Adyen==8.0.0 django>=1.10 django-choices requests diff --git a/tests/test_management_command.py b/tests/test_management_command.py index c243ae4..a9a1651 100644 --- a/tests/test_management_command.py +++ b/tests/test_management_command.py @@ -20,7 +20,7 @@ class SyncPaymentMethods(TestFileMixin, TestCase): @requests_mock.mock() def test_on_empty_database_mock(self, mock): mock.post( - "https://checkout-test.adyen.com/v69/paymentMethods", + "https://checkout-test.adyen.com/v70/paymentMethods", [ { "content": self._get_test_file("payment_methods.json").read(), @@ -37,7 +37,7 @@ def test_on_empty_database_mock(self, mock): @requests_mock.mock() def test_on_existing_database_mock(self, mock): mock.post( - "https://checkout-test.adyen.com/v69/paymentMethods", + "https://checkout-test.adyen.com/v70/paymentMethods", [ { "content": self._get_test_file("payment_methods.json").read(), From 08db0d19e983944eb5a0b4d7e32b68c96203359e Mon Sep 17 00:00:00 2001 From: bart-maykin Date: Wed, 15 Jan 2025 18:20:56 +0100 Subject: [PATCH 7/7] :arrow_up: adyen 10+ support --- djadyen/templatetags/adyen_tags.py | 2 +- djadyen/views.py | 2 +- setup.cfg | 2 +- tests/test_management_command.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/djadyen/templatetags/adyen_tags.py b/djadyen/templatetags/adyen_tags.py index 3027d19..ad9e07d 100644 --- a/djadyen/templatetags/adyen_tags.py +++ b/djadyen/templatetags/adyen_tags.py @@ -61,7 +61,7 @@ def adyen_payment_component( logger.info(request) # Starting the checkout. - result = ady.checkout.sessions(request) + result = ady.checkout.payments_api.sessions(request) if result.status_code == 201: return { diff --git a/djadyen/views.py b/djadyen/views.py index 801e53b..ab1762d 100644 --- a/djadyen/views.py +++ b/djadyen/views.py @@ -65,7 +65,7 @@ def get(self, request, *args, **kwargs): }, } # Requesting the status. - result = ady.checkout.payments_details(request) + result = ady.checkout.payments_api.payments_details(request) result_code = result.message.get("resultCode") if result_code == "Authorised": self.handle_authorised(self.object) diff --git a/setup.cfg b/setup.cfg index bcbcf63..bbc80cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ zip_safe = False include_package_data = True packages = find: install_requires = - Adyen==8.0.0 + Adyen>=10.0.0 django>=1.10 django-choices requests diff --git a/tests/test_management_command.py b/tests/test_management_command.py index a9a1651..ad4100f 100644 --- a/tests/test_management_command.py +++ b/tests/test_management_command.py @@ -20,7 +20,7 @@ class SyncPaymentMethods(TestFileMixin, TestCase): @requests_mock.mock() def test_on_empty_database_mock(self, mock): mock.post( - "https://checkout-test.adyen.com/v70/paymentMethods", + "https://checkout-test.adyen.com/v71/paymentMethods", [ { "content": self._get_test_file("payment_methods.json").read(), @@ -37,7 +37,7 @@ def test_on_empty_database_mock(self, mock): @requests_mock.mock() def test_on_existing_database_mock(self, mock): mock.post( - "https://checkout-test.adyen.com/v70/paymentMethods", + "https://checkout-test.adyen.com/v71/paymentMethods", [ { "content": self._get_test_file("payment_methods.json").read(),