-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.py
37 lines (30 loc) · 1.18 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import httpx
from lnbits.settings import settings
from .models import ChargeStatus
async def create_charge(data: dict, api_key: str) -> str:
async with httpx.AsyncClient() as client:
headers = {"X-API-KEY": api_key}
r = await client.post(
url=f"http://{settings.host}:{settings.port}/satspay/api/v1/charge",
headers=headers,
json=data,
)
r.raise_for_status()
return r.json()["id"]
async def get_charge_status(charge_id: str, api_key: str) -> ChargeStatus:
async with httpx.AsyncClient() as client:
headers = {"X-API-KEY": api_key}
r = await client.get(
url=f"http://{settings.host}:{settings.port}/satspay/api/v1/charge/{charge_id}",
headers=headers,
)
r.raise_for_status()
return ChargeStatus.parse_obj(r.json())
async def delete_charge(charge_id: str, api_key: str):
async with httpx.AsyncClient() as client:
headers = {"X-API-KEY": api_key}
r = await client.delete(
url=f"http://{settings.host}:{settings.port}/satspay/api/v1/charge/{charge_id}",
headers=headers,
)
r.raise_for_status()