From 94a42c100bbdc18180421d080fac1ef2b2961db4 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Thu, 7 Apr 2016 19:19:19 +1000 Subject: [PATCH] Adds manual payment functionality --- registrasion/forms.py | 7 +++++++ registrasion/urls.py | 5 ++++- registrasion/views.py | 34 ++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/registrasion/forms.py b/registrasion/forms.py index 47dacd3d..68c69d36 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -3,6 +3,13 @@ import models as rego from django import forms +class ManualPaymentForm(forms.ModelForm): + + class Meta: + model = rego.ManualPayment + fields = ["reference", "amount"] + + # Products forms -- none of these have any fields: they are to be subclassed # and the fields added as needs be. diff --git a/registrasion/urls.py b/registrasion/urls.py index 0620dafb..eb0606df 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -1,3 +1,5 @@ +import views + from django.conf.urls import url, patterns urlpatterns = patterns( @@ -5,7 +7,8 @@ urlpatterns = patterns( url(r"^category/([0-9]+)$", "product_category", name="product_category"), url(r"^checkout$", "checkout", name="checkout"), url(r"^invoice/([0-9]+)$", "invoice", name="invoice"), - url(r"^invoice/([0-9]+)/pay$", "pay_invoice", name="pay_invoice"), + url(r"^invoice/([0-9]+)/manual_payment$", + views.manual_payment, name="manual_payment"), url(r"^profile$", "edit_profile", name="attendee_edit"), url(r"^register$", "guided_registration", name="guided_registration"), url(r"^register/([0-9]+)$", "guided_registration", diff --git a/registrasion/views.py b/registrasion/views.py index b3f9212d..da8687cc 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -16,6 +16,7 @@ from django.contrib import messages from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ValidationError from django.http import Http404 +from django.shortcuts import get_object_or_404 from django.shortcuts import redirect from django.shortcuts import render @@ -443,15 +444,32 @@ def invoice(request, invoice_id): @login_required -def pay_invoice(request, invoice_id): - ''' Marks the invoice with the given invoice id as paid. - WORK IN PROGRESS FUNCTION. Must be replaced with real payment workflow. +def manual_payment(request, invoice_id): + ''' Allows staff to make manual payments or refunds on an invoice.''' + + FORM_PREFIX = "manual_payment" + + if not request.user.is_staff: + raise Http404() - ''' invoice_id = int(invoice_id) - inv = rego.Invoice.objects.get(pk=invoice_id) + inv = get_object_or_404(rego.Invoice, pk=invoice_id) current_invoice = InvoiceController(inv) - if not current_invoice.invoice.paid and not current_invoice.invoice.void: - current_invoice.pay("Demo invoice payment", inv.value) - return redirect("invoice", current_invoice.invoice.id) + form = forms.ManualPaymentForm( + request.POST or None, + prefix=FORM_PREFIX, + ) + + if request.POST and form.is_valid(): + form.instance.invoice = inv + form.save() + current_invoice.update_status() + form = forms.ManualPaymentForm(prefix=FORM_PREFIX) + + data = { + "invoice": inv, + "form": form, + } + + return render(request, "registrasion/manual_payment.html", data)