Skip to content

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

Add dedicated fields for Adyen plugin (#17952)

Lukasz Ostrowski55731f1b4bd5
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.py
index 73e830d8b8..d864854690 100644
--- a/saleor/payment/gateways/adyen/plugin.py
+++ b/saleor/payment/gateways/adyen/plugin.py
@@ -1,4 +1,5 @@
import json
+import logging
from typing import Optional
from urllib.parse import urlencode, urljoin
@@ -49,6 +50,8 @@ GATEWAY_NAME = "Adyen"
WEBHOOK_PATH = "/webhooks"
ADDITIONAL_ACTION_PATH = "/additional-actions"
+logger = logging.getLogger(__name__)
+
class AdyenGatewayPlugin(BasePlugin):
PLUGIN_ID = "mirumee.payments.adyen"
@@ -376,6 +379,10 @@ class AdyenGatewayPlugin(BasePlugin):
return False
return self.channel.automatically_confirm_all_new_orders
+ def _normalize_response_field(self, field: str) -> str:
+ """Normalize response field to lowercase and remove spaces."""
+ return field.strip().lower()
+
def process_payment(
self, payment_information: "PaymentData", previous_value
) -> "GatewayResponse":
@@ -426,7 +433,7 @@ class AdyenGatewayPlugin(BasePlugin):
with tracer.start_as_current_span("adyen.checkout.payments") as span:
span.set_attribute(saleor_attributes.COMPONENT, "payment")
result = api_call(request_data, self.adyen.checkout.payments)
- result_code = result.message["resultCode"].strip().lower()
+ result_code = self._normalize_response_field(result.message["resultCode"])
is_success = result_code not in FAILED_STATUSES
adyen_auto_capture = self.config.connection_params["adyen_auto_capture"]
kind = TransactionKind.AUTH
@@ -465,10 +472,17 @@ class AdyenGatewayPlugin(BasePlugin):
currency=payment_information.currency,
transaction_id=result.message.get("pspReference", ""),
error=error_message,
+ # @deprecated
raw_response=result.message,
action_required_data=action,
payment_method_info=payment_method_info,
psp_reference=psp_reference,
+ legacy_adyen_plugin_payment_method=self._normalize_response_field(
+ result.message.get("paymentMethod", "")
+ ),
+ legacy_adyen_plugin_result_code=self._normalize_response_field(
+ result.message.get("resultCode", "")
+ ),
)
@classmethod
@@ -510,7 +524,7 @@ class AdyenGatewayPlugin(BasePlugin):
with tracer.start_as_current_span("adyen.checkout.payment_details") as span:
span.set_attribute(saleor_attributes.COMPONENT, "payment")
result = api_call(additional_data, self.adyen.checkout.payments_details)
- result_code = result.message["resultCode"].strip().lower()
+ result_code = self._normalize_response_field(result.message["resultCode"])
is_success = result_code not in FAILED_STATUSES
action_required = "action" in result.message
if result_code in PENDING_STATUSES:
@@ -542,9 +556,16 @@ class AdyenGatewayPlugin(BasePlugin):
currency=payment_information.currency,
transaction_id=result.message.get("pspReference", ""),
error=result.message.get("refusalReason"),
+ # @deprecated
raw_response=result.message,
psp_reference=result.message.get("pspReference", ""),
payment_method_info=payment_method_info,
+ legacy_adyen_plugin_payment_method=self._normalize_response_field(
+ result.message.get("paymentMethod", "")
+ ),
+ legacy_adyen_plugin_result_code=self._normalize_response_field(
+ result.message.get("resultCode", "")
+ ),
)
def confirm_payment(
@@ -595,10 +616,27 @@ class AdyenGatewayPlugin(BasePlugin):
# standard flow for confirming an additional action
return self._process_additional_action(payment_information, kind)
- result_code = transaction.gateway_response.get("resultCode", "").strip().lower()
- payment_method = (
- transaction.gateway_response.get("paymentMethod", "").strip().lower()
- )
+ result_code_temporary_field = transaction.legacy_adyen_plugin_result_code
+ payment_method_temporary_field = transaction.legacy_adyen_plugin_payment_method
+
+ if (not result_code_temporary_field) and (not payment_method_temporary_field):
+ # Track legacy reads, so we keep grace period in case of enqueued messages
+ logger.warning("Reading deprecated raw_response from Adyen plugin.")
+
+ if result_code_temporary_field:
+ result_code = result_code_temporary_field
+ else:
+ result_code = self._normalize_response_field(
+ transaction.gateway_response.get("resultCode", "")
+ )
+
+ if payment_method_temporary_field:
+ payment_method = payment_method_temporary_field
+ else:
+ payment_method = self._normalize_response_field(
+ transaction.gateway_response.get("paymentMethod", "")
+ )
+
if result_code and result_code in PENDING_STATUSES:
kind = TransactionKind.PENDING
elif result_code == AUTH_STATUS and payment_method == "ideal":
@@ -638,6 +676,7 @@ class AdyenGatewayPlugin(BasePlugin):
currency=payment_information.currency,
transaction_id=token,
error=None,
+ # @deprecated
raw_response={},
transaction_already_processed=bool(transaction_already_processed),
psp_reference=token,
@@ -706,8 +745,15 @@ class AdyenGatewayPlugin(BasePlugin):
currency=currency,
transaction_id=result.message.get("pspReference", ""),
error="",
+ # @deprecated
raw_response=result.message,
psp_reference=result.message.get("pspReference", ""),
+ legacy_adyen_plugin_payment_method=self._normalize_response_field(
+ result.message.get("paymentMethod", "")
+ ),
+ legacy_adyen_plugin_result_code=self._normalize_response_field(
+ result.message.get("resultCode", "")
+ ),
)
def capture_payment(
@@ -736,9 +782,16 @@ class AdyenGatewayPlugin(BasePlugin):
currency=payment_information.currency,
transaction_id=result.message.get("pspReference", ""),
error="",
+ # @deprecated
raw_response=result.message,
payment_method_info=payment_method_info,
psp_reference=result.message.get("pspReference", ""),
+ legacy_adyen_plugin_payment_method=self._normalize_response_field(
+ result.message.get("paymentMethod", "")
+ ),
+ legacy_adyen_plugin_result_code=self._normalize_response_field(
+ result.message.get("resultCode", "")
+ ),
)
def void_payment(
@@ -767,8 +820,15 @@ class AdyenGatewayPlugin(BasePlugin):
currency=payment_information.currency,
transaction_id=result.message.get("pspReference", ""),
error="",
+ # @deprecated
raw_response=result.message,
psp_reference=result.message.get("pspReference", ""),
+ legacy_adyen_plugin_payment_method=self._normalize_response_field(
+ result.message.get("paymentMethod", "")
+ ),
+ legacy_adyen_plugin_result_code=self._normalize_response_field(
+ result.message.get("resultCode", "")
+ ),
)
@classmethod
diff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.py
index dbe30b6c6e..0376d22011 100644
--- a/saleor/payment/gateways/adyen/tests/test_plugin.py
+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py
@@ -47,6 +47,8 @@ def test_process_additional_action(
raw_response=expected_message,
psp_reference="ref-id",
payment_method_info=PaymentMethodInfo(),
+ legacy_adyen_plugin_result_code=expected_message.get("resultCode"),
+ legacy_adyen_plugin_payment_method="",
)
mocked_api_call.assert_called_with(
dummy_payment_data.data, plugin.adyen.checkout.payments_details
diff --git a/saleor/payment/gateways/adyen/webhooks.py b/saleor/payment/gateways/adyen/webhooks.py
index 642a4f7887..1aa1fedae5 100644
--- a/saleor/payment/gateways/adyen/webhooks.py
+++ b/saleor/payment/gateways/adyen/webhooks.py
@@ -153,6 +153,12 @@ def create_new_transaction(notification, payment, kind):
error="",
raw_response=notification,
psp_reference=transaction_id,
+ legacy_adyen_plugin_payment_method=notification.get("paymentMethod", "")
+ .strip()
+ .lower(),
+ legacy_adyen_plugin_result_code=notification.get("resultCode", "")
+ .strip()
+ .lower(),
)
return create_transaction(
payment,
@@ -1168,6 +1174,12 @@ def handle_api_response(
raw_response=response.message,
action_required_data=response.message.get("action"),
psp_reference=response.message.get("pspReference", ""),
+ legacy_adyen_plugin_payment_method=response.message.get("paymentMethod", "")
+ .strip()
+ .lower(),
+ legacy_adyen_plugin_result_code=response.message.get("resultCode", "")
+ .strip()
+ .lower(),
)
create_transaction(
diff --git a/saleor/payment/interface.py b/saleor/payment/interface.py
index 0d30b5afdf..c5bf578886 100644
--- a/saleor/payment/interface.py
+++ b/saleor/payment/interface.py
@@ -316,6 +316,7 @@ class GatewayResponse:
error: str | None
customer_id: str | None = None
payment_method_info: PaymentMethodInfo | None = None
+ # @deprecated
raw_response: dict[str, str] | None = None
action_required_data: JSONType | None = None
# Some gateway can process transaction asynchronously. This value define if we
@@ -323,6 +324,11 @@ class GatewayResponse:
transaction_already_processed: bool = False
psp_reference: str | None = None
+ # Temporary pass Adyen-plugin-specific data to model, so we can drop raw_response
+ # After the plugin is gone, this should be removed
+ legacy_adyen_plugin_result_code: str | None = None
+ legacy_adyen_plugin_payment_method: str | None = None
+
@dataclass
class AddressData:
diff --git a/saleor/payment/migrations/0061_transaction_legacy_adyen_plugin_payment_method_and_more.py b/saleor/payment/migrations/0061_transaction_legacy_adyen_plugin_payment_method_and_more.py
new file mode 100644
index 0000000000..e63daf2509
--- /dev/null
+++ b/saleor/payment/migrations/0061_transaction_legacy_adyen_plugin_payment_method_and_more.py
@@ -0,0 +1,22 @@
+# Generated by Django 4.2.15 on 2025-07-10 09:16
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("payment", "0060_alter_payment_captured_amount_alter_payment_total_and_more"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="transaction",
+ name="legacy_adyen_plugin_payment_method",
+ field=models.TextField(null=True),
+ ),
+ migrations.AddField(
+ model_name="transaction",
+ name="legacy_adyen_plugin_result_code",
+ field=models.TextField(null=True),
+ ),
+ ]
diff --git a/saleor/payment/migrations/0064_merge_20250716_0709.py b/saleor/payment/migrations/0064_merge_20250716_0709.py
new file mode 100644
index 0000000000..95c63750f5
--- /dev/null
+++ b/saleor/payment/migrations/0064_merge_20250716_0709.py
@@ -0,0 +1,12 @@
+# Generated by Django 5.2.1 on 2025-07-16 07:09
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("payment", "0061_transaction_legacy_adyen_plugin_payment_method_and_more"),
+ ("payment", "0063_transactionitem_payment_method_type_ids_and_more"),
+ ]
+
+ operations = []
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index adc19ba487..1023d82c12 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -467,9 +467,22 @@ class Transaction(models.Model):
)
error = models.TextField(null=True)
customer_id = models.CharField(max_length=256, null=True)
+ # @deprecated
gateway_response = JSONField(encoder=DjangoJSONEncoder)
already_processed = models.BooleanField(default=False)
+ """
+ Legacy fields that allow Adyen plugin to work until it's removed.
+
+ Previously Adyen plugin was using gateway_response which holds entire response for every Payment plugin.
+ Adyen plugin is the only plugin using this field, it has access to result_code and payment_method.
+
+ To remove gateway_response we introduce two legacy fields that Adyen can write to and gateway_response can be removed.
+ Once plugin is removed, these fields should be removed from the model.
+ """
+ legacy_adyen_plugin_result_code = models.TextField(null=True)
+ legacy_adyen_plugin_payment_method = models.TextField(null=True)
+
class Meta:
ordering = ("pk",)
indexes = [
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 9b8e3ee42c..f81facf482 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -497,6 +497,8 @@ def create_transaction(
customer_id=gateway_response.customer_id,
gateway_response=gateway_response.raw_response or {},
action_required_data=gateway_response.action_required_data or {},
+ legacy_adyen_plugin_result_code=gateway_response.legacy_adyen_plugin_result_code,
+ legacy_adyen_plugin_payment_method=gateway_response.legacy_adyen_plugin_payment_method,
)
return txn