Adds manual payment functionality
This commit is contained in:
parent
2fbe789090
commit
94a42c100b
3 changed files with 37 additions and 9 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue