Skip to content

Commit

Permalink
feat: add payment-method to extra (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
dni authored Aug 30, 2024
1 parent be438da commit 694c483
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}")

Expand Down
3 changes: 3 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 694c483

Please sign in to comment.