Skip to content

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

Fix raising payment error in payment confirm (#8333)

L3str4nge306405704aaa
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.py
index 9ec658fd80..c1a35f5968 100644
--- a/saleor/payment/gateways/adyen/plugin.py
+++ b/saleor/payment/gateways/adyen/plugin.py
@@ -431,7 +431,17 @@ class AdyenGatewayPlugin(BasePlugin):
config = self._get_gateway_config()
additional_data = payment_information.data
if not additional_data:
- raise PaymentError("Unable to finish the payment.")
+ return GatewayResponse(
+ is_success=False,
+ action_required=False,
+ kind=kind,
+ amount=payment_information.amount,
+ currency=payment_information.currency,
+ transaction_id="",
+ error=f"Unable to finish the payment. "
+ f"Payment ({payment_information.graphql_payment_id}) "
+ f"does not have the additional data.",
+ )
with opentracing.global_tracer().start_active_span(
"adyen.checkout.payment_details"
diff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.py
index 2279baa89a..d93ead7519 100644
--- a/saleor/payment/gateways/adyen/tests/test_plugin.py
+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py
@@ -9,7 +9,7 @@ from requests.exceptions import RequestException, SSLError
from .....plugins.models import PluginConfiguration
from .... import PaymentError, TransactionKind
from ....interface import GatewayResponse, PaymentMethodInfo
-from ....models import Payment
+from ....models import Payment, Transaction
from ....utils import create_payment_information, create_transaction
@@ -474,6 +474,30 @@ def test_confirm_payment_with_additional_details(payment_adyen_for_order, adyen_
adyen_plugin.confirm_payment(payment_info, None)
+def test_confirm_payment_without_additional_data(payment_adyen_for_order, adyen_plugin):
+ Transaction.objects.create(
+ payment=payment_adyen_for_order,
+ action_required=False,
+ kind=TransactionKind.ACTION_TO_CONFIRM,
+ token="token",
+ is_success=False,
+ amount="100",
+ currency="EUR",
+ error="",
+ gateway_response={},
+ action_required_data={},
+ )
+
+ payment_info = create_payment_information(payment_adyen_for_order)
+ response = adyen_plugin().confirm_payment(payment_info, None)
+
+ assert not response.is_success
+ assert not response.action_required
+ assert response.kind == TransactionKind.AUTH
+ assert response.error is not None
+ assert payment_info.graphql_payment_id in response.error
+
+
@pytest.mark.vcr
def test_refund_payment(payment_adyen_for_order, order_with_lines, adyen_plugin):
payment_info = create_payment_information(