[feat] Add stripe payments (#3184)

This commit is contained in:
Vlad Stan
2025-07-08 10:17:19 +02:00
committed by dni ⚡
parent 5c9511ccfe
commit 695e9b6471
51 changed files with 2014 additions and 175 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ from typing import AsyncGenerator, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -27,7 +28,7 @@ class AlbyWallet(Wallet):
if not settings.alby_access_token:
raise ValueError("cannot initialize AlbyWallet: missing alby_access_token")
self.endpoint = self.normalize_endpoint(settings.alby_api_endpoint)
self.endpoint = normalize_endpoint(settings.alby_api_endpoint)
self.auth = {
"Authorization": "Bearer " + settings.alby_access_token,
"User-Agent": settings.user_agent,
-14
View File
@@ -150,17 +150,3 @@ class Wallet(ABC):
except Exception as exc:
logger.error(f"could not get status of invoice {invoice}: '{exc}' ")
await asyncio.sleep(5)
def normalize_endpoint(self, endpoint: str, add_proto=True) -> str:
endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
if add_proto:
if endpoint.startswith("ws://") or endpoint.startswith("wss://"):
return endpoint
endpoint = (
f"https://{endpoint}" if not endpoint.startswith("http") else endpoint
)
return endpoint
class UnsupportedError(Exception):
pass
+3 -2
View File
@@ -10,6 +10,7 @@ from websockets.client import WebSocketClientProtocol, connect
from websockets.typing import Subprotocol
from lnbits import bolt11
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -34,13 +35,13 @@ class BlinkWallet(Wallet):
if not settings.blink_token:
raise ValueError("cannot initialize BlinkWallet: missing blink_token")
self.endpoint = self.normalize_endpoint(settings.blink_api_endpoint)
self.endpoint = normalize_endpoint(settings.blink_api_endpoint)
self.auth = {
"X-API-KEY": settings.blink_token,
"User-Agent": settings.user_agent,
}
self.ws_endpoint = self.normalize_endpoint(settings.blink_ws_endpoint)
self.ws_endpoint = normalize_endpoint(settings.blink_ws_endpoint)
self.ws_auth = {
"type": "connection_init",
"payload": {"X-API-KEY": settings.blink_token},
+2 -1
View File
@@ -5,6 +5,7 @@ from bolt11.decode import decode
from grpc.aio import AioRpcError
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from lnbits.wallets.boltz_grpc_files import boltzrpc_pb2, boltzrpc_pb2_grpc
from lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc import grpc
@@ -42,7 +43,7 @@ class BoltzWallet(Wallet):
"cannot initialize BoltzWallet: missing boltz_client_wallet"
)
self.endpoint = self.normalize_endpoint(
self.endpoint = normalize_endpoint(
settings.boltz_client_endpoint, add_proto=True
)
+2 -1
View File
@@ -1,5 +1,7 @@
import base64
from lnbits.exceptions import UnsupportedError
try:
import breez_sdk # type: ignore
@@ -34,7 +36,6 @@ else:
PaymentStatus,
PaymentSuccessStatus,
StatusResponse,
UnsupportedError,
Wallet,
)
+2 -1
View File
@@ -6,6 +6,7 @@ from typing import AsyncGenerator, Optional
from loguru import logger
from websocket import create_connection
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -25,7 +26,7 @@ class ClicheWallet(Wallet):
if not settings.cliche_endpoint:
raise ValueError("cannot initialize ClicheWallet: missing cliche_endpoint")
self.endpoint = self.normalize_endpoint(settings.cliche_endpoint)
self.endpoint = normalize_endpoint(settings.cliche_endpoint)
async def cleanup(self):
pass
+1 -1
View File
@@ -8,6 +8,7 @@ from bolt11.exceptions import Bolt11Exception
from loguru import logger
from pyln.client import LightningRpc, RpcError
from lnbits.exceptions import UnsupportedError
from lnbits.nodes.cln import CoreLightningNode
from lnbits.settings import settings
from lnbits.utils.crypto import random_secret_and_hash
@@ -20,7 +21,6 @@ from .base import (
PaymentStatus,
PaymentSuccessStatus,
StatusResponse,
UnsupportedError,
Wallet,
)
+3 -2
View File
@@ -9,6 +9,8 @@ from bolt11 import Bolt11Exception
from bolt11.decode import decode
from loguru import logger
from lnbits.exceptions import UnsupportedError
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from lnbits.utils.crypto import random_secret_and_hash
@@ -18,7 +20,6 @@ from .base import (
PaymentResponse,
PaymentStatus,
StatusResponse,
UnsupportedError,
Wallet,
)
from .macaroon import load_macaroon
@@ -43,7 +44,7 @@ class CoreLightningRestWallet(Wallet):
"invalid corelightning_rest_macaroon provided"
)
self.url = self.normalize_endpoint(settings.corelightning_rest_url)
self.url = normalize_endpoint(settings.corelightning_rest_url)
headers = {
"macaroon": macaroon,
"encodingtype": "hex",
+2 -1
View File
@@ -11,6 +11,7 @@ import httpx
from loguru import logger
from websockets.client import connect
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from lnbits.utils.crypto import random_secret_and_hash
@@ -39,7 +40,7 @@ class EclairWallet(Wallet):
if not settings.eclair_pass:
raise ValueError("cannot initialize EclairWallet: missing eclair_pass")
self.url = self.normalize_endpoint(settings.eclair_url)
self.url = normalize_endpoint(settings.eclair_url)
self.ws_url = f"ws://{urllib.parse.urlsplit(self.url).netloc}/ws"
password = settings.eclair_pass
+2 -1
View File
@@ -6,6 +6,7 @@ import httpx
from loguru import logger
from websockets.client import connect
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -36,7 +37,7 @@ class LNbitsWallet(Wallet):
"cannot initialize LNbitsWallet: "
"missing lnbits_key or lnbits_admin_key or lnbits_invoice_key"
)
self.endpoint = self.normalize_endpoint(settings.lnbits_endpoint)
self.endpoint = normalize_endpoint(settings.lnbits_endpoint)
self.ws_url = f"{self.endpoint.replace('http', 'ws', 1)}/api/v1/ws/{key}"
self.headers = {"X-Api-Key": key, "User-Agent": settings.user_agent}
self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.headers)
+2 -3
View File
@@ -11,6 +11,7 @@ import lnbits.wallets.lnd_grpc_files.lightning_pb2 as ln
import lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc as lnrpc
import lnbits.wallets.lnd_grpc_files.router_pb2 as router
import lnbits.wallets.lnd_grpc_files.router_pb2_grpc as routerrpc
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from lnbits.utils.crypto import random_secret_and_hash
@@ -72,9 +73,7 @@ class LndWallet(Wallet):
"cannot initialize LndWallet: missing lnd_grpc_cert or lnd_cert"
)
self.endpoint = self.normalize_endpoint(
settings.lnd_grpc_endpoint, add_proto=False
)
self.endpoint = normalize_endpoint(settings.lnd_grpc_endpoint, add_proto=False)
self.port = int(settings.lnd_grpc_port)
macaroon = (
+2 -1
View File
@@ -7,6 +7,7 @@ from typing import Any, AsyncGenerator, Dict, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.nodes.lndrest import LndRestNode
from lnbits.settings import settings
from lnbits.utils.crypto import random_secret_and_hash
@@ -41,7 +42,7 @@ class LndRestWallet(Wallet):
"This only works if you have a publicly issued certificate."
)
self.endpoint = self.normalize_endpoint(settings.lnd_rest_endpoint)
self.endpoint = normalize_endpoint(settings.lnd_rest_endpoint)
# if no cert provided it should be public so we set verify to True
# and it will still check for validity of certificate and fail if its not valid
+2 -1
View File
@@ -5,6 +5,7 @@ from typing import AsyncGenerator, Dict, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -36,7 +37,7 @@ class LNPayWallet(Wallet):
"missing lnpay_wallet_key or lnpay_admin_key"
)
self.wallet_key = wallet_key
self.endpoint = self.normalize_endpoint(settings.lnpay_api_endpoint)
self.endpoint = normalize_endpoint(settings.lnpay_api_endpoint)
headers = {
"X-Api-Key": settings.lnpay_api_key,
+2 -1
View File
@@ -7,6 +7,7 @@ from typing import AsyncGenerator, Dict, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -36,7 +37,7 @@ class LnTipsWallet(Wallet):
"missing lntips_api_key or lntips_admin_key or lntips_invoice_key"
)
self.endpoint = self.normalize_endpoint(settings.lntips_api_endpoint)
self.endpoint = normalize_endpoint(settings.lntips_api_endpoint)
headers = {
"Authorization": f"Basic {key}",
+3 -2
View File
@@ -4,6 +4,8 @@ from typing import AsyncGenerator, Optional
import httpx
from loguru import logger
from lnbits.exceptions import UnsupportedError
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -12,7 +14,6 @@ from .base import (
PaymentResponse,
PaymentStatus,
StatusResponse,
UnsupportedError,
Wallet,
)
@@ -38,7 +39,7 @@ class OpenNodeWallet(Wallet):
)
self.key = key
self.endpoint = self.normalize_endpoint(settings.opennode_api_endpoint)
self.endpoint = normalize_endpoint(settings.opennode_api_endpoint)
headers = {
"Authorization": self.key,
+2 -1
View File
@@ -9,6 +9,7 @@ import httpx
from loguru import logger
from websockets.client import connect
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -35,7 +36,7 @@ class PhoenixdWallet(Wallet):
"cannot initialize PhoenixdWallet: missing phoenixd_api_password"
)
self.endpoint = self.normalize_endpoint(settings.phoenixd_api_endpoint)
self.endpoint = normalize_endpoint(settings.phoenixd_api_endpoint)
parsed_url = urllib.parse.urlparse(settings.phoenixd_api_endpoint)
if parsed_url.scheme == "http":
+2 -1
View File
@@ -7,6 +7,7 @@ from typing import AsyncGenerator, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -36,7 +37,7 @@ class SparkWallet(Wallet):
if not settings.spark_token:
raise ValueError("cannot initialize SparkWallet: missing spark_token")
url = self.normalize_endpoint(settings.spark_url)
url = normalize_endpoint(settings.spark_url)
url = url.replace("/rpc", "")
self.token = settings.spark_token
+2 -1
View File
@@ -6,6 +6,7 @@ from typing import Any, AsyncGenerator, Dict, Optional
import httpx
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -94,7 +95,7 @@ class StrikeWallet(Wallet):
self._general_limiter = TokenBucket(1000, 600)
self.client = httpx.AsyncClient(
base_url=self.normalize_endpoint(settings.strike_api_endpoint),
base_url=normalize_endpoint(settings.strike_api_endpoint),
headers={
"Authorization": f"Bearer {settings.strike_api_key}",
"Content-Type": "application/json",
+2 -1
View File
@@ -6,6 +6,7 @@ import httpx
from bolt11 import decode as bolt11_decode
from loguru import logger
from lnbits.helpers import normalize_endpoint
from lnbits.settings import settings
from .base import (
@@ -27,7 +28,7 @@ class ZBDWallet(Wallet):
if not settings.zbd_api_key:
raise ValueError("cannot initialize ZBDWallet: missing zbd_api_key")
self.endpoint = self.normalize_endpoint(settings.zbd_api_endpoint)
self.endpoint = normalize_endpoint(settings.zbd_api_endpoint)
headers = {
"apikey": settings.zbd_api_key,
"User-Agent": settings.user_agent,