Extension: LNURLw webhook_url (#610)
* LNURLw web_hook * crlf -> lf * Fix typo * LNURLw webhook api doc
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import json
|
||||
import traceback
|
||||
import httpx
|
||||
|
||||
from datetime import datetime
|
||||
from http import HTTPStatus
|
||||
|
||||
@@ -103,17 +106,35 @@ async def api_lnurl_callback(
|
||||
await update_withdraw_link(link.id, **changes)
|
||||
|
||||
payment_request = pr
|
||||
|
||||
await pay_invoice(
|
||||
|
||||
payment_hash = await pay_invoice(
|
||||
wallet_id=link.wallet,
|
||||
payment_request=payment_request,
|
||||
max_sat=link.max_withdrawable,
|
||||
extra={"tag": "withdraw"},
|
||||
)
|
||||
|
||||
if link.webhook_url:
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
r = await client.post(
|
||||
link.webhook_url,
|
||||
json={
|
||||
"payment_hash": payment_hash,
|
||||
"payment_request": payment_request,
|
||||
"lnurlw": link.id,
|
||||
},
|
||||
timeout=40,
|
||||
)
|
||||
except Exception as exc:
|
||||
# webhook fails shouldn't cause the lnurlw to fail since invoice is already paid
|
||||
print("Caught exception when dispatching webhook url:", exc)
|
||||
|
||||
return {"status": "OK"}
|
||||
|
||||
except Exception as e:
|
||||
await update_withdraw_link(link.id, **changesback)
|
||||
print(traceback.format_exc())
|
||||
return {"status": "ERROR", "reason": "Link not working"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user