diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 12183aa4..6e43aca4 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -34,15 +34,27 @@ def pay_invoice(*, wallet_id: str, bolt11: str, max_sat: Optional[int] = None) - if max_sat and invoice.amount_msat > max_sat * 1000: raise ValueError("Amount in invoice is too high.") - if invoice.amount_msat > get_wallet(wallet_id).balance_msat: + fee_reserve = max(1000, invoice.amount_msat * 0.01) + create_payment( + wallet_id=wallet_id, + checking_id=temp_id, + amount=-invoice.amount_msat, + fee=-fee_reserve, + memo=temp_id, + ) + + if get_wallet(wallet_id).balance_msat < 0: raise PermissionError("Insufficient balance.") - create_payment(wallet_id=wallet_id, checking_id=temp_id, amount=-invoice.amount_msat, memo=temp_id) ok, checking_id, fee_msat, error_message = WALLET.pay_invoice(bolt11) if ok: create_payment( - wallet_id=wallet_id, checking_id=checking_id, amount=-invoice.amount_msat, memo=invoice.description + wallet_id=wallet_id, + checking_id=checking_id, + amount=-invoice.amount_msat, + fee=fee_msat, + memo=invoice.description, ) except Exception as e: