Created
January 6, 2025 18:17
-
-
Save imaginator/0b8244f2f89be2daac251889c354eb52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pull_unpaid_invoices_since(last_timestamp: datetime): | |
""" | |
Lists all payments (both sent and received). | |
""" | |
if not sdk_services: | |
raise RuntimeError("Breez SDK not connected yet. Call connect_breez() first.") | |
last_timestamp = 0 | |
print("Last Timestamp: ", last_timestamp) | |
try: | |
req = breez_sdk_liquid.ListPaymentsRequest( | |
[breez_sdk_liquid.PaymentType.RECEIVE], | |
from_timestamp=last_timestamp, | |
offset=0, | |
limit=50, | |
) | |
print("Request", req) | |
new_payments = sdk_services.list_payments(req) | |
print("New Payments: ", new_payments) | |
count_marked = 0 | |
for p in new_payments: | |
print("Payment: ", p) | |
if p.status == breez_sdk_liquid.PaymentState.COMPLETE: | |
print("Payment paid when application starts") | |
bolt11_of_this_payment = p.destination | |
print("Bolt11 of the unpaid invoice: ", bolt11_of_this_payment) | |
mark_invoice_as_paid_in_db(bolt11_of_this_payment) | |
count_marked += 1 | |
logging.info(f"[pull_unpaid_invoices_since] Marked {count_marked} new invoices as paid!") | |
except Exception as e: | |
logging.error(f"Error listing payments: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment