Adds fiat currency metadata to payments
Adds fiat currency information to payment invoices and ledger entries. This allows for tracking the fiat value of transactions and provides a more complete financial picture. Calculates the fiat amount proportionally based on the user's balance and includes the fiat currency, amount, and exchange rates in the invoice's extra data. This data is then extracted and added to the ledger entry's metadata when recording the payment.
This commit is contained in:
parent
8f35788e1a
commit
3add13075c
2 changed files with 77 additions and 1 deletions
19
tasks.py
19
tasks.py
|
|
@ -161,6 +161,23 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
# Convert amount from millisatoshis to satoshis
|
||||
amount_sats = payment.amount // 1000
|
||||
|
||||
# Extract fiat metadata from invoice (if present)
|
||||
from decimal import Decimal
|
||||
line_metadata = {}
|
||||
if payment.extra:
|
||||
fiat_currency = payment.extra.get("fiat_currency")
|
||||
fiat_amount = payment.extra.get("fiat_amount")
|
||||
fiat_rate = payment.extra.get("fiat_rate")
|
||||
btc_rate = payment.extra.get("btc_rate")
|
||||
|
||||
if fiat_currency and fiat_amount:
|
||||
line_metadata = {
|
||||
"fiat_currency": fiat_currency,
|
||||
"fiat_amount": str(fiat_amount),
|
||||
"fiat_rate": fiat_rate,
|
||||
"btc_rate": btc_rate,
|
||||
}
|
||||
|
||||
# Get user's receivable account (what user owes)
|
||||
user_receivable = await get_or_create_user_account(
|
||||
user_id, AccountType.ASSET, "Accounts Receivable"
|
||||
|
|
@ -193,12 +210,14 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
debit=amount_sats,
|
||||
credit=0,
|
||||
description="Lightning payment received",
|
||||
metadata=line_metadata,
|
||||
),
|
||||
CreateEntryLine(
|
||||
account_id=user_receivable.id,
|
||||
debit=0,
|
||||
credit=amount_sats,
|
||||
description="Payment applied to balance",
|
||||
metadata=line_metadata,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue