Added webhook for tickets

This commit is contained in:
benarc
2020-11-30 14:59:21 +00:00
parent 67e8c567a3
commit 16fff9899f
4 changed files with 30 additions and 14 deletions
+19 -4
View File
@@ -4,7 +4,7 @@ from lnbits.helpers import urlsafe_short_hash
from . import db
from .models import Tickets, Forms
import httpx
async def create_ticket(
payment_hash: str,
@@ -52,10 +52,25 @@ async def set_ticket_paid(payment_hash: str) -> Tickets:
""",
(amount, row[1]),
)
ticket = await get_ticket(payment_hash)
async with httpx.AsyncClient() as client:
try:
r = await client.post(
formdata.webhook,
json={
"form": ticket.form,
"name": ticket.name,
"email": ticket.email,
"comment": ticket.ltext
},
timeout=40,
)
except AssertionError:
webhook = None
return ticket
ticket = await get_ticket(payment_hash)
assert ticket, "Newly updated ticket couldn't be retrieved"
return ticket
return
async def get_ticket(ticket_id: str) -> Optional[Tickets]: