-
Notifications
You must be signed in to change notification settings - Fork 2
/
services.py
32 lines (26 loc) · 910 Bytes
/
services.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
import httpx
from .crud import get_form, update_form, update_ticket
from .models import Ticket
async def send_webhook(webhook: str, ticket: Ticket) -> None:
async with httpx.AsyncClient() as client:
await client.post(
webhook,
json={
"form": ticket.form,
"name": ticket.name,
"email": ticket.email,
"content": ticket.ltext,
},
timeout=6,
)
async def set_ticket_paid(ticket: Ticket) -> Ticket:
if not ticket.paid:
ticket.paid = True
await update_ticket(ticket)
formdata = await get_form(ticket.form)
assert formdata, "Couldn't get form from paid ticket"
formdata.amountmade += ticket.sats
await update_form(formdata)
if formdata.webhook:
await send_webhook(formdata.webhook, ticket)
return ticket