Skip to content

Commit

Permalink
added country_code
Browse files Browse the repository at this point in the history
  • Loading branch information
JostCrow committed Jul 27, 2022
1 parent 8f4b122 commit 771fc9b
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion djadyen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .choices import Status

logger = logging.getLogger(__name__)
logger = logging.getLogger("adyen")


class AdyenNotification(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion djadyen/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..models import AdyenNotification
from .hmac import get_signature

logger = logging.getLogger(__name__)
logger = logging.getLogger("adyen")


class NotificationView(View):
Expand Down
3 changes: 3 additions & 0 deletions djadyen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
)
DJADYEN_ORDER_MODELS = getattr(dj_settings, "DJADYEN_ORDER_MODELS")
DJADYEN_NOTIFICATION_KEY = getattr(dj_settings, "DJADYEN_NOTIFICATION_KEY")
DJADYEN_DEFAULT_COUNTRY_CODE = getattr(
dj_settings, "DJADYEN_DEFAULT_COUNTRY_CODE", "nl"
)
16 changes: 8 additions & 8 deletions djadyen/static/djadyen/djadyen.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions djadyen/templates/adyen/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
{% if issuer %}data-issuer="{{ issuer }}"{% endif %}
></div>
<div id="djadyen-container"></div>
<div id="djadyen-actions">
<button id="button" class="button button">{% trans "Betaal" %}</button>
</div>
2 changes: 1 addition & 1 deletion djadyen/templates/adyen/pay.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


{% block content %}
{% adyen_payment_component order=object %}
{% adyen_payment_component language=request.LANGUAGE_CODE order=object %}
{% endblock %}
19 changes: 15 additions & 4 deletions djadyen/templatetags/adyen_tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from django import template
from django.utils.translation import get_language

Expand All @@ -7,31 +8,41 @@
from djadyen.choices import Status

register = template.Library()
logger = logging.getLogger("adyen")


@register.inclusion_tag("adyen/component.html")
def adyen_payment_component(order):
def adyen_payment_component(
language,
order,
merchant_account=settings.DJADYEN_MERCHANT_ACCOUNT,
country_code=settings.DJADYEN_DEFAULT_COUNTRY_CODE,
):
"""
Will display a singular payment method.
"""
logger.info("Start new payment for {}".format(str(order.reference)))
ady = Adyen.Adyen()

# 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

# Setting request data.
request = {
"amount": {
"value": order.get_price_in_cents(),
"currency": settings.DJADYEN_CURRENCYCODE,
},
"reference": str(order.reference),
"merchantAccount": settings.DJADYEN_MERCHANT_ACCOUNT,
"merchantAccount": merchant_account,
"returnUrl": order.get_return_url(),
"shopperLocale": language.lower(),
"countryCode": country_code.lower()
if country_code
else settings.DJADYEN_DEFAULT_COUNTRY_CODE,
}

logger.info(request)
# Starting the checkout.
result = ady.checkout.sessions(request)

Expand Down
17 changes: 16 additions & 1 deletion djadyen/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from django.http import JsonResponse
from django.http import JsonResponse, HttpResponseRedirect
from django.views.generic.detail import DetailView

from .choices import Status
Expand All @@ -18,11 +18,26 @@ class AdyenPaymentView(DetailView):
slug_field = "reference"
slug_url_kwarg = "reference"

def get(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.get_price_in_cents() == 0:
return HttpResponseRedirect(self.object.get_return_url())
return super(AdyenPaymentView, self).get(request, *args, **kwargs)


class AdyenResponseView(DetailView):
slug_field = "reference"
slug_url_kwarg = "reference"

def get(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.get_price_in_cents() == 0:
self.handle_authorised(self.object)
return super(AdyenResponseView, self).get(request, *args, **kwargs)

def handle_authorised(self, order):
raise NotImplementedError()


class AdyenOrderStatusView(DetailView):
slug_field = "reference"
Expand Down
7 changes: 1 addition & 6 deletions javascript/djadyen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "./overwrites.css";

document.addEventListener("DOMContentLoaded", async () => {
const config = document.querySelector("#djadyen-config");
const button = document.querySelector("#button");

if (config) {
const configuration = {
environment: config.dataset.environment,
clientKey: config.dataset.clientKey,
locale: config.dataset.language,
showPayButton: true,
analytics: {
enabled: false,
},
Expand Down Expand Up @@ -50,11 +50,6 @@ document.addEventListener("DOMContentLoaded", async () => {
component.submit();
}, 50);
}

button.addEventListener("click", (event) => {
event.preventDefault();
component.submit();
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.4a5
version = 2.0.4a19
description = Django adyen payment integration
long_description = file: README.rst
url = https://github.com/maykinmedia/djadyen
Expand Down

0 comments on commit 771fc9b

Please sign in to comment.