diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py
index bb1ca0c1c..881d10014 100644
--- a/lnbits/core/crud.py
+++ b/lnbits/core/crud.py
@@ -229,6 +229,24 @@ async def get_wallet_payment(
return Payment.from_row(row) if row else None
+async def get_latest_payments_by_extension(ext_name: str, ext_id: str, limit: int = 5):
+ rows = await db.fetchall(
+ f"""
+ SELECT * FROM apipayments
+ WHERE pending = 'false'
+ AND extra LIKE ?
+ AND extra LIKE ?
+ ORDER BY time DESC LIMIT {limit}
+ """,
+ (
+ f"%{ext_name}%",
+ f"%{ext_id}%",
+ ),
+ )
+
+ return rows
+
+
async def get_payments(
*,
wallet_id: Optional[str] = None,
diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html
index ad04b3bea..c66238f76 100644
--- a/lnbits/extensions/tpos/templates/tpos/tpos.html
+++ b/lnbits/extensions/tpos/templates/tpos/tpos.html
@@ -148,6 +148,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No paid invoices
+
+
+
+ {%raw%}
+
+ {{payment.amount / 1000}} sats
+ Hash: {{payment.checking_id.slice(0, 30)}}...
+
+
+ {{payment.dateFrom}}
+
+
+ {%endraw%}
+
+
+
+
{% endblock %} {% block styles %}
@@ -296,6 +336,10 @@
tipAmount: 0.0,
hasNFC: false,
nfcTagReading: false,
+ lastPaymentsDialog: {
+ show: false,
+ data: []
+ },
invoiceDialog: {
show: false,
data: null,
@@ -520,6 +564,24 @@
self.exchangeRate =
response.data.data['BTC' + self.currency][self.currency]
})
+ },
+ getLastPayments() {
+ return axios
+ .get(`/tpos/api/v1/tposs/${this.tposId}/invoices`)
+ .then(res => {
+ if (res.data && res.data.length) {
+ let last = [...res.data]
+ this.lastPaymentsDialog.data = last.map(obj => {
+ obj.dateFrom = moment(obj.time * 1000).fromNow()
+ return obj
+ })
+ }
+ })
+ .catch(e => console.error(e))
+ },
+ showLastPayments() {
+ this.getLastPayments()
+ this.lastPaymentsDialog.show = true
}
},
created: function () {
diff --git a/lnbits/extensions/tpos/views_api.py b/lnbits/extensions/tpos/views_api.py
index 805014917..fe63a2471 100644
--- a/lnbits/extensions/tpos/views_api.py
+++ b/lnbits/extensions/tpos/views_api.py
@@ -7,7 +7,8 @@ from lnurl import decode as decode_lnurl
from loguru import logger
from starlette.exceptions import HTTPException
-from lnbits.core.crud import get_user
+from lnbits.core.crud import get_latest_payments_by_extension, get_user
+from lnbits.core.models import Payment
from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
@@ -81,6 +82,30 @@ async def api_tpos_create_invoice(
return {"payment_hash": payment_hash, "payment_request": payment_request}
+@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices")
+async def api_tpos_get_latest_invoices(tpos_id: str = None):
+ try:
+ payments = [
+ Payment.from_row(row)
+ for row in await get_latest_payments_by_extension(
+ ext_name="tpos", ext_id=tpos_id
+ )
+ ]
+
+ except Exception as e:
+ raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
+
+ return [
+ {
+ "checking_id": payment.checking_id,
+ "amount": payment.amount,
+ "time": payment.time,
+ "pending": payment.pending,
+ }
+ for payment in payments
+ ]
+
+
@tpos_ext.post(
"/api/v1/tposs/{tpos_id}/invoices/{payment_request}/pay", status_code=HTTPStatus.OK
)