2016-03-30 04:13:50 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
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 registrasion import models as rego
|
|
|
|
from registrasion.controllers.invoice import InvoiceController
|
|
|
|
|
2017-04-29 04:28:48 +00:00
|
|
|
from pinaxcon.registrasion import models
|
2016-03-30 04:13:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def demopay(request, invoice_id, access_code):
|
|
|
|
''' Marks the invoice with the given invoice id as paid.
|
|
|
|
'''
|
|
|
|
invoice_id = int(invoice_id)
|
2017-03-05 07:34:15 +00:00
|
|
|
inv = get_object_or_404(rego.Invoice.objects, pk=invoice_id)
|
2016-03-30 04:13:50 +00:00
|
|
|
|
|
|
|
invoice = InvoiceController(inv)
|
|
|
|
|
|
|
|
if not invoice.can_view(user=request.user, access_code=access_code):
|
|
|
|
raise Http404()
|
|
|
|
|
|
|
|
to_invoice = redirect("invoice", invoice.invoice.id, access_code)
|
|
|
|
|
|
|
|
try:
|
|
|
|
invoice.validate_allowed_to_pay() # Verify that we're allowed to do this.
|
|
|
|
except ValidationError as ve:
|
|
|
|
messages.error(request, ve.message)
|
|
|
|
return to_invoice
|
|
|
|
|
|
|
|
# Create the payment object
|
|
|
|
models.DemoPayment.objects.create(
|
|
|
|
invoice=invoice.invoice,
|
|
|
|
reference="Demo payment by user: " + request.user.username,
|
|
|
|
amount=invoice.invoice.value,
|
|
|
|
)
|
|
|
|
|
|
|
|
invoice.update_status()
|
|
|
|
|
|
|
|
messages.success(request, "This invoice was successfully paid.")
|
|
|
|
|
|
|
|
return to_invoice
|