Skip to content

Commit

Permalink
fix: v1 update, make withdraw post (#105)
Browse files Browse the repository at this point in the history
* make withdraw post
* add id repo and version to config.json
  • Loading branch information
dni authored Nov 28, 2024
1 parent d42e1d1 commit d1cb9f6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions templates/tpos/dialogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
target="_blank"
rel="noopener noreferrer"
>
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
<lnbits-qrcode
:value="'lightning:' + invoiceDialog.data.payment_request.toUpperCase()"
:options="{width: 800}"
class="rounded-borders"
></lnbits-qrcode>
</q-responsive>
<lnbits-qrcode
:value="'lightning:' + invoiceDialog.data.payment_request.toUpperCase()"
class="rounded-borders"
></lnbits-qrcode>
<q-tooltip>Pay in wallet</q-tooltip>
</a>
<div class="text-center">
Expand Down Expand Up @@ -111,7 +108,6 @@ <h5 class="q-mt-none q-mb-sm">
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
<lnbits-qrcode
value="{{ request.url }}"
:options="{width: 800}"
class="rounded-borders"
></lnbits-qrcode>
</q-responsive>
Expand Down
11 changes: 6 additions & 5 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CreateTposData,
CreateTposInvoice,
CreateUpdateItemData,
CreateWithdrawPay,
LnurlCharge,
PayLnurlWData,
Tpos,
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit d1cb9f6

Please sign in to comment.