from django.views.generic import FormView from django.shortcuts import get_object_or_404 from django.contrib import messages from django.urls import reverse_lazy from localauth.mixins import SuperUserRequiredMixin from .forms import SepaApplyPaymentForm from .models import SepaPaymentReference, SepaInvoicePayment class SepaApplyPaymentView(SuperUserRequiredMixin, FormView): template_name = "payment/sepa/apply.html" form_class = SepaApplyPaymentForm success_url = reverse_lazy("sepa:apply") def form_valid(self, form): reference = form.cleaned_data["reference"] pr = get_object_or_404(SepaPaymentReference, reference=reference) pr.create_payment(form.cleaned_data["amount"]) messages.success(self.request, "Zahlung angewendet.") return super().form_valid(form)