uncomment webhook_listerner and add TODO

This commit is contained in:
dni ⚡
2023-04-04 07:34:50 +02:00
parent 9c8a79eb9b
commit abfee29676
2 changed files with 46 additions and 40 deletions
+18 -18
View File
@@ -1,10 +1,11 @@
import asyncio
# import hmac
# from http import HTTPStatus
import hmac
from http import HTTPStatus
from typing import AsyncGenerator, Optional
import httpx
from fastapi import HTTPException
from loguru import logger
from lnbits.settings import settings
@@ -17,9 +18,6 @@ from .base import (
Wallet,
)
# from fastapi import Request, HTTPException
# from loguru import logger
class OpenNodeWallet(Wallet):
"""https://developers.opennode.com/"""
@@ -142,17 +140,19 @@ class OpenNodeWallet(Wallet):
value = await self.queue.get()
yield value
# async def webhook_listener(self):
# data = await request.form
# if "status" not in data or data["status"] != "paid":
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
async def webhook_listener(self):
# TODO: request.form is undefined, was it something with Flask or quart?
# probably issue introduced when refactoring?
data = await request.form # type: ignore
if "status" not in data or data["status"] != "paid":
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# charge_id = data["id"]
# x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
# x.update(charge_id.encode("ascii"))
# if x.hexdigest() != data["hashed_order"]:
# logger.error("invalid webhook, not from opennode")
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
charge_id = data["id"]
x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
x.update(charge_id.encode("ascii"))
if x.hexdigest() != data["hashed_order"]:
logger.error("invalid webhook, not from opennode")
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# await self.queue.put(charge_id)
# raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
await self.queue.put(charge_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)