Skip to content

Commit 6b42e04

Browse files
committed
[#3793] Revert fallback to random reference, fix related tests
1 parent 86867eb commit 6b42e04

File tree

6 files changed

+13
-47
lines changed

6 files changed

+13
-47
lines changed

src/openforms/payments/contrib/demo/tests/test_plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DemoPaymentTests(TestCase):
2323

2424
def test_payment(self):
2525
submission = SubmissionFactory.create(
26-
completed=True,
26+
with_public_registration_reference=True,
2727
form__slug="myform",
2828
form__payment_backend="demo",
2929
form__product__price=Decimal("11.35"),

src/openforms/payments/contrib/ogone/tests/test_plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_payment(self):
2929
pspid="psp123",
3030
)
3131
submission = SubmissionFactory.create(
32-
completed=True,
32+
with_public_registration_reference=True,
3333
form__slug="myform",
3434
form__payment_backend="ogone-legacy",
3535
form__payment_backend_options={"merchant_id": merchant.id},
@@ -131,7 +131,7 @@ def test_webhook(self):
131131
pspid="psp123",
132132
)
133133
submission = SubmissionFactory.create(
134-
completed=True,
134+
with_public_registration_reference=True,
135135
form__slug="myform",
136136
form__payment_backend="ogone-legacy",
137137
form__payment_backend_options={"merchant_id": merchant.id},

src/openforms/payments/models.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ def create_public_order_id_for(
5656
if prefix:
5757
prefix = f"{prefix}/"
5858

59-
reference = payment.submission.public_registration_reference
60-
if not reference and config.wait_for_payment_to_register:
61-
from openforms.submissions.public_references import ( # circ. ref
62-
set_submission_reference,
63-
)
64-
65-
reference = set_submission_reference(payment.submission)
59+
assert payment.submission.public_registration_reference
6660

6761
pk = pk if pk is not None else payment.pk
6862

69-
return f"{prefix}{payment.submission.public_registration_reference}/{pk}"
63+
return (
64+
f"{prefix}{payment.submission.public_registration_reference}/{payment.pk}"
65+
)
7066

7167

7268
class SubmissionPaymentQuerySet(models.QuerySet["SubmissionPayment"]):

src/openforms/payments/tests/test_models.py

-32
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,6 @@ def test_create_for_with_prefix(self, m: MagicMock):
8686
)
8787
self.assertEqual(payment.public_order_id, "xyz2020/OF-123456/4")
8888

89-
@patch(
90-
"openforms.payments.models.GlobalConfiguration.get_solo",
91-
return_value=GlobalConfiguration(
92-
payment_order_id_prefix="", wait_for_payment_to_register=True
93-
),
94-
)
95-
@patch(
96-
"openforms.submissions.public_references.get_random_reference",
97-
return_value="OF-123456",
98-
)
99-
def test_create_for_no_registration(self, m1: MagicMock, m2: MagicMock):
100-
amount = Decimal("11.25")
101-
options = {
102-
"foo": 123,
103-
}
104-
105-
submission = SubmissionFactory.create(completed_not_preregistered=True)
106-
# create some pre-existing records
107-
SubmissionPaymentFactory.create_batch(size=2)
108-
109-
# create payment with auto-generated order_id
110-
payment = SubmissionPayment.objects.create_for(
111-
submission, "plugin1", options, amount
112-
)
113-
114-
self.assertEqual(payment.public_order_id, "OF-123456/3")
115-
116-
payment = SubmissionPayment.objects.create_for(
117-
submission, "plugin1", options, amount
118-
)
119-
self.assertEqual(payment.public_order_id, "OF-123456/4")
120-
12189
def test_queryset_sum_amount(self):
12290
self.assertEqual(0, SubmissionPayment.objects.none().sum_amount())
12391

src/openforms/payments/tests/test_views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_views(self, on_post_submission_event_mock):
4848
self.addCleanup(registry_mock.stop)
4949

5050
submission = SubmissionFactory.create(
51-
completed=True,
51+
with_public_registration_reference=True,
5252
form__product__price=Decimal("11.25"),
5353
form__payment_backend="plugin1",
5454
form_url="http://allowed.foo/my-form",
@@ -191,7 +191,7 @@ def test_start_plugin_not_enabled(
191191
registry_mock.start()
192192
self.addCleanup(registry_mock.stop)
193193
submission = SubmissionFactory.create(
194-
completed=True,
194+
with_public_registration_reference=True,
195195
form__product__price=Decimal("11.25"),
196196
form__payment_backend="plugin1",
197197
form_url="http://allowed.foo/my-form",

src/openforms/payments/views.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ class PaymentFlowBaseView(APIView):
9999
class PaymentStartView(PaymentFlowBaseView, GenericAPIView):
100100
lookup_field = "uuid"
101101
lookup_url_kwarg = "uuid"
102-
queryset = Submission.objects.all()
102+
queryset = Submission.objects.exclude(completed_on__isnull=True)
103103
serializer_class = PaymentInfoSerializer
104104

105105
def post(self, request, uuid: str, plugin_id: str):
106-
submission = self.get_object()
106+
submission: Submission = self.get_object()
107+
assert submission.public_registration_reference
108+
107109
try:
108110
plugin = register[plugin_id]
109111
except KeyError:

0 commit comments

Comments
 (0)