Skip to content

Commit 1d57e1a

Browse files
talvasconcelosdni
andauthored
Fix create ticket endpoint (#7)
* create ticket when creating invoice not on check payment --------- Co-authored-by: dni ⚡ <[email protected]>
1 parent 13658ce commit 1d57e1a

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

tasks.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,5 @@ async def on_invoice_paid(payment: Payment) -> None:
2828
await api_ticket_send_ticket(
2929
payment.memo,
3030
payment.payment_hash,
31-
CreateTicket(
32-
name=str(payment.extra.get("name")),
33-
email=str(payment.extra.get("email")),
34-
),
3531
)
3632
return

views_api.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from fastapi import Depends, Query
44
from starlette.exceptions import HTTPException
55

6-
from lnbits.core.crud import get_user
6+
from lnbits.core.crud import get_user, get_standalone_payment
77
from lnbits.core.services import create_invoice
8-
from lnbits.core.views.api import api_payment
98
from lnbits.decorators import WalletTypeInfo, get_key_type
109

1110
from . import events_ext
@@ -110,40 +109,32 @@ async def api_ticket_make_ticket(event_id, name, email):
110109
memo=f"{event_id}",
111110
extra={"tag": "events", "name": name, "email": email},
112111
)
112+
await create_ticket(payment_hash=payment_hash, wallet=event.wallet, event=event.id, name=name, email=email)
113113
except Exception as e:
114114
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
115115
return {"payment_hash": payment_hash, "payment_request": payment_request}
116116

117117

118118
@events_ext.post("/api/v1/tickets/{event_id}/{payment_hash}")
119-
async def api_ticket_send_ticket(event_id, payment_hash, data: CreateTicket):
119+
async def api_ticket_send_ticket(event_id, payment_hash):
120120
event = await get_event(event_id)
121121
if not event:
122122
raise HTTPException(
123123
status_code=HTTPStatus.NOT_FOUND,
124124
detail="Event could not be fetched.",
125125
)
126126

127-
status = await api_payment(payment_hash)
128-
if status["paid"]:
129-
130-
exists = await get_ticket(payment_hash)
131-
if exists:
132-
return {"paid": True, "ticket_id": exists.id}
133-
134-
ticket = await create_ticket(
135-
payment_hash=payment_hash,
136-
wallet=event.wallet,
137-
event=event_id,
138-
name=data.name,
139-
email=data.email,
127+
ticket = await get_ticket(payment_hash)
128+
if not ticket:
129+
raise HTTPException(
130+
status_code=HTTPStatus.NOT_FOUND,
131+
detail="Ticket could not be fetched.",
140132
)
141-
if not ticket:
142-
raise HTTPException(
143-
status_code=HTTPStatus.NOT_FOUND,
144-
detail="Event could not be fetched.",
145-
)
133+
134+
payment = await get_standalone_payment(payment_hash)
135+
if not payment.pending and event.price_per_ticket * 1000 == payment.amount:
146136
return {"paid": True, "ticket_id": ticket.id}
137+
147138
return {"paid": False}
148139

149140

0 commit comments

Comments
 (0)