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