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

fix Adyen dependency #220

Merged
merged 6 commits into from
Jan 19, 2025
Merged
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
2 changes: 2 additions & 0 deletions djadyen/constants.py
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 7 additions & 3 deletions djadyen/management/commands/sync_payment_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from djadyen import settings

from ...constants import LIVE_URL_PREFIX_ERROR
from ...models import AdyenIssuer, AdyenPaymentOption


Expand Down Expand Up @@ -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
Expand All @@ -55,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:
Expand Down
20 changes: 12 additions & 8 deletions djadyen/templatetags/adyen_tags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

from django import template
from django.utils.translation import get_language

import Adyen

from djadyen import settings
from djadyen.choices import Status
from djadyen.constants import LIVE_URL_PREFIX_ERROR

register = template.Library()
logger = logging.getLogger("adyen")
Expand All @@ -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
Expand All @@ -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
Expand All @@ -57,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 {
Expand All @@ -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 {}
Expand Down
12 changes: 8 additions & 4 deletions djadyen/views.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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
Expand All @@ -61,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)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ zip_safe = False
include_package_data = True
packages = find:
install_requires =
Adyen>=6.0.0<7.0.0
Adyen>=10.0.0
django>=1.10
django-choices
requests
Expand Down
5 changes: 4 additions & 1 deletion testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@
]

# New settings
DJADYEN_ENVIRONMENT = "test"
DJADYEN_SERVER_KEY = "test_server_key"
DJADYEN_CLIENT_KEY = "test_client_key"
DJADYEN_APPNAME = "Djadyen testapp"
DJADYEN_MERCHANT_ACCOUNT = "Djadyen_merchant_account"
DJADYEN_ORDER_MODELS = ["testapp.Order"]
DJADYEN_NOTIFICATION_KEY = "3424242342353453422435626342654643645624564526436435643542364365"
DJADYEN_NOTIFICATION_KEY = (
"3424242342353453422435626342654643645624564526436435643542364365"
)
2 changes: 1 addition & 1 deletion testapp/urls.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions testapp/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.views.generic import TemplateView

from djadyen.choices import Status
from djadyen.views import AdyenResponseView

Expand Down
1 change: 0 additions & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from djadyen.choices import Status
from djadyen.models import AdyenIssuer, AdyenNotification, AdyenPaymentOption

from testapp.models import Order


Expand Down
4 changes: 2 additions & 2 deletions tests/test_management_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/v71/paymentMethods",
[
{
"content": self._get_test_file("payment_methods.json").read(),
Expand All @@ -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/v71/paymentMethods",
[
{
"content": self._get_test_file("payment_methods.json").read(),
Expand Down
1 change: 1 addition & 0 deletions tests/test_notification_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from django.urls import reverse

from django_webtest import WebTest
Expand Down
Loading