lnurlpos working

This commit is contained in:
benarc
2021-11-03 14:41:36 +00:00
parent e62f2e2c34
commit c1d6d3eee6
4 changed files with 42 additions and 47 deletions
+11 -15
View File
@@ -2,6 +2,7 @@ import json
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from lnurl.types import LnurlPayMetadata # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from sqlite3 import Row
from typing import NamedTuple, Optional, Dict
import shortuuid # type: ignore
@@ -26,29 +27,24 @@ class lnurlposs(BaseModel):
currency: str
timestamp: str
@classmethod
def from_row(cls, row: Row) -> "lnurlposs":
return cls(**dict(row))
@property
def lnurl(self) -> Lnurl:
url = url_for("lnurlpos.lnurl_response", pos_id=self.id, _external=True)
def lnurl(self, req: Request) -> Lnurl:
url = req.url_for("lnurlpos.lnurl_response", pos_id=self.id, _external=True)
return lnurl_encode(url)
@property
def lnurlpay_metadata(self) -> LnurlPayMetadata:
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
return LnurlPayMetadata(json.dumps([["text/plain", self.title]]))
def success_action(self, paymentid: str, req: Request) -> Optional[Dict]:
url = url_for(
"lnurlpos.displaypin",
paymentid=paymentid,
def success_action(
self, paymentid: str, req: Request
) -> Optional[LnurlPaySuccessAction]:
return UrlAction(
url=req.url_for("lnurlpos.displaypin", paymentid=paymentid),
description="Check the attached link",
)
return {
"tag": "url",
"description": "Check the attached link",
"url": url,
}
class lnurlpospayment(BaseModel):