extra fields on apipayments + index payments by payment_hash
This commit is contained in:
@@ -9,31 +9,31 @@ from .models import Tickets, Events
|
||||
#######TICKETS########
|
||||
|
||||
|
||||
def create_ticket(checking_id: str, wallet: str, event: str, name: str, email: str) -> Tickets:
|
||||
def create_ticket(payment_hash: str, wallet: str, event: str, name: str, email: str) -> Tickets:
|
||||
with open_ext_db("events") as db:
|
||||
db.execute(
|
||||
"""
|
||||
INSERT INTO ticket (id, wallet, event, name, email, registered, paid)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(checking_id, wallet, event, name, email, False, False),
|
||||
(payment_hash, wallet, event, name, email, False, False),
|
||||
)
|
||||
|
||||
return get_ticket(checking_id)
|
||||
return get_ticket(payment_hash)
|
||||
|
||||
|
||||
def update_ticket(paid: bool, checking_id: str) -> Tickets:
|
||||
def update_ticket(paid: bool, payment_hash: str) -> Tickets:
|
||||
with open_ext_db("events") as db:
|
||||
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (checking_id,))
|
||||
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (payment_hash,))
|
||||
if row[6] == True:
|
||||
return get_ticket(checking_id)
|
||||
return get_ticket(payment_hash)
|
||||
db.execute(
|
||||
"""
|
||||
UPDATE ticket
|
||||
SET paid = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(paid, checking_id),
|
||||
(paid, payment_hash),
|
||||
)
|
||||
|
||||
eventdata = get_event(row[2])
|
||||
@@ -47,12 +47,12 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
|
||||
""",
|
||||
(sold, amount_tickets, row[2]),
|
||||
)
|
||||
return get_ticket(checking_id)
|
||||
return get_ticket(payment_hash)
|
||||
|
||||
|
||||
def get_ticket(checking_id: str) -> Optional[Tickets]:
|
||||
def get_ticket(payment_hash: str) -> Optional[Tickets]:
|
||||
with open_ext_db("events") as db:
|
||||
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (checking_id,))
|
||||
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (payment_hash,))
|
||||
|
||||
return Tickets(**row) if row else None
|
||||
|
||||
@@ -68,9 +68,9 @@ def get_tickets(wallet_ids: Union[str, List[str]]) -> List[Tickets]:
|
||||
return [Tickets(**row) for row in rows]
|
||||
|
||||
|
||||
def delete_ticket(checking_id: str) -> None:
|
||||
def delete_ticket(payment_hash: str) -> None:
|
||||
with open_ext_db("events") as db:
|
||||
db.execute("DELETE FROM ticket WHERE id = ?", (checking_id,))
|
||||
db.execute("DELETE FROM ticket WHERE id = ?", (payment_hash,))
|
||||
|
||||
|
||||
########EVENTS#########
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
)
|
||||
.then(function (response) {
|
||||
self.paymentReq = response.data.payment_request
|
||||
self.paymentCheck = response.data.checking_id
|
||||
self.paymentCheck = response.data.payment_hash
|
||||
|
||||
dismissMsg = self.$q.notify({
|
||||
timeout: 0,
|
||||
|
||||
@@ -2,9 +2,8 @@ from flask import g, jsonify, request
|
||||
from http import HTTPStatus
|
||||
|
||||
from lnbits.core.crud import get_user, get_wallet
|
||||
from lnbits.core.services import create_invoice
|
||||
from lnbits.core.services import create_invoice, check_invoice_status
|
||||
from lnbits.decorators import api_check_wallet_key, api_validate_post_request
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
from lnbits.extensions.events import events_ext
|
||||
from .crud import (
|
||||
@@ -108,39 +107,37 @@ def api_tickets():
|
||||
}
|
||||
)
|
||||
def api_ticket_make_ticket(event_id, sats):
|
||||
|
||||
event = get_event(event_id)
|
||||
|
||||
if not event:
|
||||
return jsonify({"message": "LNTicket does not exist."}), HTTPStatus.NOT_FOUND
|
||||
try:
|
||||
checking_id, payment_request = create_invoice(
|
||||
payment_hash, payment_request = create_invoice(
|
||||
wallet_id=event.wallet, amount=int(sats), memo=f"#lnticket {event_id}"
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"message": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
ticket = create_ticket(checking_id=checking_id, wallet=event.wallet, event=event_id, **g.data)
|
||||
ticket = create_ticket(payment_hash=payment_hash, wallet=event.wallet, event=event_id, **g.data)
|
||||
|
||||
if not ticket:
|
||||
return jsonify({"message": "LNTicket could not be fetched."}), HTTPStatus.NOT_FOUND
|
||||
|
||||
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), HTTPStatus.OK
|
||||
return jsonify({"payment_hash": payment_hash, "payment_request": payment_request}), HTTPStatus.OK
|
||||
|
||||
|
||||
@events_ext.route("/api/v1/tickets/<checking_id>", methods=["GET"])
|
||||
def api_ticket_send_ticket(checking_id):
|
||||
theticket = get_ticket(checking_id)
|
||||
@events_ext.route("/api/v1/tickets/<payment_hash>", methods=["GET"])
|
||||
def api_ticket_send_ticket(payment_hash):
|
||||
ticket = get_ticket(payment_hash)
|
||||
try:
|
||||
is_paid = not WALLET.get_invoice_status(checking_id).pending
|
||||
is_paid = not check_invoice_status(ticket.wallet, payment_hash).pending
|
||||
except Exception:
|
||||
return jsonify({"message": "Not paid."}), HTTPStatus.NOT_FOUND
|
||||
|
||||
if is_paid:
|
||||
wallet = get_wallet(theticket.wallet)
|
||||
payment = wallet.get_payment(checking_id)
|
||||
wallet = get_wallet(ticket.wallet)
|
||||
payment = wallet.get_payment(payment_hash)
|
||||
payment.set_pending(False)
|
||||
ticket = update_ticket(paid=True, checking_id=checking_id)
|
||||
ticket = update_ticket(paid=True, payment_hash=payment_hash)
|
||||
|
||||
return jsonify({"paid": True, "ticket_id": ticket.id}), HTTPStatus.OK
|
||||
|
||||
|
||||
Reference in New Issue
Block a user