From 694c4837a6d7efec05c93f034adb6c597bb321ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Aug 2024 17:48:08 +0200 Subject: [PATCH] feat: add payment-method to extra (#70) --- helpers.py | 2 ++ tasks.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/helpers.py b/helpers.py index d49e4b6..dd67dbe 100644 --- a/helpers.py +++ b/helpers.py @@ -92,6 +92,7 @@ async def check_charge_balance(charge: Charge) -> Charge: assert payment, "Payment not found." status = await payment.check_status() if status.success: + charge.add_extra({"payment_method": "lightning"}) charge.balance = charge.amount if charge.onchainaddress: @@ -108,6 +109,7 @@ async def check_charge_balance(charge: Charge) -> Charge: else balance.confirmed ) charge.pending = balance.unconfirmed + charge.add_extra({"payment_method": "onchain"}) except Exception as exc: logger.warning(f"Charge check onchain address failed with: {exc!s}") diff --git a/tasks.py b/tasks.py index f3190ed..0f429ff 100644 --- a/tasks.py +++ b/tasks.py @@ -31,6 +31,7 @@ async def restart_address_tracking(): charge = await check_charge_balance(charge) assert charge.onchainaddress if charge.paid: + charge.add_extra({"payment_method": "onchain"}) await update_charge(charge) logger.success(f"Charge {charge.id} marked as paid.") continue @@ -77,6 +78,7 @@ async def on_invoice_paid(payment: Payment) -> None: charge.balance = int(payment.amount / 1000) charge.paid = True logger.success(f"Charge {charge.id} invoice paid.") + charge.add_extra({"payment_method": "lightning"}) await send_success_websocket(charge) if charge.webhook: resp = await call_webhook(charge) @@ -124,6 +126,7 @@ async def _handle_ws_message(address: str, data: dict): charge.paid = charge.balance >= charge.amount await send_success_websocket(charge) if charge.paid: + charge.add_extra({"payment_method": "onchain"}) logger.success(f"Charge {charge.id} onchain paid.") stop_onchain_listener(address) if charge.webhook: