Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Enhance `TransactionEvent` handling (#17681)
Iga Karbowiakd16c9aa2d6ed
diff --git a/saleor/graphql/payment/tests/queries/test_transaction.py b/saleor/graphql/payment/tests/queries/test_transaction.pyindex f3a8dc6d1a..a796b26916 100644--- a/saleor/graphql/payment/tests/queries/test_transaction.py+++ b/saleor/graphql/payment/tests/queries/test_transaction.py@@ -656,6 +656,7 @@ def test_transaction_event_by_app(external_url=f"http://`{TEST_SERVER_DOMAIN}/test",app_identifier=app_api_client.app.identifier,app=app_api_client.app,+ include_in_calculations=True,)variables = {diff --git a/saleor/payment/tests/test_utils.py b/saleor/payment/tests/test_utils.pyindex 153b8a5be8..8e22415adf 100644--- a/saleor/payment/tests/test_utils.py+++ b/saleor/payment/tests/test_utils.py@@ -2500,6 +2500,52 @@ def test_create_transaction_event_for_transaction_session_failure_doesnt_set_actassert transaction.available_actions == ["charge"]+ "response_result",+ [+ TransactionEventType.AUTHORIZATION_REQUEST,+ TransactionEventType.CHARGE_REQUEST,+ ],+)+def test_create_transaction_event_for_transaction_session_request_events_as_response(+ response_result,+ transaction_item_generator,+ transaction_session_response,+ webhook_app,+ plugins_manager,+):+ # given+ expected_amount = Decimal("15")+ response = transaction_session_response.copy()+ response["result"] = response_result.upper()+ response["amount"] = expected_amount+ transaction = transaction_item_generator()+ request_event = TransactionEvent.objects.create(+ transaction=transaction, include_in_calculations=False+ )++ # when the response event is the `*_REQUEST` event+ response_event = create_transaction_event_for_transaction_session(+ request_event,+ webhook_app,+ manager=plugins_manager,+ transaction_webhook_response=response,+ )++ # then the response event should update the request event with the values+ # from the response+ assert response_event.id == request_event.id+ assert response_event.type == response_result+ assert response_event.include_in_calculations is True+ assert response_event.amount_value == expected_amount+ assert response_event.message == response["message"]+ assert response_event.external_url == response["externalUrl"]+ assert response_event.created_at == datetime.datetime.fromisoformat(+ response["time"]+ )+ assert response_event.psp_reference == response["pspReference"]++@freeze_time("2018-05-31 12:00:01")def test_create_transaction_event_from_request_and_webhook_updates_modified_at(transaction_item_generator,diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex c8821f6198..1a9637c5ee 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -1178,7 +1178,12 @@ def create_transaction_event_for_transaction_session(request_event.amount_value = response_event.amountrequest_event.psp_reference = response_event.psp_referencerequest_event.include_in_calculations = True+ if response_event.time:+ request_event.created_at = response_event.timerequest_event.app = app+ request_event.message = response_event.message+ if response_event.external_url:+ request_event.external_url = response_event.external_urlrequest_event_update_fields.extend(["type",@@ -1186,6 +1191,9 @@ def create_transaction_event_for_transaction_session("psp_reference","include_in_calculations","app",+ "message",+ "created_at",+ "external_url",])event = request_event