JourneyJoker/payment/sepa/views.py

23 lines
825 B
Python
Raw Normal View History

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
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"
form_class = SepaApplyPaymentForm
2021-03-22 17:42:07 +00:00
success_url = reverse_lazy("sepa:apply")
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"])
messages.success(self.request, "Zahlung angewendet.")
return super().form_valid(form)