Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lnurl.py #17

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lnurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
create_lnurldevicepayment,
get_lnurldevice,
get_lnurldevicepayment,
get_lnurldevicepayment_by_p,
get_lnurlpayload,
update_lnurldevicepayment,
)

Expand Down Expand Up @@ -169,20 +169,21 @@ async def lnurl_params(
if device.device != "atm":
return {"status": "ERROR", "reason": "Not ATM device."}
price_msat = int(price_msat * (1 - (device.profit / 100)) / 1000)
lnurldevicepayment = await get_lnurldevicepayment_by_p(p)
lnurldevicepayment = await get_lnurlpayload(p)
if lnurldevicepayment:
if lnurldevicepayment.payload == lnurldevicepayment.payhash:
return {"status": "ERROR", "reason": "Payment already claimed"}
try:
lnurldevicepayment = await create_lnurldevicepayment(
deviceid=device.id,
payload=p,
sats=price_msat * 1000,
pin=pin,
payhash="payment_hash",
)
except:
return {"status": "ERROR", "reason": "Could not create ATM payment."}
if not lnurldevicepayment:
try:
lnurldevicepayment = await create_lnurldevicepayment(
deviceid=device.id,
payload=p,
sats=price_msat * 1000,
pin=pin,
payhash="payment_hash",
)
except:
return {"status": "ERROR", "reason": "Could not create ATM payment."}
if not lnurldevicepayment:
return {"status": "ERROR", "reason": "Could not create ATM payment."}
return {
Expand Down Expand Up @@ -267,6 +268,9 @@ async def lnurl_callback(
extra={"tag": "withdraw"},
)
except:
await update_lnurldevicepayment(
lnurldevicepayment_id=paymentid, payhash="payment_hash"
)
return {"status": "ERROR", "reason": "Payment failed, use a different wallet."}
return {"status": "OK"}
if device.device == "switch":
Expand Down