def demopay(request, invoice_id, access_code): ''' Marks the invoice with the given invoice id as paid. ''' invoice_id = int(invoice_id) inv = get_object_or_404(rego.Invoice.objects, pk=invoice_id) 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: "******"This invoice was successfully paid.") return to_invoice
def demopay(request, invoice_id, access_code): ''' Marks the invoice with the given invoice id as paid. ''' invoice_id = int(invoice_id) inv = get_object_or_404(rego.Invoice.objects,pk=invoice_id) 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: "******"This invoice was successfully paid.") return to_invoice
def invoice(request, invoice_id, access_code=None): ''' Displays an invoice for a given invoice id. This view is not authenticated, but it will only allow access to either: the user the invoice belongs to; staff; or a request made with the correct access code. ''' invoice_id = int(invoice_id) inv = commerce.Invoice.objects.get(pk=invoice_id) current_invoice = InvoiceController(inv) if not current_invoice.can_view( user=request.user, access_code=access_code, ): raise Http404() data = { "invoice": current_invoice.invoice, } return render(request, "registrasion/invoice.html", data)