From e03370188a57744e08f3eecf6c5ca8da31fd4577 Mon Sep 17 00:00:00 2001
From: benarc Curl example
curl {{ request.url_root }}api/v1/wallet -H "X-Api-Key:
+ >curl {{ request.base_url }}api/v1/wallet -H "X-Api-Key:
{{ wallet.inkey }}"
@@ -59,7 +59,7 @@
>
Curl example
curl -X POST {{ request.url_root }}api/v1/payments -d '{"out": false,
+ >curl -X POST {{ request.base_url }}api/v1/payments -d '{"out": false,
"amount": <int>, "memo": <string>, "webhook":
<url:string>}' -H "X-Api-Key: {{ wallet.inkey }}" -H
"Content-type: application/json"
{"payment_hash": <string>}
Curl example
curl -X POST {{ request.url_root }}api/v1/payments -d '{"out": true,
+ >curl -X POST {{ request.base_url }}api/v1/payments -d '{"out": true,
"bolt11": <string>}' -H "X-Api-Key:
{{ wallet.adminkey }}" -H "Content-type:
application/json"
Curl example
curl -X POST {{ request.url_root }}api/v1/payments/decode -d
+ >curl -X POST {{ request.base_url }}api/v1/payments/decode -d
'{"data": <bolt11/lnurl, string>}' -H "X-Api-Key:
{{ wallet.inkey }}" -H "Content-type: application/json"
@@ -144,7 +144,7 @@
{"paid": <bool>}
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/payments/<payment_hash> -H "X-Api-Key:
{{ wallet.inkey }}" -H "Content-type: application/json"
diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html
index 7a3b6dca1..deca6cbbb 100644
--- a/lnbits/core/templates/core/wallet.html
+++ b/lnbits/core/templates/core/wallet.html
@@ -270,22 +270,24 @@
can scan it from your phone to open your wallet from there.
- {{ parse.lnurlpay.targetUser || parse.lnurlpay.domain }} is requesting
+ {{ parse.lnurlpay.targetUser || parse.lnurlpay.domain }} is
+ requesting
between {{ parse.lnurlpay.minSendable | msatoshiFormat }} and
{{ parse.lnurlpay.maxSendable | msatoshiFormat }} sat
diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py
index 8853bc081..95d32cb1f 100644
--- a/lnbits/core/views/api.py
+++ b/lnbits/core/views/api.py
@@ -27,7 +27,12 @@ from lnbits.requestvars import g
from lnbits.utils.exchange_rates import currencies, fiat_amount_as_satoshis
from .. import core_app, db
-from ..crud import get_payments, save_balance_check, update_wallet
+from ..crud import (
+ get_payments,
+ save_balance_check,
+ update_wallet,
+ get_standalone_payment,
+)
from ..services import (
InvoiceFailure,
PaymentFailure,
@@ -318,9 +323,11 @@ async def api_payments_sse(
@core_app.get("/api/v1/payments/{payment_hash}")
-async def api_payment(payment_hash, wallet: WalletTypeInfo = Depends(get_key_type)):
- payment = await wallet.wallet.get_payment(payment_hash)
+async def api_payment(payment_hash):
+ payment = await get_standalone_payment(payment_hash)
+ await check_invoice_status(payment.wallet_id, payment_hash)
+ payment = await get_standalone_payment(payment_hash)
if not payment:
return {"message": "Payment does not exist."}
elif not payment.pending:
diff --git a/lnbits/extensions/copilot/templates/copilot/_api_docs.html b/lnbits/extensions/copilot/templates/copilot/_api_docs.html
index 9cbb99cb7..64acba148 100644
--- a/lnbits/extensions/copilot/templates/copilot/_api_docs.html
+++ b/lnbits/extensions/copilot/templates/copilot/_api_docs.html
@@ -31,7 +31,7 @@
[<copilot_object>, ...]
Curl example
curl -X POST {{ request.url_root }}api/v1/copilot -d '{"title":
+ >curl -X POST {{ request.base_url }}api/v1/copilot -d '{"title":
<string>, "animation": <string>,
"show_message":<string>, "amount": <integer>,
"lnurl_title": <string>}' -H "Content-type: application/json"
@@ -58,7 +58,7 @@
[<copilot_object>, ...]
Curl example
curl -X POST {{ request.url_root
+ >curl -X POST {{ request.base_url
}}api/v1/copilot/<copilot_id> -d '{"title": <string>,
"animation": <string>, "show_message":<string>,
"amount": <integer>, "lnurl_title": <string>}' -H
@@ -87,7 +87,7 @@
[<copilot_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/copilot/<copilot_id>
+ >curl -X GET {{ request.base_url }}api/v1/copilot/<copilot_id>
-H "X-Api-Key: {{ user.wallets[0].inkey }}"
[<copilot_object>, ...]
curl -X GET {{ request.url_root }}api/v1/copilots -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/copilots -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -135,7 +135,7 @@
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}api/v1/copilot/<copilot_id> -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -161,7 +161,7 @@
curl -X GET {{ request.url_root }}/api/v1/copilot/ws/<string,
+ >curl -X GET {{ request.base_url }}/api/v1/copilot/ws/<string,
copilot_id>/<string, comment>/<string, gif name> -H
"X-Api-Key: {{ user.wallets[0].adminkey }}"
diff --git a/lnbits/extensions/events/views_api.py b/lnbits/extensions/events/views_api.py
index 4ff93c31e..4040babba 100644
--- a/lnbits/extensions/events/views_api.py
+++ b/lnbits/extensions/events/views_api.py
@@ -7,6 +7,7 @@ from starlette.requests import Request
from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import check_invoice_status, create_invoice
+from lnbits.core.views.api import api_payment
from lnbits.decorators import WalletTypeInfo, get_key_type
from lnbits.extensions.events.models import CreateEvent, CreateTicket
@@ -43,21 +44,22 @@ async def api_events(
return [event.dict() for event in await get_events(wallet_ids)]
+
@events_ext.post("/api/v1/events")
@events_ext.put("/api/v1/events/{event_id}")
-async def api_event_create(data: CreateEvent, event_id=None, wallet: WalletTypeInfo = Depends(get_key_type)):
+async def api_event_create(
+ data: CreateEvent, event_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
+):
if event_id:
event = await get_event(event_id)
if not event:
raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail=f"Event does not exist."
+ status_code=HTTPStatus.NOT_FOUND, detail=f"Event does not exist."
)
if event.wallet != wallet.wallet.id:
raise HTTPException(
- status_code=HTTPStatus.FORBIDDEN,
- detail=f"Not your event."
+ status_code=HTTPStatus.FORBIDDEN, detail=f"Not your event."
)
event = await update_event(event_id, **data.dict())
else:
@@ -70,16 +72,12 @@ async def api_event_create(data: CreateEvent, event_id=None, wallet: WalletTypeI
async def api_form_delete(event_id, wallet: WalletTypeInfo = Depends(get_key_type)):
event = await get_event(event_id)
if not event:
- raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail=f"Event does not exist."
- )
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND, detail=f"Event does not exist."
+ )
if event.wallet != wallet.wallet.id:
- raise HTTPException(
- status_code=HTTPStatus.FORBIDDEN,
- detail=f"Not your event."
- )
+ raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail=f"Not your event.")
await delete_event(event_id)
await delete_event_tickets(event_id)
@@ -107,10 +105,9 @@ async def api_tickets(
async def api_ticket_make_ticket(event_id, sats, data: CreateTicket):
event = await get_event(event_id)
if not event:
- raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail=f"Event does not exist."
- )
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND, detail=f"Event does not exist."
+ )
try:
payment_hash, payment_request = await create_invoice(
wallet_id=event.wallet,
@@ -122,14 +119,17 @@ async def api_ticket_make_ticket(event_id, sats, data: CreateTicket):
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
ticket = await create_ticket(
- payment_hash=payment_hash, wallet=event.wallet, event=event_id, name=data.name, email=data.email
+ payment_hash=payment_hash,
+ wallet=event.wallet,
+ event=event_id,
+ name=data.name,
+ email=data.email,
)
if not ticket:
raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail=f"Event could not be fetched."
- )
+ status_code=HTTPStatus.NOT_FOUND, detail=f"Event could not be fetched."
+ )
return {"payment_hash": payment_hash, "payment_request": payment_request}
@@ -139,20 +139,12 @@ async def api_ticket_send_ticket(payment_hash):
ticket = await get_ticket(payment_hash)
try:
- status = await check_invoice_status(ticket.wallet, payment_hash)
- is_paid = not status.pending
-
+ status = await api_payment(payment_hash)
+ if status["paid"]:
+ await set_ticket_paid(payment_hash=payment_hash)
+ return {"paid": True, "ticket_id": ticket.id}
except Exception:
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Not paid")
-
- if is_paid:
- wallet = await get_wallet(ticket.wallet)
- payment = await wallet.get_payment(payment_hash)
- await payment.set_pending(False)
- ticket = await set_ticket_paid(payment_hash=payment_hash)
-
- return {"paid": True, "ticket_id": ticket.id}
-
return {"paid": False}
@@ -160,33 +152,28 @@ async def api_ticket_send_ticket(payment_hash):
async def api_ticket_delete(ticket_id, wallet: WalletTypeInfo = Depends(get_key_type)):
ticket = await get_ticket(ticket_id)
if not ticket:
- raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail=f"Ticket does not exist."
- )
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND, detail=f"Ticket does not exist."
+ )
if ticket.wallet != wallet.wallet.id:
raise HTTPException(
- status_code=HTTPStatus.FORBIDDEN,
- detail=f"Not your ticket."
+ status_code=HTTPStatus.FORBIDDEN, detail=f"Not your ticket."
)
await delete_ticket(ticket_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
-
# Event Tickets
@events_ext.get("/api/v1/eventtickets/{wallet_id}/{event_id}")
async def api_event_tickets(wallet_id, event_id):
return [
- ticket.dict()
- for ticket in await get_event_tickets(
- wallet_id=wallet_id, event_id=event_id
- )
- ]
+ ticket.dict()
+ for ticket in await get_event_tickets(wallet_id=wallet_id, event_id=event_id)
+ ]
@events_ext.get("/api/v1/register/ticket/{ticket_id}")
@@ -194,20 +181,17 @@ async def api_event_register_ticket(ticket_id):
ticket = await get_ticket(ticket_id)
if not ticket:
raise HTTPException(
- status_code=HTTPStatus.NOT_FOUND,
- detail="Ticket does not exist."
+ status_code=HTTPStatus.NOT_FOUND, detail="Ticket does not exist."
)
if not ticket.paid:
raise HTTPException(
- status_code=HTTPStatus.FORBIDDEN,
- detail="Ticket not paid for."
+ status_code=HTTPStatus.FORBIDDEN, detail="Ticket not paid for."
)
if ticket.registered == True:
raise HTTPException(
- status_code=HTTPStatus.FORBIDDEN,
- detail="Ticket already registered"
+ status_code=HTTPStatus.FORBIDDEN, detail="Ticket already registered"
)
return [ticket.dict() for ticket in await reg_ticket(ticket_id)]
diff --git a/lnbits/extensions/jukebox/templates/jukebox/_api_docs.html b/lnbits/extensions/jukebox/templates/jukebox/_api_docs.html
index b1968b486..791a55e71 100644
--- a/lnbits/extensions/jukebox/templates/jukebox/_api_docs.html
+++ b/lnbits/extensions/jukebox/templates/jukebox/_api_docs.html
@@ -37,7 +37,7 @@
[<jukebox_object>, ...]
curl -X GET {{ request.url_root }}api/v1/jukebox -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/jukebox -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -59,7 +59,7 @@
<jukebox_object>
curl -X GET {{ request.url_root }}api/v1/jukebox/<juke_id> -H
+ >curl -X GET {{ request.base_url }}api/v1/jukebox/<juke_id> -H
"X-Api-Key: {{ user.wallets[0].adminkey }}"
@@ -86,7 +86,7 @@
<jukbox_object>
curl -X POST {{ request.url_root }}api/v1/jukebox/ -d '{"user":
+ >curl -X POST {{ request.base_url }}api/v1/jukebox/ -d '{"user":
<string, user_id>, "title": <string>,
"wallet":<string>, "sp_user": <string,
spotify_user_account>, "sp_secret": <string,
@@ -116,7 +116,7 @@
<jukebox_object>
Curl example
curl -X DELETE {{ request.url_root }}api/v1/jukebox/<juke_id>
+ >curl -X DELETE {{ request.base_url }}api/v1/jukebox/<juke_id>
-H "X-Api-Key: {{ user.wallets[0].adminkey }}"
diff --git a/lnbits/extensions/jukebox/views_api.py b/lnbits/extensions/jukebox/views_api.py
index ed92efc9e..dc9e97194 100644
--- a/lnbits/extensions/jukebox/views_api.py
+++ b/lnbits/extensions/jukebox/views_api.py
@@ -10,6 +10,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse # type: ignore
from lnbits.core.crud import get_wallet
+from lnbits.core.views.api import api_payment
from lnbits.core.services import check_invoice_status, create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
@@ -95,7 +96,9 @@ async def api_create_update_jukebox(
@jukebox_ext.delete("/api/v1/jukebox/{juke_id}")
-async def api_delete_item(juke_id=None, wallet: WalletTypeInfo = Depends(require_admin_key)):
+async def api_delete_item(
+ juke_id=None, wallet: WalletTypeInfo = Depends(require_admin_key)
+):
await delete_jukebox(juke_id)
try:
return [{**jukebox} for jukebox in await get_jukeboxs(wallet.wallet.user)]
@@ -276,20 +279,17 @@ async def api_get_jukebox_invoice_check(
pay_hash: str = Query(None), juke_id: str = Query(None)
):
try:
- jukebox = await get_jukebox(juke_id)
+ await get_jukebox(juke_id)
except:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox")
try:
- status = await check_invoice_status(jukebox.wallet, pay_hash)
- is_paid = not status.pending
+ status = await api_payment(pay_hash)
+ if status["paid"]:
+ await update_jukebox_payment(pay_hash, paid=True)
+ return {"paid": True}
except:
return {"paid": False}
- if is_paid:
- wallet = await get_wallet(jukebox.wallet)
- payment = await wallet.get_payment(pay_hash)
- await payment.set_pending(False)
- await update_jukebox_payment(pay_hash, paid=True)
- return {"paid": True}
+
return {"paid": False}
diff --git a/lnbits/extensions/lnticket/views_api.py b/lnbits/extensions/lnticket/views_api.py
index caf39708a..a83a25883 100644
--- a/lnbits/extensions/lnticket/views_api.py
+++ b/lnbits/extensions/lnticket/views_api.py
@@ -9,6 +9,7 @@ from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import HTMLResponse, JSONResponse # type: ignore
+from lnbits.core.views.api import api_payment
from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import check_invoice_status, create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type
@@ -169,19 +170,15 @@ async def api_ticket_make_ticket(data: CreateTicketData, form_id):
@lnticket_ext.get("/api/v1/tickets/{payment_hash}", status_code=HTTPStatus.OK)
async def api_ticket_send_ticket(payment_hash):
ticket = await get_ticket(payment_hash)
+
try:
- status = await check_invoice_status(ticket.wallet, payment_hash)
- is_paid = not status.pending
+ status = await api_payment(payment_hash)
+ if status["paid"]:
+ await set_ticket_paid(payment_hash=payment_hash)
+ return {"paid": True}
except Exception:
return {"paid": False}
- if is_paid:
- wallet = await get_wallet(ticket.wallet)
- payment = await wallet.get_payment(payment_hash)
- await payment.set_pending(False)
- ticket = await set_ticket_paid(payment_hash=payment_hash)
- return {"paid": True}
-
return {"paid": False}
diff --git a/lnbits/extensions/lnurlp/templates/lnurlp/_api_docs.html b/lnbits/extensions/lnurlp/templates/lnurlp/_api_docs.html
index 6bea55945..80d1478d2 100644
--- a/lnbits/extensions/lnurlp/templates/lnurlp/_api_docs.html
+++ b/lnbits/extensions/lnurlp/templates/lnurlp/_api_docs.html
@@ -17,7 +17,7 @@
[<pay_link_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/links -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/links -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -39,7 +39,7 @@
{"lnurl": <string>}
Curl example
curl -X GET {{ request.url_root }}api/v1/links/<pay_id> -H
+ >curl -X GET {{ request.base_url }}api/v1/links/<pay_id> -H
"X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -68,7 +68,7 @@
{"lnurl": <string>}
Curl example
curl -X POST {{ request.url_root }}api/v1/links -d '{"description":
+ >curl -X POST {{ request.base_url }}api/v1/links -d '{"description":
<string>, "amount": <integer>, "max": <integer>,
"min": <integer>, "comment_chars": <integer>}' -H
"Content-type: application/json" -H "X-Api-Key: {{
@@ -99,7 +99,7 @@
{"lnurl": <string>}
Curl example
curl -X PUT {{ request.url_root }}api/v1/links/<pay_id> -d
+ >curl -X PUT {{ request.base_url }}api/v1/links/<pay_id> -d
'{"description": <string>, "amount": <integer>}' -H
"Content-type: application/json" -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -126,7 +126,7 @@
Curl example
curl -X DELETE {{ request.url_root }}api/v1/links/<pay_id> -H
+ >curl -X DELETE {{ request.base_url }}api/v1/links/<pay_id> -H
"X-Api-Key: {{ user.wallets[0].adminkey }}"
diff --git a/lnbits/extensions/lnurlpos/templates/lnurlpos/_api_docs.html b/lnbits/extensions/lnurlpos/templates/lnurlpos/_api_docs.html
index 071d6d6ca..c4960d64d 100644
--- a/lnbits/extensions/lnurlpos/templates/lnurlpos/_api_docs.html
+++ b/lnbits/extensions/lnurlpos/templates/lnurlpos/_api_docs.html
@@ -39,7 +39,7 @@
[<lnurlpos_object>, ...]
Curl example
curl -X POST {{ request.url_root }}api/v1/lnurlpos -d '{"title":
+ >curl -X POST {{ request.base_url }}api/v1/lnurlpos -d '{"title":
<string>, "message":<string>, "currency":
<integer>}' -H "Content-type: application/json" -H "X-Api-Key:
{{user.wallets[0].adminkey }}"
@@ -70,7 +70,7 @@
[<lnurlpos_object>, ...]
Curl example
curl -X POST {{ request.url_root
+ >curl -X POST {{ request.base_url
}}api/v1/lnurlpos/<lnurlpos_id> -d ''{"title": <string>,
"message":<string>, "currency": <integer>} -H
"Content-type: application/json" -H "X-Api-Key:
@@ -98,7 +98,7 @@
[<lnurlpos_object>, ...]
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/lnurlpos/<lnurlpos_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -122,7 +122,7 @@
[<lnurlpos_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/lnurlposs -H "X-Api-Key:
+ >curl -X GET {{ request.base_url }}api/v1/lnurlposs -H "X-Api-Key:
{{ user.wallets[0].inkey }}"
@@ -147,7 +147,7 @@
Curl example
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}api/v1/lnurlpos/<lnurlpos_id> -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
diff --git a/lnbits/extensions/lnurlpos/views.py b/lnbits/extensions/lnurlpos/views.py
index 68e4ef06a..c8ac47243 100644
--- a/lnbits/extensions/lnurlpos/views.py
+++ b/lnbits/extensions/lnurlpos/views.py
@@ -9,6 +9,7 @@ from lnbits.core.crud import get_standalone_payment
import hashlib
from lnbits.core.services import check_invoice_status
from lnbits.core.crud import update_payment_status
+from lnbits.core.views.api import api_payment
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
@@ -44,17 +45,13 @@ async def displaypin(request: Request, paymentid: str = Query(None)):
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="lnurlpos not found."
)
-
- status = await check_invoice_status(pos.wallet, lnurlpospayment.payhash)
-
- is_paid = not status.pending
- if not is_paid:
+ status = await api_payment(lnurlpospayment.payhash)
+ if status["paid"]:
+ await update_payment_status(checking_id=lnurlpospayment.payhash, pending=True)
return lnurlpos_renderer().TemplateResponse(
- "lnurlpos/error.html",
- {"request": request, "pin": "filler", "not_paid": True},
+ "lnurlpos/paid.html", {"request": request, "pin": lnurlpospayment.pin}
)
-
- await update_payment_status(checking_id=lnurlpospayment.payhash, pending=True)
return lnurlpos_renderer().TemplateResponse(
- "lnurlpos/paid.html", {"request": request, "pin": lnurlpospayment.pin}
+ "lnurlpos/error.html",
+ {"request": request, "pin": "filler", "not_paid": True},
)
diff --git a/lnbits/extensions/ngrok/config.json.example b/lnbits/extensions/ngrok/config.json
similarity index 100%
rename from lnbits/extensions/ngrok/config.json.example
rename to lnbits/extensions/ngrok/config.json
diff --git a/lnbits/extensions/offlineshop/templates/offlineshop/_api_docs.html b/lnbits/extensions/offlineshop/templates/offlineshop/_api_docs.html
index d3d1e53a8..ac655697b 100644
--- a/lnbits/extensions/offlineshop/templates/offlineshop/_api_docs.html
+++ b/lnbits/extensions/offlineshop/templates/offlineshop/_api_docs.html
@@ -62,7 +62,7 @@
Returns 201 OK
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}/offlineshop/api/v1/offlineshop/items -H "Content-Type:
application/json" -H "X-Api-Key: {{ user.wallets[0].inkey }}" -d
'{"name": <string>, "description": <string>, "image":
@@ -96,7 +96,7 @@
>
Curl example
curl -X GET {{ request.url_root }}/offlineshop/api/v1/offlineshop -H
+ >curl -X GET {{ request.base_url }}/offlineshop/api/v1/offlineshop -H
"X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -117,12 +117,12 @@
Returns 200 OK
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}/offlineshop/api/v1/offlineshop/items/<item_id> -H
"Content-Type: application/json" -H "X-Api-Key: {{
- user.wallets[0].inkey }}" -d '{"name": <string>,
- "description": <string>, "image": <data-uri string>,
- "price": <integer>, "unit": <"sat" or "USD">}'
+ user.wallets[0].inkey }}" -d '{"name": <string>, "description":
+ <string>, "image": <data-uri string>, "price":
+ <integer>, "unit": <"sat" or "USD">}'
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}/offlineshop/api/v1/offlineshop/items/<item_id> -H "X-Api-Key:
{{ user.wallets[0].inkey }}"
diff --git a/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html b/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html
index 7d73ae7e4..fb43b90dc 100644
--- a/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html
+++ b/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html
@@ -17,7 +17,7 @@
[<satsdice_link_object>, ...]
curl -X GET {{ request.url_root }}api/v1/links -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/links -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -44,7 +44,7 @@
{"lnurl": <string>}
curl -X GET {{ request.url_root }}api/v1/links/<satsdice_id> -H
+ >curl -X GET {{ request.base_url }}api/v1/links/<satsdice_id> -H
"X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -73,7 +73,7 @@
{"lnurl": <string>}
curl -X POST {{ request.url_root }}api/v1/links -d '{"title":
+ >curl -X POST {{ request.base_url }}api/v1/links -d '{"title":
<string>, "min_satsdiceable": <integer>,
"max_satsdiceable": <integer>, "uses": <integer>,
"wait_time": <integer>, "is_unique": <boolean>}' -H
@@ -109,7 +109,7 @@
{"lnurl": <string>}
Curl example
curl -X PUT {{ request.url_root }}api/v1/links/<satsdice_id> -d
+ >curl -X PUT {{ request.base_url }}api/v1/links/<satsdice_id> -d
'{"title": <string>, "min_satsdiceable": <integer>,
"max_satsdiceable": <integer>, "uses": <integer>,
"wait_time": <integer>, "is_unique": <boolean>}' -H
@@ -137,7 +137,7 @@
Curl example
curl -X DELETE {{ request.url_root }}api/v1/links/<satsdice_id>
+ >curl -X DELETE {{ request.base_url }}api/v1/links/<satsdice_id>
-H "X-Api-Key: {{ user.wallets[0].adminkey }}"
@@ -164,7 +164,7 @@
{"status": <bool>}
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/links/<the_hash>/<lnurl_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -186,7 +186,7 @@
>
Curl example
curl -X GET {{ request.url_root }}/satsdice/img/<lnurl_id>"
+ >curl -X GET {{ request.base_url }}/satsdice/img/<lnurl_id>"
diff --git a/lnbits/extensions/satsdice/views.py b/lnbits/extensions/satsdice/views.py
index 53c1b4206..ed6dde6d7 100644
--- a/lnbits/extensions/satsdice/views.py
+++ b/lnbits/extensions/satsdice/views.py
@@ -15,6 +15,7 @@ from lnbits.core.crud import (
delete_expired_invoices,
get_balance_checks,
)
+from lnbits.core.views.api import api_payment
from lnbits.core.services import check_invoice_status
from fastapi import FastAPI, Request
from fastapi.params import Depends
@@ -62,9 +63,7 @@ async def displaywin(
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
)
- status = await check_invoice_status(
- wallet_id=satsdicelink.wallet, payment_hash=payment_hash
- )
+ await api_payment(payment_hash)
withdrawLink = await get_satsdice_withdraw(payment_hash)
if withdrawLink:
@@ -86,7 +85,7 @@ async def displaywin(
)
if payment.pending == 1:
- await check_invoice_status(payment.wallet_id, payment_hash)
+ await api_payment(payment_hash)
payment = await get_standalone_payment(payment_hash) or abort(
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
)
diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py
index 50545d9cd..8efa70273 100644
--- a/lnbits/extensions/satspay/crud.py
+++ b/lnbits/extensions/satspay/crud.py
@@ -9,7 +9,7 @@ from lnbits.helpers import urlsafe_short_hash
import httpx
from lnbits.core.services import create_invoice, check_invoice_status
from ..watchonly.crud import get_watch_wallet, get_fresh_address, get_mempool
-
+from lnbits.core.views.api import api_payment
###############CHARGES##########################
@@ -110,10 +110,9 @@ async def check_address_balance(charge_id: str) -> List[Charges]:
except Exception:
pass
if charge.lnbitswallet:
- invoice_status = await check_invoice_status(
- charge.lnbitswallet, charge.payment_hash
- )
- if invoice_status.paid:
+ invoice_status = await api_payment(charge.payment_hash)
+
+ if invoice_status["paid"]:
return await update_charge(charge_id=charge_id, balance=charge.amount)
row = await db.fetchone("SELECT * FROM satspay.charges WHERE id = ?", (charge_id,))
return Charges.from_row(row) if row else None
diff --git a/lnbits/extensions/satspay/templates/satspay/_api_docs.html b/lnbits/extensions/satspay/templates/satspay/_api_docs.html
index af95cbf2c..d834db200 100644
--- a/lnbits/extensions/satspay/templates/satspay/_api_docs.html
+++ b/lnbits/extensions/satspay/templates/satspay/_api_docs.html
@@ -32,7 +32,7 @@
[<charge_object>, ...]
Curl example
curl -X POST {{ request.url_root }}api/v1/charge -d
+ >curl -X POST {{ request.base_url }}api/v1/charge -d
'{"onchainwallet": <string, watchonly_wallet_id>,
"description": <string>, "webhook":<string>, "time":
<integer>, "amount": <integer>, "lnbitswallet":
@@ -60,7 +60,7 @@
[<charge_object>, ...]
Curl example
curl -X POST {{ request.url_root }}api/v1/charge/<charge_id>
+ >curl -X POST {{ request.base_url }}api/v1/charge/<charge_id>
-d '{"onchainwallet": <string, watchonly_wallet_id>,
"description": <string>, "webhook":<string>, "time":
<integer>, "amount": <integer>, "lnbitswallet":
@@ -89,7 +89,7 @@
[<charge_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/charge/<charge_id>
+ >curl -X GET {{ request.base_url }}api/v1/charge/<charge_id>
-H "X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -112,7 +112,7 @@
[<charge_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/charges -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/charges -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -137,7 +137,7 @@
Curl example
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}api/v1/charge/<charge_id> -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -160,7 +160,7 @@
[<charge_object>, ...]
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/charges/balance/<charge_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py
index 733e63e6c..695673e70 100644
--- a/lnbits/extensions/satspay/views_api.py
+++ b/lnbits/extensions/satspay/views_api.py
@@ -7,7 +7,7 @@ from starlette.exceptions import HTTPException
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from lnbits.extensions.satspay import satspay_ext
-
+from lnbits.core.views.api import api_payment
from .crud import (
check_address_balance,
create_charge,
@@ -24,7 +24,9 @@ from .models import CreateCharge
@satspay_ext.post("/api/v1/charge")
@satspay_ext.put("/api/v1/charge/{charge_id}")
async def api_charge_create_or_update(
- data: CreateCharge, wallet: WalletTypeInfo = Depends(require_admin_key), charge_id=None
+ data: CreateCharge,
+ wallet: WalletTypeInfo = Depends(require_admin_key),
+ charge_id=None,
):
if not charge_id:
charge = await create_charge(user=wallet.wallet.user, data=data)
diff --git a/lnbits/extensions/splitpayments/templates/splitpayments/_api_docs.html b/lnbits/extensions/splitpayments/templates/splitpayments/_api_docs.html
index 116bdd744..78b5362cd 100644
--- a/lnbits/extensions/splitpayments/templates/splitpayments/_api_docs.html
+++ b/lnbits/extensions/splitpayments/templates/splitpayments/_api_docs.html
@@ -52,7 +52,7 @@
>
Curl example
curl -X GET {{ request.url_root }}api/v1/livestream -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/livestream -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -78,7 +78,7 @@
Curl example
curl -X PUT {{ request.url_root }}api/v1/splitpayments/targets -H
+ >curl -X PUT {{ request.base_url }}api/v1/splitpayments/targets -H
"X-Api-Key: {{ user.wallets[0].adminkey }}" -H 'Content-Type:
application/json' -d '{"targets": [{"wallet": <wallet id or invoice
key>, "alias": <name to identify this>, "percent": <number
diff --git a/lnbits/extensions/tpos/templates/tpos/_api_docs.html b/lnbits/extensions/tpos/templates/tpos/_api_docs.html
index 6ceab7284..7897383d0 100644
--- a/lnbits/extensions/tpos/templates/tpos/_api_docs.html
+++ b/lnbits/extensions/tpos/templates/tpos/_api_docs.html
@@ -17,7 +17,7 @@
[<tpos_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/tposs -H "X-Api-Key:
+ >curl -X GET {{ request.base_url }}api/v1/tposs -H "X-Api-Key:
<invoice_key>"
@@ -42,7 +42,7 @@
>
Curl example
curl -X POST {{ request.url_root }}api/v1/tposs -d '{"name":
+ >curl -X POST {{ request.base_url }}api/v1/tposs -d '{"name":
<string>, "currency": <string>}' -H "Content-type:
application/json" -H "X-Api-Key: <admin_key>"
@@ -69,7 +69,7 @@
Curl example
curl -X DELETE {{ request.url_root }}api/v1/tposs/<tpos_id> -H
+ >curl -X DELETE {{ request.base_url }}api/v1/tposs/<tpos_id> -H
"X-Api-Key: <admin_key>"
diff --git a/lnbits/extensions/tpos/views.py b/lnbits/extensions/tpos/views.py
index 2d78ecce1..bf16ecd32 100644
--- a/lnbits/extensions/tpos/views.py
+++ b/lnbits/extensions/tpos/views.py
@@ -29,6 +29,7 @@ async def tpos(request: Request, tpos_id):
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
+ print(request.base_url)
return tpos_renderer().TemplateResponse(
"tpos/tpos.html", {"request": request, "tpos": tpos}
diff --git a/lnbits/extensions/tpos/views_api.py b/lnbits/extensions/tpos/views_api.py
index d7008c2cd..54f6698b3 100644
--- a/lnbits/extensions/tpos/views_api.py
+++ b/lnbits/extensions/tpos/views_api.py
@@ -7,7 +7,8 @@ from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import check_invoice_status, create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
-
+from lnbits.core.views.api import api_payment
+from lnbits.core.models import Wallet
from . import tpos_ext
from .crud import create_tpos, delete_tpos, get_tpos, get_tposs
from .models import CreateTposData
@@ -33,7 +34,9 @@ async def api_tpos_create(
@tpos_ext.delete("/api/v1/tposs/{tpos_id}")
-async def api_tpos_delete(tpos_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)):
+async def api_tpos_delete(
+ tpos_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
+):
tpos = await get_tpos(tpos_id)
if not tpos:
@@ -84,20 +87,9 @@ async def api_tpos_check_invoice(tpos_id: str, payment_hash: str):
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)
- # return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
-
try:
- status = await check_invoice_status(tpos.wallet, payment_hash)
- is_paid = not status.pending
+ status = await api_payment(payment_hash)
except Exception as exc:
print(exc)
return {"paid": False}
-
- if is_paid:
- wallet = await get_wallet(tpos.wallet)
- payment = await wallet.get_payment(payment_hash)
- await payment.set_pending(False)
-
- return {"paid": True}
-
- return {"paid": False}
+ return status
diff --git a/lnbits/extensions/usermanager/templates/usermanager/_api_docs.html b/lnbits/extensions/usermanager/templates/usermanager/_api_docs.html
index 1944416b4..f3b1e8bdb 100644
--- a/lnbits/extensions/usermanager/templates/usermanager/_api_docs.html
+++ b/lnbits/extensions/usermanager/templates/usermanager/_api_docs.html
@@ -42,7 +42,7 @@
JSON list of users
Curl example
curl -X GET {{ request.url_root }}usermanager/api/v1/users -H
+ >curl -X GET {{ request.base_url }}usermanager/api/v1/users -H
"X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -62,7 +62,7 @@
JSON list of users
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}usermanager/api/v1/users/<user_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -85,7 +85,7 @@
JSON wallet data
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}usermanager/api/v1/wallets/<user_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -108,7 +108,7 @@
JSON a wallets transactions
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}usermanager/api/v1/wallets<wallet_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -150,7 +150,7 @@
>
Curl example
curl -X POST {{ request.url_root }}usermanager/api/v1/users -d
+ >curl -X POST {{ request.base_url }}usermanager/api/v1/users -d
'{"admin_id": "{{ user.id }}", "wallet_name": <string>,
"user_name": <string>, "email": <Optional string>,
"password": < Optional string>}' -H "X-Api-Key: {{
@@ -188,7 +188,7 @@
>
Curl example
curl -X POST {{ request.url_root }}usermanager/api/v1/wallets -d
+ >curl -X POST {{ request.base_url }}usermanager/api/v1/wallets -d
'{"user_id": <string>, "wallet_name": <string>,
"admin_id": "{{ user.id }}"}' -H "X-Api-Key: {{ user.wallets[0].inkey
}}" -H "Content-type: application/json"
@@ -212,7 +212,7 @@
{"X-Api-Key": <string>}
Curl example
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}usermanager/api/v1/users/<user_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -230,7 +230,7 @@
{"X-Api-Key": <string>}
Curl example
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}usermanager/api/v1/wallets/<wallet_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -253,7 +253,7 @@
{"X-Api-Key": <string>}
Curl example
curl -X POST {{ request.url_root }}usermanager/api/v1/extensions -d
+ >curl -X POST {{ request.base_url }}usermanager/api/v1/extensions -d
'{"userid": <string>, "extension": <string>, "active":
<integer>}' -H "X-Api-Key: {{ user.wallets[0].inkey }}" -H
"Content-type: application/json"
diff --git a/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html b/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html
index 9d6bb6ac1..e82171920 100644
--- a/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html
+++ b/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html
@@ -37,7 +37,7 @@
[<wallets_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/wallet -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/wallet -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -66,7 +66,7 @@
[<wallet_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/wallet/<wallet_id>
+ >curl -X GET {{ request.base_url }}api/v1/wallet/<wallet_id>
-H "X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -89,7 +89,7 @@
[<wallet_object>, ...]
Curl example
curl -X POST {{ request.url_root }}api/v1/wallet -d '{"title":
+ >curl -X POST {{ request.base_url }}api/v1/wallet -d '{"title":
<string>, "masterpub": <string>}' -H "Content-type:
application/json" -H "X-Api-Key: {{ user.wallets[0].adminkey }}"
@@ -115,7 +115,7 @@
Curl example
curl -X DELETE {{ request.url_root
+ >curl -X DELETE {{ request.base_url
}}api/v1/wallet/<wallet_id> -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -141,7 +141,7 @@
[<address_object>, ...]
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/addresses/<wallet_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -173,7 +173,7 @@
[<address_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/address/<wallet_id>
+ >curl -X GET {{ request.base_url }}api/v1/address/<wallet_id>
-H "X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -202,7 +202,7 @@
[<mempool_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/mempool -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/mempool -H "X-Api-Key: {{
user.wallets[0].adminkey }}"
@@ -233,7 +233,7 @@
[<mempool_object>, ...]
Curl example
curl -X PUT {{ request.url_root }}api/v1/mempool -d '{"endpoint":
+ >curl -X PUT {{ request.base_url }}api/v1/mempool -d '{"endpoint":
<string>}' -H "Content-type: application/json" -H "X-Api-Key:
{{ user.wallets[0].adminkey }}"
diff --git a/lnbits/extensions/withdraw/templates/withdraw/_api_docs.html b/lnbits/extensions/withdraw/templates/withdraw/_api_docs.html
index ca141c1da..77f855fdd 100644
--- a/lnbits/extensions/withdraw/templates/withdraw/_api_docs.html
+++ b/lnbits/extensions/withdraw/templates/withdraw/_api_docs.html
@@ -22,7 +22,7 @@
[<withdraw_link_object>, ...]
Curl example
curl -X GET {{ request.url_root }}api/v1/links -H "X-Api-Key: {{
+ >curl -X GET {{ request.base_url }}api/v1/links -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -49,7 +49,7 @@
{"lnurl": <string>}
Curl example
curl -X GET {{ request.url_root }}api/v1/links/<withdraw_id> -H
+ >curl -X GET {{ request.base_url }}api/v1/links/<withdraw_id> -H
"X-Api-Key: {{ user.wallets[0].inkey }}"
@@ -78,7 +78,7 @@
{"lnurl": <string>}
Curl example
curl -X POST {{ request.url_root }}api/v1/links -d '{"title":
+ >curl -X POST {{ request.base_url }}api/v1/links -d '{"title":
<string>, "min_withdrawable": <integer>,
"max_withdrawable": <integer>, "uses": <integer>,
"wait_time": <integer>, "is_unique": <boolean>}' -H
@@ -114,7 +114,7 @@
{"lnurl": <string>}
Curl example
curl -X PUT {{ request.url_root }}api/v1/links/<withdraw_id> -d
+ >curl -X PUT {{ request.base_url }}api/v1/links/<withdraw_id> -d
'{"title": <string>, "min_withdrawable": <integer>,
"max_withdrawable": <integer>, "uses": <integer>,
"wait_time": <integer>, "is_unique": <boolean>}' -H
@@ -142,7 +142,7 @@
Curl example
curl -X DELETE {{ request.url_root }}api/v1/links/<withdraw_id>
+ >curl -X DELETE {{ request.base_url }}api/v1/links/<withdraw_id>
-H "X-Api-Key: {{ user.wallets[0].adminkey }}"
@@ -169,7 +169,7 @@
{"status": <bool>}
Curl example
curl -X GET {{ request.url_root
+ >curl -X GET {{ request.base_url
}}api/v1/links/<the_hash>/<lnurl_id> -H "X-Api-Key: {{
user.wallets[0].inkey }}"
@@ -191,7 +191,7 @@
>
Curl example
curl -X GET {{ request.url_root }}/withdraw/img/<lnurl_id>"
+ >curl -X GET {{ request.base_url }}/withdraw/img/<lnurl_id>"