Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Update adyen configuration and webhooks

IKarbowiak77d8c9bfc5e8
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.py
index 39f2cc7184..9615296dbe 100644
--- a/saleor/payment/gateways/adyen/plugin.py
+++ b/saleor/payment/gateways/adyen/plugin.py
@@ -6,11 +6,12 @@ import Adyen
from django.contrib.auth.hashers import make_password
from django.core.exceptions import ObjectDoesNotExist
from django.core.handlers.wsgi import WSGIRequest
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseNotFound
from graphql_relay import from_global_id
from ....checkout.models import Checkout
from ....core.emails import prepare_url
+from ....core.utils import build_absolute_uri
from ....plugins.base_plugin import BasePlugin, ConfigurationTypeField
from ... import PaymentError, TransactionKind
from ...interface import GatewayConfig, GatewayResponse, PaymentData, PaymentGateway
@@ -24,9 +25,11 @@ from .utils import (
request_for_payment_refund,
update_payment_with_action_required_data,
)
-from .webhooks import handle_webhook
+from .webhooks import handle_additional_actions, handle_webhook
GATEWAY_NAME = "Adyen"
+WEBHOOK_PATH = "/webhooks"
+ADDITIONAL_ACTION_PATH = "/additional_actions"
def require_active_plugin(fn):
@@ -49,7 +52,6 @@ class AdyenGatewayPlugin(BasePlugin):
{"name": "Merchant Account", "value": None},
{"name": "API key", "value": None},
{"name": "Supported currencies", "value": ""},
- {"name": "Return Url", "value": ""},
{"name": "Origin Key", "value": ""},
{"name": "Origin Url", "value": ""},
{"name": "Live", "value": ""},
@@ -80,11 +82,6 @@ class AdyenGatewayPlugin(BasePlugin):
" Please enter currency codes separated by a comma.",
"label": "Supported currencies",
},
- "Return Url": {
- "type": ConfigurationTypeField.STRING,
- "help_text": "", # FIXME define them as per channel
- "label": "Return Url",
- },
"Origin Key": {
"type": ConfigurationTypeField.STRING,
"help_text": "", # FIXME define them as per channel
@@ -175,7 +172,6 @@ class AdyenGatewayPlugin(BasePlugin):
connection_params={
"api_key": configuration["API key"],
"merchant_account": configuration["Merchant Account"],
- "return_url": configuration["Return Url"],
"origin_key": configuration["Origin Key"],
"origin_url": configuration["Origin Url"],
"live": configuration["Live"],
@@ -194,7 +190,13 @@ class AdyenGatewayPlugin(BasePlugin):
def webhook(self, request: WSGIRequest, path: str, previous_value) -> HttpResponse:
config = self._get_gateway_config()
- return handle_webhook(request, config, self.adyen.checkout.payments_details)
+ if path.startswith(WEBHOOK_PATH):
+ return handle_webhook(request, config)
+ elif path.startswith(ADDITIONAL_ACTION_PATH):
+ return handle_additional_actions(
+ request, self.adyen.checkout.payments_details
+ )
+ return HttpResponseNotFound()
def _get_gateway_config(self) -> GatewayConfig:
return self.config
@@ -234,9 +236,15 @@ class AdyenGatewayPlugin(BasePlugin):
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
params = urlencode({"payment": payment_information.payment_id})
+ return_url = prepare_url(
+ params,
+ build_absolute_uri(
+ f"/plugins/{self.PLUGIN_ID}/additional_actions"
+ ), # type: ignore
+ )
request_data = request_data_for_payment(
payment_information,
- return_url=prepare_url(params, self.config.connection_params["return_url"]),
+ return_url=return_url,
merchant_account=self.config.connection_params["merchant_account"],
origin_url=self.config.connection_params["origin_url"],
)
diff --git a/saleor/payment/gateways/adyen/webhooks.py b/saleor/payment/gateways/adyen/webhooks.py
index 4f8ce829a9..5996b160de 100644
--- a/saleor/payment/gateways/adyen/webhooks.py
+++ b/saleor/payment/gateways/adyen/webhooks.py
@@ -470,14 +470,8 @@ def validate_auth_user(headers: HttpHeaders, gateway_config: "GatewayConfig") ->
return False
-def handle_webhook(
- request: WSGIRequest, gateway_config: "GatewayConfig", payment_details: Callable
-):
- try:
- json_data = json.loads(request.body)
- except ValueError:
- return handle_additional_actions(request, payment_details)
-
+def handle_webhook(request: WSGIRequest, gateway_config: "GatewayConfig"):
+ json_data = json.loads(request.body)
# JSON and HTTP POST notifications always contain a single NotificationRequestItem
# object.
notification = json_data.get("notificationItems")[0].get(