mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 14:51:05 +01:00
* initial commit * add docs * black & prettier * mobile styles * add print view * prettier * make format * initial migrations un-messed * make migrations work for sqlite * add invoices table * clean migrations * add migration to conv * fix card size * hopefully fix test migration * add missing status * timestamp * init testing * remove draft invoice by default on create * what should i test * make format * raise if not invoice * new test and renaming * fix issue reported by @talvasconcelos which prevented users from setting status on creation * readme * run black * trying to make tests work * make it work again * send paid amount * partial pay flow * good coding * can't get these test to work * clean up and commenting * make format * validation for 2 decimals Co-authored-by: ben <ben@arc.wales> Co-authored-by: Tiago vasconcelos <talvasconcelos@gmail.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
from datetime import datetime
|
|
from http import HTTPStatus
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.params import Depends
|
|
from fastapi.templating import Jinja2Templates
|
|
from starlette.exceptions import HTTPException
|
|
from starlette.responses import HTMLResponse
|
|
|
|
from lnbits.core.models import User
|
|
from lnbits.decorators import check_user_exists
|
|
|
|
from . import invoices_ext, invoices_renderer
|
|
from .crud import (
|
|
get_invoice,
|
|
get_invoice_items,
|
|
get_invoice_payments,
|
|
get_invoice_total,
|
|
get_payments_total,
|
|
)
|
|
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
|
|
@invoices_ext.get("/", response_class=HTMLResponse)
|
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
|
return invoices_renderer().TemplateResponse(
|
|
"invoices/index.html", {"request": request, "user": user.dict()}
|
|
)
|
|
|
|
|
|
@invoices_ext.get("/pay/{invoice_id}", response_class=HTMLResponse)
|
|
async def index(request: Request, invoice_id: str):
|
|
invoice = await get_invoice(invoice_id)
|
|
|
|
if not invoice:
|
|
raise HTTPException(
|
|
status_code=HTTPStatus.NOT_FOUND, detail="Invoice does not exist."
|
|
)
|
|
|
|
invoice_items = await get_invoice_items(invoice_id)
|
|
invoice_total = await get_invoice_total(invoice_items)
|
|
|
|
invoice_payments = await get_invoice_payments(invoice_id)
|
|
payments_total = await get_payments_total(invoice_payments)
|
|
|
|
return invoices_renderer().TemplateResponse(
|
|
"invoices/pay.html",
|
|
{
|
|
"request": request,
|
|
"invoice_id": invoice_id,
|
|
"invoice": invoice.dict(),
|
|
"invoice_items": invoice_items,
|
|
"invoice_total": invoice_total,
|
|
"invoice_payments": invoice_payments,
|
|
"payments_total": payments_total,
|
|
"datetime": datetime,
|
|
},
|
|
)
|