feat: store mor info about the webhook call status

This commit is contained in:
Vlad Stan 2022-12-19 19:42:11 +02:00
parent 681883a8f9
commit c5fdd35078

View File

@ -49,15 +49,22 @@ async def on_invoice_paid(payment: Payment) -> None:
if pay_link.webhook_headers:
kwargs["headers"] = json.loads(pay_link.webhook_headers)
r = await client.post(pay_link.webhook_url, **kwargs)
await mark_webhook_sent(payment, r.status_code)
r: httpx.Response = await client.post(pay_link.webhook_url, **kwargs)
await mark_webhook_sent(
payment, r.status_code, r.is_success, r.reason_phrase, r.text
)
except Exception as ex:
logger.error(ex)
await mark_webhook_sent(payment, -1)
await mark_webhook_sent(payment, -1, False, "Unexpected Error", str(ex))
async def mark_webhook_sent(payment: Payment, status: int) -> None:
payment.extra["wh_status"] = status
async def mark_webhook_sent(
payment: Payment, status: int, is_success: bool, reason_phrase="", text=""
) -> None:
payment.extra["wh_status"] = status # keep for backwards compability
payment.extra["wh_success"] = is_success
payment.extra["wh_message"] = reason_phrase
payment.extra["wh_response"] = text
await core_db.execute(
"""