Skip to content

Commit

Permalink
make withdraw post
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 30, 2024
1 parent 4a26f33 commit d6555e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
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 @@ -569,8 +569,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
12 changes: 7 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 @@ -254,14 +255,15 @@ async def api_tpos_atm_pay(
resp = r.json()

amount = amount * 1000 # convert to msats
print(resp)

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 d6555e9

Please sign in to comment.