diff --git a/lnbits/extensions/jukebox/crud.py b/lnbits/extensions/jukebox/crud.py index f7a726a3a..c7a045f1d 100644 --- a/lnbits/extensions/jukebox/crud.py +++ b/lnbits/extensions/jukebox/crud.py @@ -1,7 +1,7 @@ from typing import List, Optional from . import db -from .models import Jukebox, JukeboxPayment, CreateJukeLinkData +from .models import Jukebox, JukeboxPayment, CreateJukeLinkData, CreateJukeboxPayment from lnbits.helpers import urlsafe_short_hash @@ -61,7 +61,6 @@ async def get_jukebox_by_user(user: str) -> Optional[Jukebox]: async def get_jukeboxs(user: str) -> List[Jukebox]: rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,)) for row in rows: - if row.sp_playlists == None: print("cunt") await delete_jukebox(row.id) @@ -82,22 +81,20 @@ async def delete_jukebox(juke_id: str): #####################################PAYMENTS -async def create_jukebox_payment( - song_id: str, payment_hash: str, juke_id: str -) -> JukeboxPayment: +async def create_jukebox_payment(data: CreateJukeboxPayment) -> JukeboxPayment: result = await db.execute( """ INSERT INTO jukebox.jukebox_payment (payment_hash, juke_id, song_id, paid) VALUES (?, ?, ?, ?) """, ( - payment_hash, - juke_id, - song_id, + data.payment_hash, + data.juke_id, + data.song_id, False, ), ) - jukebox_payment = await get_jukebox_payment(payment_hash) + jukebox_payment = await get_jukebox_payment(data.payment_hash) assert jukebox_payment, "Newly created Jukebox Payment couldn't be retrieved" return jukebox_payment diff --git a/lnbits/extensions/jukebox/models.py b/lnbits/extensions/jukebox/models.py index 6cb49a5e7..093961e42 100644 --- a/lnbits/extensions/jukebox/models.py +++ b/lnbits/extensions/jukebox/models.py @@ -40,3 +40,11 @@ class JukeboxPayment(BaseModel): juke_id: str song_id: str paid: bool + + +class CreateJukeboxPayment(BaseModel): + invoice: str = Query(None) + payment_hash: str = Query(None) + juke_id: str = Query(None) + song_id: str = Query(None) + paid: bool = Query(False) diff --git a/lnbits/extensions/jukebox/templates/jukebox/jukebox.html b/lnbits/extensions/jukebox/templates/jukebox/jukebox.html index 6a49f7c4d..2791f09ef 100644 --- a/lnbits/extensions/jukebox/templates/jukebox/jukebox.html +++ b/lnbits/extensions/jukebox/templates/jukebox/jukebox.html @@ -157,8 +157,9 @@ song_id ) .then(function (response) { - self.receive.paymentReq = response.data[0][1] - self.receive.paymentHash = response.data[0][0] + console.log(response.data) + self.receive.paymentReq = response.data.invoice + self.receive.paymentHash = response.data.payment_hash self.receive.dialogues.second = true dialog.data = response.data @@ -187,8 +188,10 @@ self.receive.paymentHash ) .then(function (ress) { + console.log('ress') console.log(ress) - if (ress.data[2] == self.receive.id) { + console.log('ress') + if (ress.data.song_id == self.receive.id) { clearInterval(dialog.paymentChecker) dialog.dismissMsg() self.receive.dialogues.second = false diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py index c58f76cd3..4f2940d38 100644 --- a/lnbits/extensions/jukebox/views_api.py +++ b/lnbits/extensions/jukebox/views_api.py @@ -9,7 +9,7 @@ import json from typing import Optional from fastapi.params import Depends from fastapi.param_functions import Query -from .models import CreateJukeLinkData +from .models import CreateJukeLinkData, CreateJukeboxPayment from lnbits.decorators import ( check_user_exists, WalletTypeInfo, @@ -258,10 +258,7 @@ async def api_get_jukebox_device_check( @jukebox_ext.get("/api/v1/jukebox/jb/invoice/{juke_id}/{song_id}") -async def api_get_jukebox_invoice( - juke_id: str = Query(None), - song_id: str = Query(None), -): +async def api_get_jukebox_invoice(juke_id, song_id): try: jukebox = await get_jukebox(juke_id) print(jukebox) @@ -271,6 +268,7 @@ async def api_get_jukebox_invoice( detail="No jukebox", ) try: + devices = await api_get_jukebox_device_check(juke_id) deviceConnected = False for device in devices["devices"]: @@ -294,9 +292,14 @@ async def api_get_jukebox_invoice( extra={"tag": "jukebox"}, ) - jukebox_payment = await create_jukebox_payment(song_id, invoice[0], juke_id) + payment_hash = invoice[0] + data = CreateJukeboxPayment( + invoice=invoice[1], payment_hash=payment_hash, juke_id=juke_id, song_id=song_id + ) + jukebox_payment = await create_jukebox_payment(data) + print(data) - return {invoice, jukebox_payment} + return data @jukebox_ext.get("/api/v1/jukebox/jb/checkinvoice/{pay_hash}/{juke_id}") @@ -368,7 +371,7 @@ async def api_get_jukebox_invoice_paid( headers={"Authorization": "Bearer " + jukebox.sp_access_token}, ) if r.status_code == 204: - return jsonify(jukebox_payment), HTTPStatus.OK + return jukebox_payment elif r.status_code == 401 or r.status_code == 403: token = await api_get_token(juke_id) if token == False: