Fix create ticket endpoint (#7)
* create ticket when creating invoice not on check payment
---------
Co-authored-by: dni ⚡ <office@dnilabs.com>
This commit is contained in:
parent
13658ceda9
commit
1d57e1ae1a
2 changed files with 12 additions and 25 deletions
4
tasks.py
4
tasks.py
|
|
@ -28,9 +28,5 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
await api_ticket_send_ticket(
|
await api_ticket_send_ticket(
|
||||||
payment.memo,
|
payment.memo,
|
||||||
payment.payment_hash,
|
payment.payment_hash,
|
||||||
CreateTicket(
|
|
||||||
name=str(payment.extra.get("name")),
|
|
||||||
email=str(payment.extra.get("email")),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
27
views_api.py
27
views_api.py
|
|
@ -3,9 +3,8 @@ from http import HTTPStatus
|
||||||
from fastapi import Depends, Query
|
from fastapi import Depends, Query
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user, get_standalone_payment
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.core.views.api import api_payment
|
|
||||||
from lnbits.decorators import WalletTypeInfo, get_key_type
|
from lnbits.decorators import WalletTypeInfo, get_key_type
|
||||||
|
|
||||||
from . import events_ext
|
from . import events_ext
|
||||||
|
|
@ -110,13 +109,14 @@ async def api_ticket_make_ticket(event_id, name, email):
|
||||||
memo=f"{event_id}",
|
memo=f"{event_id}",
|
||||||
extra={"tag": "events", "name": name, "email": email},
|
extra={"tag": "events", "name": name, "email": email},
|
||||||
)
|
)
|
||||||
|
await create_ticket(payment_hash=payment_hash, wallet=event.wallet, event=event.id, name=name, email=email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
|
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
|
||||||
return {"payment_hash": payment_hash, "payment_request": payment_request}
|
return {"payment_hash": payment_hash, "payment_request": payment_request}
|
||||||
|
|
||||||
|
|
||||||
@events_ext.post("/api/v1/tickets/{event_id}/{payment_hash}")
|
@events_ext.post("/api/v1/tickets/{event_id}/{payment_hash}")
|
||||||
async def api_ticket_send_ticket(event_id, payment_hash, data: CreateTicket):
|
async def api_ticket_send_ticket(event_id, payment_hash):
|
||||||
event = await get_event(event_id)
|
event = await get_event(event_id)
|
||||||
if not event:
|
if not event:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -124,26 +124,17 @@ async def api_ticket_send_ticket(event_id, payment_hash, data: CreateTicket):
|
||||||
detail="Event could not be fetched.",
|
detail="Event could not be fetched.",
|
||||||
)
|
)
|
||||||
|
|
||||||
status = await api_payment(payment_hash)
|
ticket = await get_ticket(payment_hash)
|
||||||
if status["paid"]:
|
|
||||||
|
|
||||||
exists = await get_ticket(payment_hash)
|
|
||||||
if exists:
|
|
||||||
return {"paid": True, "ticket_id": exists.id}
|
|
||||||
|
|
||||||
ticket = await create_ticket(
|
|
||||||
payment_hash=payment_hash,
|
|
||||||
wallet=event.wallet,
|
|
||||||
event=event_id,
|
|
||||||
name=data.name,
|
|
||||||
email=data.email,
|
|
||||||
)
|
|
||||||
if not ticket:
|
if not ticket:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND,
|
status_code=HTTPStatus.NOT_FOUND,
|
||||||
detail="Event could not be fetched.",
|
detail="Ticket could not be fetched.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
payment = await get_standalone_payment(payment_hash)
|
||||||
|
if not payment.pending and event.price_per_ticket * 1000 == payment.amount:
|
||||||
return {"paid": True, "ticket_id": ticket.id}
|
return {"paid": True, "ticket_id": ticket.id}
|
||||||
|
|
||||||
return {"paid": False}
|
return {"paid": False}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue