Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Call additionaldetails action to confirm the payment (#5979)
Maciej Korycinski6de8cada1e8c
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex 1e3c37bc26..838147d964 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -346,20 +346,34 @@ class AdyenGatewayPlugin(BasePlugin):.exclude(token__isnull=True, token__exact="").last())- if not transaction:- raise PaymentError(- "Unable to finish the payment. Payment needs to be confirm by external "- "source."+ if transaction:+ # We already have the Auth/Capture transaction which means that payment was+ # confirmed asynchronous+ return GatewayResponse(+ is_success=transaction.is_success,+ action_required=False,+ kind=TransactionKind.CONFIRM,+ amount=transaction.amount,+ currency=transaction.currency,+ transaction_id=transaction.token,+ error=None,+ raw_response={},)+ additional_data = payment_information.data+ if not additional_data:+ raise PaymentError("Unable to finish the payment.")++ result = api_call(additional_data, self.adyen.checkout.payments)+ is_success = result.message["resultCode"].strip().lower() not in FAILED_STATUSESreturn GatewayResponse(- is_success=transaction.is_success,- action_required=False,+ is_success=is_success,+ action_required="action" in result.message,kind=TransactionKind.CONFIRM,- amount=transaction.amount,- currency=transaction.currency,- transaction_id=transaction.token,- error=None,- raw_response={},+ amount=payment_information.amount,+ currency=payment_information.currency,+ transaction_id=result.get("pspReference", ""),+ error=result.message.get("refusalReason"),+ raw_response=result.message,)@require_active_plugindiff --git a/saleor/payment/gateways/adyen/tests/test_plugin.py b/saleor/payment/gateways/adyen/tests/test_plugin.pyindex d204ba5575..93112b42fd 100644--- a/saleor/payment/gateways/adyen/tests/test_plugin.py+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py@@ -237,6 +237,15 @@ def test_confirm_payment(payment_adyen_for_order, adyen_plugin):assert response.currency == auth_transaction.currency[email protected](reason="To finish when additional auth data schema will be known")+def test_confirm_payment_with_additional_details(payment_adyen_for_order, adyen_plugin):+ return # test it when we will have additional auth data+ payment_info = create_payment_information(payment_adyen_for_order,)+ adyen_plugin = adyen_plugin()+ adyen_plugin.confirm_payment(payment_info, None)++@pytest.mark.vcrdef test_refund_payment(payment_adyen_for_order, order_with_lines, adyen_plugin):payment_info = create_payment_information(