Skip to content

Commit

Permalink
testing this is turning out a PITA
Browse files Browse the repository at this point in the history
  • Loading branch information
talvasconcelos committed Aug 27, 2024
1 parent cb6e62c commit ad02b4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
8 changes: 3 additions & 5 deletions static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,7 @@ const tposJS = async () => {
})
},
async pinCallback(callback) {
const {data} = await LNbits.api.request(
'GET',
const {data} = await axios.get(
`/tpos/api/v1/tposs/${this.tposId}/invoices/${this.invoiceDialog.data.payment_request}/pay?cb=${callback}`
)
if (!data.success) {
Expand All @@ -617,8 +616,7 @@ const tposJS = async () => {
}
},
async payInvoice(lnurl, readerAbortController) {
const {data} = await LNbits.api.request(
'POST',
const {data} = await axios.post(
`/tpos/api/v1/tposs/${this.tposId}/invoices/${this.invoiceDialog.data.payment_request}/pay`,
{lnurl}
)
Expand All @@ -630,7 +628,7 @@ const tposJS = async () => {
}
if (data.success && data.detail.includes('PIN') && data.callback) {
this.$q.notify({
type: 'warning',
type: 'negative',
message: data.detail
})
this.$q
Expand Down
33 changes: 23 additions & 10 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async def api_tpos_get_latest_invoices(tpos_id: str):
async def api_tpos_pay_invoice(
lnurl_data: PayLnurlWData, payment_request: str, tpos_id: str
):
logger.debug(f"1st call lnurl_data: {lnurl_data}")
tpos = await get_tpos(tpos_id)

if not tpos:
Expand Down Expand Up @@ -198,41 +199,52 @@ async def api_tpos_pay_invoice(
lnurl_response = {"success": False, "detail": "Error loading"}
else:
resp = r.json()
if resp["tag"] != "withdrawRequest":
logger.debug(f"1st call resp: {resp}")
if resp.get("tag") != "withdrawRequest":
lnurl_response = {"success": False, "detail": "Wrong tag type"}

elif resp["pinLimit"]:
elif resp.get("pinLimit"):
logger.debug(
f"PIN required for this amount: {resp.get('pinLimit')}"
)
invoice = bolt11.decode(payment_request)
if invoice.amount_msat >= resp["pinLimit"]:
if invoice.amount_msat >= resp.get("pinLimit"):
return {
"success": True,
"detail": "PIN required for this amount",
"callback": resp["callback"],
"k1": resp["k1"],
"callback": resp.get("callback"),
"k1": resp.get("k1"),
}
else:
logger.debug(
f"all clear making callback to: {resp.get('callback')}"
)
r2 = await client.get(
resp["callback"],
resp.get("callback"),
follow_redirects=True,
headers=headers,
params={
"k1": resp["k1"],
"k1": resp.get("k1"),
"pr": payment_request,
},
)
resp2 = r2.json()
logger.debug(f"2nd call resp2 OK: {resp2}")
if r2.is_error:
lnurl_response = {
"success": False,
"detail": "Error loading callback",
}
elif resp2["status"] == "ERROR":
lnurl_response = {"success": False, "detail": resp2["reason"]}
elif resp2.get("status") == "ERROR":
lnurl_response = {
"success": False,
"detail": resp2.get("reason"),
}
else:
lnurl_response = {"success": True, "detail": resp2}
except (httpx.ConnectError, httpx.RequestError):
lnurl_response = {"success": False, "detail": "Unexpected error occurred"}

logger.debug(f"lnurl_response: {lnurl_response}")
return lnurl_response


Expand All @@ -246,6 +258,7 @@ async def api_tpos_pay_invoice_cb(
cb: str = Query(None),
):
tpos = await get_tpos(tpos_id)
logger.debug(f"2nd call cb: {cb}")

if not tpos:
raise HTTPException(
Expand Down

0 comments on commit ad02b4c

Please sign in to comment.