From 8aed2c28364c51b254693202e86807423b42b9fe Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Wed, 10 Apr 2024 11:35:19 +0200 Subject: [PATCH 1/3] :test_tube: [#4145] Reproduced with test --- .../contrib/stuf_zds/tests/test_backend.py | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py index dc4b5996c2..93750f9ea0 100644 --- a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py +++ b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py @@ -2,22 +2,27 @@ from decimal import Decimal from unittest.mock import patch +from django.test import override_settings, tag + import requests_mock from freezegun import freeze_time from privates.test import temp_private_root from requests import ConnectTimeout from openforms.authentication.tests.factories import RegistratorInfoFactory +from openforms.config.models import GlobalConfiguration from openforms.forms.tests.factories import FormVariableFactory from openforms.logging.models import TimelineLogProxy +from openforms.payments.constants import PaymentStatus from openforms.submissions.constants import PostSubmissionEvents -from openforms.submissions.tasks import pre_registration +from openforms.submissions.tasks import on_post_submission_event, pre_registration from openforms.submissions.tests.factories import ( SubmissionFactory, SubmissionFileAttachmentFactory, SubmissionValueVariableFactory, ) from openforms.variables.constants import FormVariableDataTypes, FormVariableSources +from stuf.stuf_zds.client import PaymentStatus as StuFPaymentStatus from stuf.stuf_zds.models import StufZDSConfig from stuf.stuf_zds.tests import StUFZDSTestBase from stuf.stuf_zds.tests.utils import load_mock, match_text, xml_from_request_history @@ -2851,3 +2856,74 @@ def test_plugin_with_extra_unmapped_number_data(self, m, mock_task): "//stuf:extraElementen/stuf:extraElement[@naam='extra_number']", "2023", ) + + @tag("gh-4145") + @override_settings(CELERY_TASK_ALWAYS_EAGER=True) + def test_payment_status_is_correct(self, m): + """ + #4145: + Testing that if 'wait_for_payment_to_register' is True, when the payment is completed and the submission is + registered, the right payment status is sent to the StUF-ZDS backend. + """ + submission = SubmissionFactory.from_components( + components_list=[ + { + "key": "email", + "type": "email", + "label": "Email", + }, + ], + submitted_data={"email": "test@test.nl"}, + with_public_registration_reference=True, + cosign_request_email_sent=True, + confirmation_email_sent=True, + form__registration_backend="stuf-zds-create-zaak", + form__registration_backend_options={ + "zds_zaaktype_code": "zt-code", + "zds_documenttype_omschrijving_inzending": "aaabbc", + }, + form__name="Pretty Form", + with_completed_payment=True, + registration_result={"intermediate": {"zaaknummer": "ZAAK-TRALALA"}}, + ) + + m.post( + self.service.soap_service.url, + content=load_mock("creeerZaak.xml"), + additional_matcher=match_text("zakLk01"), + ) + m.post( + self.service.soap_service.url, + content=load_mock( + "genereerDocumentIdentificatie.xml", + {"document_identificatie": "bar-document"}, + ), + additional_matcher=match_text("genereerDocumentIdentificatie_Di02"), + ) + m.post( + self.service.soap_service.url, + content=load_mock("voegZaakdocumentToe.xml"), + additional_matcher=match_text("edcLk01"), + ) + + with patch( + "openforms.registrations.tasks.GlobalConfiguration.get_solo", + return_value=GlobalConfiguration(wait_for_payment_to_register=True), + ): + on_post_submission_event( + submission.id, PostSubmissionEvents.on_payment_complete + ) + + submission.refresh_from_db() + + self.assertTrue( + submission.payments.filter(status=PaymentStatus.registered).exists() + ) + + xml_doc = xml_from_request_history(m, 0) + + self.assertXPathEquals( + xml_doc, + "//zkn:betalingsIndicatie", + StuFPaymentStatus.FULL, + ) From d68f6bbac8450c8a95d5c85a3885ad250595acf1 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Wed, 10 Apr 2024 12:37:39 +0200 Subject: [PATCH 2/3] :bug: [#4145] Extract payment status from submission Send to the registration backend the payment status that is tracked on the submission. --- .../registrations/contrib/stuf_zds/plugin.py | 22 +++++++++++++++---- src/stuf/stuf_zds/client.py | 4 ---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/openforms/registrations/contrib/stuf_zds/plugin.py b/src/openforms/registrations/contrib/stuf_zds/plugin.py index f03b4afe82..5ca9b0e199 100644 --- a/src/openforms/registrations/contrib/stuf_zds/plugin.py +++ b/src/openforms/registrations/contrib/stuf_zds/plugin.py @@ -22,7 +22,12 @@ ) from openforms.submissions.models import Submission, SubmissionReport from openforms.utils.mixins import JsonSchemaSerializerMixin -from stuf.stuf_zds.client import NoServiceConfigured, ZaakOptions, get_client +from stuf.stuf_zds.client import ( + NoServiceConfigured, + PaymentStatus, + ZaakOptions, + get_client, +) from stuf.stuf_zds.constants import VertrouwelijkheidsAanduidingen from stuf.stuf_zds.models import StufZDSConfig @@ -266,10 +271,19 @@ def items(self): yield ("language_code", submission.language_code) yield from extra_data.items() + payment_status = ( + PaymentStatus.NVT + if not submission.payment_required + else ( + PaymentStatus.FULL + if submission.payment_user_has_paid + else PaymentStatus.NOT_YET + ) + ) + zaak_data.update({"betalings_indicatie": payment_status}) + execute_unless_result_exists( - lambda: client.create_zaak( - zaak_id, zaak_data, LangInjection(), submission.payment_required - ), + lambda: client.create_zaak(zaak_id, zaak_data, LangInjection()), submission, "intermediate.zaak_created", default=False, diff --git a/src/stuf/stuf_zds/client.py b/src/stuf/stuf_zds/client.py index bd85d1e4a9..b17dbef70b 100644 --- a/src/stuf/stuf_zds/client.py +++ b/src/stuf/stuf_zds/client.py @@ -221,7 +221,6 @@ def create_zaak( zaak_identificatie: str, zaak_data: dict, extra_data, - payment_required=False, ) -> None: now = timezone.now() context = { @@ -240,9 +239,6 @@ def create_zaak( "zaak_omschrijving": self.zds_options["omschrijving"], "zaak_identificatie": zaak_identificatie, "extra": extra_data, - "betalings_indicatie": ( - PaymentStatus.NOT_YET if payment_required else PaymentStatus.NVT - ), "global_config": GlobalConfiguration.get_solo(), **zaak_data, } From 61cb9264863b14717a31be96436c6a9946ccd6dd Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Wed, 10 Apr 2024 12:38:05 +0200 Subject: [PATCH 3/3] :white_check_mark: [#4145] Add tests to improve coverage --- .../contrib/stuf_zds/tests/test_backend.py | 126 +++++++++++++++++- src/stuf/stuf_zds/tests/test_backend.py | 6 +- 2 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py index 93750f9ea0..b0e7f7d7ea 100644 --- a/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py +++ b/src/openforms/registrations/contrib/stuf_zds/tests/test_backend.py @@ -2857,9 +2857,22 @@ def test_plugin_with_extra_unmapped_number_data(self, m, mock_task): "2023", ) + +@freeze_time("2020-12-22") +@temp_private_root() +@requests_mock.Mocker() +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) +class StufZDSPluginPaymentTests(StUFZDSTestBase): + def setUp(self): + super().setUp() + + self.service = StufServiceFactory.create() + config = StufZDSConfig.get_solo() + config.service = self.service + config.save() + @tag("gh-4145") - @override_settings(CELERY_TASK_ALWAYS_EAGER=True) - def test_payment_status_is_correct(self, m): + def test_payment_status_is_correct_on_payment_update(self, m): """ #4145: Testing that if 'wait_for_payment_to_register' is True, when the payment is completed and the submission is @@ -2875,7 +2888,6 @@ def test_payment_status_is_correct(self, m): ], submitted_data={"email": "test@test.nl"}, with_public_registration_reference=True, - cosign_request_email_sent=True, confirmation_email_sent=True, form__registration_backend="stuf-zds-create-zaak", form__registration_backend_options={ @@ -2927,3 +2939,111 @@ def test_payment_status_is_correct(self, m): "//zkn:betalingsIndicatie", StuFPaymentStatus.FULL, ) + + def test_payment_status_is_correct_if_not_waiting_for_payment(self, m): + submission = SubmissionFactory.from_components( + components_list=[ + { + "key": "email", + "type": "email", + "label": "Email", + }, + ], + submitted_data={"email": "test@test.nl"}, + with_public_registration_reference=True, + form__registration_backend="stuf-zds-create-zaak", + form__registration_backend_options={ + "zds_zaaktype_code": "zt-code", + "zds_documenttype_omschrijving_inzending": "aaabbc", + }, + form__name="Pretty Form", + form__product__price=Decimal("10.00"), + form__payment_backend="demo", + registration_result={}, + ) + + m.post( + self.service.soap_service.url, + content=load_mock("creeerZaak.xml"), + additional_matcher=match_text("zakLk01"), + ) + m.post( + self.service.soap_service.url, + content=load_mock( + "genereerDocumentIdentificatie.xml", + {"document_identificatie": "bar-document"}, + ), + additional_matcher=match_text("genereerDocumentIdentificatie_Di02"), + ) + m.post( + self.service.soap_service.url, + content=load_mock("voegZaakdocumentToe.xml"), + additional_matcher=match_text("edcLk01"), + ) + + with patch( + "openforms.registrations.tasks.GlobalConfiguration.get_solo", + return_value=GlobalConfiguration(wait_for_payment_to_register=False), + ): + on_post_submission_event(submission.id, PostSubmissionEvents.on_completion) + + submission.refresh_from_db() + + xml_doc = xml_from_request_history(m, 0) + + self.assertXPathEquals( + xml_doc, + "//zkn:betalingsIndicatie", + StuFPaymentStatus.NOT_YET, + ) + + def test_payment_status_is_correct_when_no_payment_required(self, m): + submission = SubmissionFactory.from_components( + components_list=[ + { + "key": "email", + "type": "email", + "label": "Email", + }, + ], + submitted_data={"email": "test@test.nl"}, + with_public_registration_reference=True, + form__registration_backend="stuf-zds-create-zaak", + form__registration_backend_options={ + "zds_zaaktype_code": "zt-code", + "zds_documenttype_omschrijving_inzending": "aaabbc", + }, + form__name="Pretty Form", + registration_result={}, + ) + + m.post( + self.service.soap_service.url, + content=load_mock("creeerZaak.xml"), + additional_matcher=match_text("zakLk01"), + ) + m.post( + self.service.soap_service.url, + content=load_mock( + "genereerDocumentIdentificatie.xml", + {"document_identificatie": "bar-document"}, + ), + additional_matcher=match_text("genereerDocumentIdentificatie_Di02"), + ) + m.post( + self.service.soap_service.url, + content=load_mock("voegZaakdocumentToe.xml"), + additional_matcher=match_text("edcLk01"), + ) + + on_post_submission_event(submission.id, PostSubmissionEvents.on_completion) + + submission.refresh_from_db() + + xml_doc = xml_from_request_history(m, 0) + + self.assertXPathEquals( + xml_doc, + "//zkn:betalingsIndicatie", + StuFPaymentStatus.NVT, + ) diff --git a/src/stuf/stuf_zds/tests/test_backend.py b/src/stuf/stuf_zds/tests/test_backend.py index 9cac4202f5..144d5bc2cc 100644 --- a/src/stuf/stuf_zds/tests/test_backend.py +++ b/src/stuf/stuf_zds/tests/test_backend.py @@ -214,7 +214,11 @@ def test_create_zaak(self, m): additional_matcher=match_text("zakLk01"), ) - client.create_zaak("foo", {"bsn": "111222333"}, {}, payment_required=True) + client.create_zaak( + "foo", + {"bsn": "111222333", "betalings_indicatie": PaymentStatus.NOT_YET}, + {}, + ) request = m.request_history[0] self.assertEqual(