-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
50 lines (40 loc) · 1.64 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from http import HTTPStatus
from fastapi import Depends, HTTPException, Query, Request
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
from lnbits.core.crud import get_standalone_payment
from lnbits.core.models import User, PaymentState
from lnbits.core.views.api import api_payment
from lnbits.decorators import check_user_exists
from . import partytap_ext, partytap_renderer
from .crud import get_payment
templates = Jinja2Templates(directory="templates")
@partytap_ext.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return partytap_renderer().TemplateResponse(
"partytap/index.html",
{"request": request, "user": user.dict()},
)
@partytap_ext.get(
"/{paymentid}", name="partytap.displaypin", response_class=HTMLResponse
)
async def displaypin(request: Request, paymentid: str):
partytap_payment = await get_payment(paymentid)
if not partytap_payment:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="No payment"
)
payment = await get_standalone_payment(partytap_payment.payhash)
if not payment:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Payment not found."
)
status = await payment.check_status()
if status.success:
return partytap_renderer().TemplateResponse(
"partytap/paid.html", {"request": request, "pin": partytap_payment.pin}
)
return partytap_renderer().TemplateResponse(
"partytap/error.html",
{"request": request, "pin": "filler", "not_paid": True},
)