parent
98ec59df96
commit
bbfc301440
4 changed files with 36 additions and 3 deletions
|
|
@ -387,6 +387,7 @@ class CreateInvoice(BaseModel):
|
||||||
extra: Optional[dict] = None
|
extra: Optional[dict] = None
|
||||||
webhook: Optional[str] = None
|
webhook: Optional[str] = None
|
||||||
bolt11: Optional[str] = None
|
bolt11: Optional[str] = None
|
||||||
|
lnurl_callback: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class CreateTopup(BaseModel):
|
class CreateTopup(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import json
|
||||||
import uuid
|
import uuid
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -177,9 +177,34 @@ async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
|
||||||
|
|
||||||
invoice = bolt11.decode(payment_request)
|
invoice = bolt11.decode(payment_request)
|
||||||
|
|
||||||
|
lnurl_response: Union[None, bool, str] = None
|
||||||
|
if data.lnurl_callback:
|
||||||
|
headers = {"User-Agent": settings.user_agent}
|
||||||
|
async with httpx.AsyncClient(headers=headers) as client:
|
||||||
|
try:
|
||||||
|
r = await client.get(
|
||||||
|
data.lnurl_callback,
|
||||||
|
params={
|
||||||
|
"pr": payment_request,
|
||||||
|
},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
if r.is_error:
|
||||||
|
lnurl_response = r.text
|
||||||
|
else:
|
||||||
|
resp = json.loads(r.text)
|
||||||
|
if resp["status"] != "OK":
|
||||||
|
lnurl_response = resp["reason"]
|
||||||
|
else:
|
||||||
|
lnurl_response = True
|
||||||
|
except (httpx.ConnectError, httpx.RequestError) as ex:
|
||||||
|
logger.error(ex)
|
||||||
|
lnurl_response = False
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"payment_hash": invoice.payment_hash,
|
"payment_hash": invoice.payment_hash,
|
||||||
"payment_request": payment_request,
|
"payment_request": payment_request,
|
||||||
|
"lnurl_response": lnurl_response,
|
||||||
# maintain backwards compatibility with API clients:
|
# maintain backwards compatibility with API clients:
|
||||||
"checking_id": checking_id,
|
"checking_id": checking_id,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
lnbits/static/bundle.min.js
vendored
2
lnbits/static/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -22,11 +22,18 @@ window.LNbits = {
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
createInvoice: async function (wallet, amount, memo, unit = 'sat') {
|
createInvoice: async function (
|
||||||
|
wallet,
|
||||||
|
amount,
|
||||||
|
memo,
|
||||||
|
unit = 'sat',
|
||||||
|
lnurlCallback = null
|
||||||
|
) {
|
||||||
return this.request('post', '/api/v1/payments', wallet.inkey, {
|
return this.request('post', '/api/v1/payments', wallet.inkey, {
|
||||||
out: false,
|
out: false,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
memo: memo,
|
memo: memo,
|
||||||
|
lnurl_callback: lnurlCallback,
|
||||||
unit: unit
|
unit: unit
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue