Skip to content

Commit

Permalink
feat: show prominent warning about bank account change
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 13, 2024
1 parent a4b2007 commit ad1c397
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion weblate_web/payments/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
}


def get_backend(name):
def get_backend(name: str) -> type[Backend]:
backend = BACKENDS[name]
if backend.debug and not settings.PAYMENT_DEBUG:
raise KeyError("Invalid backend")
Expand Down
7 changes: 6 additions & 1 deletion weblate_web/payments/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

from __future__ import annotations

import json
from datetime import date
from typing import cast

import responses
from django.core import mail
Expand All @@ -27,6 +30,7 @@
from django.test import SimpleTestCase, TestCase
from django.test.utils import override_settings

from weblate_web.invoices.models import Invoice
from weblate_web.tests import (
THEPAY2_MOCK_SETTINGS,
mock_vies,
Expand Down Expand Up @@ -273,7 +277,8 @@ def test_proforma(self):
mail.outbox = []

received = FIO_TRASACTIONS.copy()
proforma_id = backend.payment.draft_invoice.number
self.assertIsNotNone(backend.payment.draft_invoice)
proforma_id = cast(Invoice, backend.payment.draft_invoice).number
transaction = received["accountStatement"]["transactionList"]["transaction"] # type: ignore[index]
transaction[0]["column16"]["value"] = proforma_id
transaction[1]["column16"]["value"] = proforma_id
Expand Down
16 changes: 14 additions & 2 deletions weblate_web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@
process_donation,
process_subscription,
)
from weblate_web.payments.backends import PaymentError, get_backend, list_backends
from weblate_web.payments.backends import (
Backend,
PaymentError,
get_backend,
list_backends,
)
from weblate_web.payments.forms import CustomerForm
from weblate_web.payments.models import Customer, Payment
from weblate_web.payments.validators import cache_vies_data, validate_vatin
Expand Down Expand Up @@ -503,7 +508,7 @@ def dispatch(self, request, *args, **kwargs):

# Get backend and refetch payment from the database
try:
backend = get_backend(self.object.backend)(self.object)
backend: Backend = get_backend(self.object.backend)(self.object)
except KeyError as error:
raise Http404("Non-existing backend") from error

Expand All @@ -516,6 +521,13 @@ def dispatch(self, request, *args, **kwargs):
backend.complete(self.request)
# If payment is still pending, display info page
if backend.payment.state == Payment.PENDING:
if backend.name == "fio-bank":
messages.info(
request,
gettext(
"New company, new bank details! Pay with attention to the current invoice."
),
)
return render(
request,
"payment/pending.html",
Expand Down

0 comments on commit ad1c397

Please sign in to comment.