Skip to content

Commit

Permalink
🐛 [#3924] Update payment status also if 'wait_for_payment_to_register…
Browse files Browse the repository at this point in the history
…=True'

The problem was:
If the registration happens after payment, the status of the payment was never changed from 'completed' to 'registered'. The 'finalise_completion' task filters for payments with 'registered' status to decide whether the retry flag should be turned on. This resulted in the retry flag being True even though the payment has been registered.

Backport-of: #3935
  • Loading branch information
SilviaAmAm authored and sergei-maertens committed Feb 27, 2024
1 parent 056aeaf commit f8d406e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/openforms/registrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from openforms.celery import app
from openforms.config.models import GlobalConfiguration
from openforms.logging import logevent
from openforms.payments.constants import PaymentStatus
from openforms.submissions.constants import PostSubmissionEvents, RegistrationStatuses
from openforms.submissions.models import Submission
from openforms.submissions.public_references import set_submission_reference
Expand Down Expand Up @@ -278,5 +279,8 @@ def register_submission(submission_id: int, event: PostSubmissionEvents) -> None
submission,
)

if config.wait_for_payment_to_register and event.on_payment_complete:
submission.payments.update(status=PaymentStatus.registered)

submission.save_registration_status(RegistrationStatuses.success, result or {})
logevent.registration_success(submission, plugin)
36 changes: 35 additions & 1 deletion src/openforms/submissions/tests/test_post_submission_event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from decimal import Decimal
from unittest.mock import patch

from django.core import mail
from django.test import TestCase, override_settings
from django.test import TestCase, override_settings, tag
from django.utils.translation import gettext_lazy as _

from privates.test import temp_private_root
Expand Down Expand Up @@ -982,6 +983,39 @@ def test_cosign_not_required_but_filled_in_does_not_proceed_with_registration(se
self.assertTrue(submission.confirmation_email_sent)
self.assertEqual(submission.auth_info.value, "111222333")

@tag("gh-3924")
def test_payment_complete_does_not_set_retry_flag(self):
submission = SubmissionFactory.create(
form__payment_backend="demo",
form__product__price=Decimal("11.35"),
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
form__name="Pretty Form",
with_public_registration_reference=True,
with_completed_payment=True,
)

with (
patch(
"openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission"
),
patch(
"openforms.registrations.contrib.email.plugin.EmailRegistration.update_payment_status"
),
patch(
"openforms.registrations.tasks.GlobalConfiguration.get_solo",
return_value=GlobalConfiguration(wait_for_payment_to_register=True),
),
):
with self.captureOnCommitCallbacks(execute=True):
on_post_submission_event(
submission.id, PostSubmissionEvents.on_payment_complete
)

submission.refresh_from_db()

self.assertFalse(submission.needs_on_completion_retry)


@temp_private_root()
@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
Expand Down

0 comments on commit f8d406e

Please sign in to comment.