mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-11 04:52:34 +02:00
Get basic working endpoints
This is a setup that works specifically with a hardcoded test wallet
This commit is contained in:
9
lnbits/extensions/TwitchAlerts/crud.py
Normal file
9
lnbits/extensions/TwitchAlerts/crud.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
async def get_charge_details(service):
|
||||||
|
details = {
|
||||||
|
"user": "8ee4d2d2b788467ebbab172ed3d50aaa",
|
||||||
|
"description": "Testing",
|
||||||
|
"lnbitswallet": "e1e7c4f4f86a4905ab413f96fb78aabc",
|
||||||
|
"time": 1440,
|
||||||
|
"amount": 1
|
||||||
|
}
|
||||||
|
return details
|
@@ -1,11 +1,11 @@
|
|||||||
# async def m001_initial(db):
|
async def m001_initial(db):
|
||||||
|
|
||||||
# await db.execute(
|
await db.execute(
|
||||||
# """
|
"""
|
||||||
# CREATE TABLE IF NOT EXISTS TwitchAlerts (
|
CREATE TABLE IF NOT EXISTS TwitchAlerts (
|
||||||
# id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
# wallet TEXT NOT NULL,
|
wallet TEXT NOT NULL,
|
||||||
# time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||||
# );
|
);
|
||||||
# """
|
"""
|
||||||
# )
|
)
|
||||||
|
@@ -1,40 +1,65 @@
|
|||||||
# views_api.py is for you API endpoints that could be hit by another service
|
|
||||||
|
|
||||||
# add your dependencies here
|
|
||||||
|
|
||||||
# import json
|
# import json
|
||||||
# import httpx
|
# import httpx
|
||||||
# (use httpx just like requests, except instead of response.ok there's only the
|
# (use httpx just like requests, except instead of response.ok there's only the
|
||||||
# response.is_error that is its inverse)
|
# response.is_error that is its inverse)
|
||||||
|
|
||||||
from quart import jsonify
|
from quart import g, redirect, request # jsonify
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
|
from lnbits.decorators import api_validate_post_request, api_check_wallet_key
|
||||||
|
|
||||||
from . import TwitchAlerts_ext
|
from . import TwitchAlerts_ext
|
||||||
|
from .crud import get_charge_details
|
||||||
|
from ..satspay.crud import create_charge, get_charge, delete_charge
|
||||||
|
|
||||||
|
|
||||||
# add your endpoints here
|
@TwitchAlerts_ext.route("/api/v1/createdonation", methods=["POST"])
|
||||||
|
@api_check_wallet_key("invoice")
|
||||||
|
@api_validate_post_request(
|
||||||
|
schema={
|
||||||
|
"name": {"type": "string"},
|
||||||
|
"sats": {"type": "integer", "required": True},
|
||||||
|
"service": {"type": "string", "required": True},
|
||||||
|
"cur_code": {"type": "string", "required": True},
|
||||||
|
"amount": {"type": "float", "required": True}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
async def api_create_donation():
|
||||||
|
"""Takes data from donation form and creates+returns SatsPay charge"""
|
||||||
|
webhook_base = request.scheme + "://" + request.headers["Host"]
|
||||||
|
charge_details = await get_charge_details(g.data["service"])
|
||||||
|
charge = await create_charge(
|
||||||
|
webhook=webhook_base + "/TwitchAlerts/api/v1/postdonation",
|
||||||
|
**charge_details)
|
||||||
|
return redirect(f"/satspay/{charge.id}")
|
||||||
|
|
||||||
|
|
||||||
@TwitchAlerts_ext.route("/api/v1/tools", methods=["GET"])
|
@TwitchAlerts_ext.route("/api/v1/postdonation", methods=["POST"])
|
||||||
async def api_TwitchAlerts():
|
# @api_validate_post_request(
|
||||||
"""Try to add descriptions for others."""
|
# schema={
|
||||||
tools = [
|
# "id": {"type": "string", "required": True},
|
||||||
{
|
# "description": {"type": "string", "allow_unknown": True},
|
||||||
"name": "Quart",
|
# "onchainaddress": {"type": "string", "allow_unknown": True},
|
||||||
"url": "https://pgjones.gitlab.io/quart/",
|
# "payment_request": {"type": "string", "allow_unknown": True},
|
||||||
"language": "Python",
|
# "payment_hash": {"type": "string", "allow_unknown": True},
|
||||||
},
|
# "time": {"type": "integer", "allow_unknown": True},
|
||||||
{
|
# "amount": {"type": "integer", "allow_unknown": True},
|
||||||
"name": "Vue.js",
|
# "paid": {"type": "boolean", "allow_unknown": True},
|
||||||
"url": "https://vuejs.org/",
|
# "timestamp": {"type": "integer", "allow_unknown": True},
|
||||||
"language": "JavaScript",
|
# "completelink": {"type": "string", "allow_unknown": True},
|
||||||
},
|
# }
|
||||||
{
|
# )
|
||||||
"name": "Quasar Framework",
|
async def api_post_donation():
|
||||||
"url": "https://quasar.dev/",
|
"""Posts a paid donation to Stremalabs/StreamElements.
|
||||||
"language": "JavaScript",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
return jsonify(tools), HTTPStatus.OK
|
This endpoint acts as a webhook for the SatsPayServer extension."""
|
||||||
|
data = await request.get_json(force=True)
|
||||||
|
charge_id = data["id"]
|
||||||
|
charge = await get_charge(charge_id)
|
||||||
|
print(charge)
|
||||||
|
if charge and charge.paid:
|
||||||
|
await delete_charge(charge_id)
|
||||||
|
print("This endpoint works!")
|
||||||
|
return "", HTTPStatus.OK
|
||||||
|
else:
|
||||||
|
return "", HTTPStatus.OK
|
||||||
|
Reference in New Issue
Block a user