|
3 | 3 | from fastapi import Depends, Query |
4 | 4 | from starlette.exceptions import HTTPException |
5 | 5 |
|
6 | | -from lnbits.core.crud import get_user |
| 6 | +from lnbits.core.crud import get_user, get_standalone_payment |
7 | 7 | from lnbits.core.services import create_invoice |
8 | | -from lnbits.core.views.api import api_payment |
9 | 8 | from lnbits.decorators import WalletTypeInfo, get_key_type |
10 | 9 |
|
11 | 10 | from . import events_ext |
@@ -110,40 +109,32 @@ async def api_ticket_make_ticket(event_id, name, email): |
110 | 109 | memo=f"{event_id}", |
111 | 110 | extra={"tag": "events", "name": name, "email": email}, |
112 | 111 | ) |
| 112 | + await create_ticket(payment_hash=payment_hash, wallet=event.wallet, event=event.id, name=name, email=email) |
113 | 113 | except Exception as e: |
114 | 114 | raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e)) |
115 | 115 | return {"payment_hash": payment_hash, "payment_request": payment_request} |
116 | 116 |
|
117 | 117 |
|
118 | 118 | @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): |
120 | 120 | event = await get_event(event_id) |
121 | 121 | if not event: |
122 | 122 | raise HTTPException( |
123 | 123 | status_code=HTTPStatus.NOT_FOUND, |
124 | 124 | detail="Event could not be fetched.", |
125 | 125 | ) |
126 | 126 |
|
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.", |
140 | 132 | ) |
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: |
146 | 136 | return {"paid": True, "ticket_id": ticket.id} |
| 137 | + |
147 | 138 | return {"paid": False} |
148 | 139 |
|
149 | 140 |
|
|
0 commit comments