Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix missing psp references for some adyen payments (#11674)
Maciej Korycinskib8786c1bf4d3
diff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex af848f94d6..b36a34f6fb 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -650,6 +650,7 @@ class AdyenGatewayPlugin(BasePlugin):error=None,raw_response={},transaction_already_processed=bool(transaction_already_processed),+ psp_reference=token,)def refund_payment(diff --git a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_additional_actions.py b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_additional_actions.pyindex 7c7af3017c..331e6308e6 100644--- a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_additional_actions.py+++ b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_additional_actions.py@@ -159,6 +159,45 @@ def test_handle_additional_actions_handles_return_urls(assert response.status_code == 302[email protected]("saleor.payment.gateways.adyen.webhooks.api_call")+def test_handle_additional_actions_sets_psp_reference(+ api_call_mock, payment_adyen_for_checkout, adyen_plugin+):+ # given+ plugin = adyen_plugin()+ channel_slug = plugin.channel.slug+ payment_adyen_for_checkout.to_confirm = True+ payment_adyen_for_checkout.extra_data = json.dumps(+ {"payment_data": "test_data", "parameters": ["payload"]}+ )+ payment_adyen_for_checkout.save(update_fields=["to_confirm", "extra_data"])++ checkout = payment_adyen_for_checkout.checkout+ payment_id = graphene.Node.to_global_id("Payment", payment_adyen_for_checkout.pk)++ request_mock = mock.Mock()+ request_mock.GET = {+ "payment": payment_id,+ "checkout": str(checkout.pk),+ "payload": "test",+ }++ expected_psp_reference = "psp-11111"+ payment_details_mock = mock.Mock()+ message = {+ "pspReference": expected_psp_reference,+ "resultCode": "authorised",+ }+ api_call_mock.return_value.message = message++ # when+ handle_additional_actions(request_mock, payment_details_mock, channel_slug)++ # then+ payment_adyen_for_checkout.refresh_from_db()+ assert payment_adyen_for_checkout.psp_reference == expected_psp_reference++@mock.patch("saleor.payment.gateways.adyen.webhooks.api_call")def test_handle_additional_actions_get(api_call_mock, payment_adyen_for_checkout, adyen_plugindiff --git a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.pyindex 388b1e6ae3..b5bb57e366 100644--- a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py+++ b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py@@ -147,6 +147,52 @@ def test_handle_authorization_for_pending_order(assert external_events.count() == 1+def test_handle_authorization_sets_psp_reference(+ notification,+ adyen_plugin,+ payment_adyen_for_checkout,+ address,+ shipping_method,+):+ # given+ checkout = payment_adyen_for_checkout.checkout+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ checkout.billing_address = address+ checkout.save()++ payment = payment_adyen_for_checkout+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ total = calculations.calculate_checkout_total_with_gift_cards(+ manager, checkout_info, lines, address+ )+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.to_confirm = True+ payment.save()++ expected_psp_reference = "psp-123"++ payment_id = graphene.Node.to_global_id("Payment", payment.pk)+ notification = notification(+ psp_reference=expected_psp_reference,+ merchant_reference=payment_id,+ value=price_to_minor_unit(payment.total, payment.currency),+ )+ config = adyen_plugin().config++ # when+ handle_authorization(notification, config)++ # then+ payment.refresh_from_db()+ assert payment.psp_reference == expected_psp_reference++def test_handle_authorization_for_checkout(notification,adyen_plugin,