diff --git a/src/openforms/registrations/tasks.py b/src/openforms/registrations/tasks.py index bb97291063..d2da261b81 100644 --- a/src/openforms/registrations/tasks.py +++ b/src/openforms/registrations/tasks.py @@ -102,7 +102,7 @@ def pre_registration(submission_id: int, event: PostSubmissionEvents) -> None: ignore_result=False, once={"graceful": True}, # do not spam error monitoring ) -def register_submission(submission_id: int, event: PostSubmissionEvents) -> None: +def register_submission(submission_id: int, event: PostSubmissionEvents | str) -> None: """ Attempt to register the submission with the configured backend. @@ -279,7 +279,10 @@ def register_submission(submission_id: int, event: PostSubmissionEvents) -> None submission, ) - if config.wait_for_payment_to_register and event.on_payment_complete: + if ( + config.wait_for_payment_to_register + and event == PostSubmissionEvents.on_payment_complete + ): submission.payments.update(status=PaymentStatus.registered) submission.save_registration_status(RegistrationStatuses.success, result or {}) diff --git a/src/openforms/registrations/tests/test_registration_hook.py b/src/openforms/registrations/tests/test_registration_hook.py index c9b131ed86..4d0969b184 100644 --- a/src/openforms/registrations/tests/test_registration_hook.py +++ b/src/openforms/registrations/tests/test_registration_hook.py @@ -1,6 +1,7 @@ """ Test the registration hook on submissions. """ + from datetime import timedelta from unittest.mock import patch @@ -17,6 +18,7 @@ from openforms.forms.models import FormRegistrationBackend from openforms.logging.models import TimelineLogProxy from openforms.submissions.constants import PostSubmissionEvents, RegistrationStatuses +from openforms.submissions.public_references import get_random_reference from openforms.submissions.tests.factories import SubmissionFactory from ..base import BasePlugin @@ -345,6 +347,27 @@ def test_registration_backend_invalid_options(self): ): register_submission(submission.id, PostSubmissionEvents.on_retry) + def test_calling_registration_task_with_serialized_args(self): + submission = SubmissionFactory.create( + completed=True, + public_registration_reference=get_random_reference(), + with_completed_payment=True, + form__registration_backend="email", + form__registration_backend_options={"to_emails": ["registration@test.nl"]}, + ) + + with patch( + "openforms.registrations.tasks.GlobalConfiguration.get_solo", + return_value=GlobalConfiguration(wait_for_payment_to_register=True), + ): + register_submission( + submission.id, str(PostSubmissionEvents.on_payment_complete) + ) + + submission.refresh_from_db() + + self.assertEqual(submission.registration_status, RegistrationStatuses.success) + class NumRegistrationsTest(TestCase): @patch("openforms.plugins.registry.GlobalConfiguration.get_solo")