From d1cb9f6c7461b9ddea98d4a2fb5aa8b64ed3026d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Thu, 28 Nov 2024 22:39:11 +0100 Subject: [PATCH] fix: v1 update, make withdraw post (#105) * make withdraw post * add id repo and version to config.json --- config.json | 3 +++ models.py | 4 ++++ static/js/tpos.js | 8 ++++++-- templates/tpos/dialogs.html | 12 ++++-------- views_api.py | 11 ++++++----- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/config.json b/config.json index 4e9bf2d..35740d0 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,8 @@ { + "id": "tpos", + "version": "1.0.0", "name": "TPoS", + "repo": "https://github.com/lnbits/tpos", "short_description": "A shareable PoS terminal!", "tile": "/tpos/static/image/tpos.png", "min_lnbits_version": "1.0.0", diff --git a/models.py b/models.py index 6588497..da71698 100644 --- a/models.py +++ b/models.py @@ -6,6 +6,10 @@ from pydantic import BaseModel, Field, validator +class CreateWithdrawPay(BaseModel): + pay_link: str + + class CreateTposInvoice(BaseModel): amount: int = Query(..., ge=1) memo: Optional[str] = Query(None) diff --git a/static/js/tpos.js b/static/js/tpos.js index af69c68..062dc7c 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -570,8 +570,12 @@ window.app = Vue.createApp({ } LNbits.api .request( - 'GET', - `/tpos/api/v1/atm/withdraw/${this.atmToken}/${this.sat}/pay?payLink=${payLink}` + 'POST', + `/tpos/api/v1/atm/withdraw/${this.atmToken}/${this.sat}/pay`, + null, + { + pay_link: payLink + } ) .then(res => { if (!res.data.success) { diff --git a/templates/tpos/dialogs.html b/templates/tpos/dialogs.html index 3fe576a..f09f6bb 100644 --- a/templates/tpos/dialogs.html +++ b/templates/tpos/dialogs.html @@ -13,13 +13,10 @@ target="_blank" rel="noopener noreferrer" > - - - + Pay in wallet
@@ -111,7 +108,6 @@
diff --git a/views_api.py b/views_api.py index 28232fe..231e7fa 100644 --- a/views_api.py +++ b/views_api.py @@ -33,6 +33,7 @@ CreateTposData, CreateTposInvoice, CreateUpdateItemData, + CreateWithdrawPay, LnurlCharge, PayLnurlWData, Tpos, @@ -237,15 +238,15 @@ async def api_tpos_atm_pin_check(tpos_id: str, atmpin: int) -> LnurlCharge: return token -@tpos_api_router.get( +@tpos_api_router.post( "/api/v1/atm/withdraw/{k1}/{amount}/pay", status_code=HTTPStatus.OK ) async def api_tpos_atm_pay( - request: Request, k1: str, amount: int, pay_link: str = Query(...) + request: Request, k1: str, amount: int, data: CreateWithdrawPay ): try: # get the payment_request from the lnurl - pay_link = pay_link.replace("lnurlp://", "https://") + pay_link = data.pay_link.replace("lnurlp://", "https://") async with httpx.AsyncClient() as client: headers = {"user-agent": "lnbits/tpos"} r = await client.get(pay_link, follow_redirects=True, headers=headers) @@ -258,10 +259,10 @@ async def api_tpos_atm_pay( if resp["tag"] != "payRequest": return {"success": False, "detail": "Wrong tag type"} - if amount < resp["minSendable"]: + if amount < int(resp["minSendable"]): return {"success": False, "detail": "Amount too low"} - if amount > resp["maxSendable"]: + if amount > int(resp["maxSendable"]): return {"success": False, "detail": "Amount too high"} cb_res = await client.get(