Skip to content

Commit

Permalink
Add incoming_payments_for_invoice query (#31)
Browse files Browse the repository at this point in the history
Also bumping the version to 2.6.0.
  • Loading branch information
jklein24 authored Mar 8, 2024
2 parents 60e2b1e + fc5246c commit 5dbcf54
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# v2.6.0

- Use a 64-bit nonce for signed requests to avoid conflicts.
- Add `is_internal_payment` fields to payment objects.
- Add `multisig_wallet_address_validation_parameters` to support validating node wallet addresses used for deposits.
- Add `incoming_payments_for_invoice` to get all incoming payments for an invoice.

# v2.5.1

- Ensure that the README and LICENSE are included in the pypi package.
Expand Down
32 changes: 32 additions & 0 deletions lightspark/lightspark_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from lightspark.objects.FeeEstimate import from_json as FeeEstimate_from_json
from lightspark.objects.IncomingPayment import IncomingPayment
from lightspark.objects.IncomingPayment import from_json as IncomingPayment_from_json
from lightspark.objects.IncomingPaymentsForInvoiceQueryOutput import (
from_json as IncomingPaymentsForInvoiceQueryOutput_from_json,
)
from lightspark.objects.Invoice import Invoice
from lightspark.objects.Invoice import from_json as Invoice_from_json
from lightspark.objects.InvoiceData import InvoiceData
Expand Down Expand Up @@ -83,6 +86,9 @@
from lightspark.scripts.delete_api_token import DELETE_API_TOKEN_MUTATION
from lightspark.scripts.fetch_uma_invitation import FETCH_UMA_INVITATION_QUERY
from lightspark.scripts.fund_node import FUND_NODE_MUTATION
from lightspark.scripts.incoming_payments_for_invoice import (
INCOMING_PAYMENTS_FOR_INVOICE_QUERY,
)
from lightspark.scripts.lightning_fee_estimate_for_invoice import (
LIGHTNING_FEE_ESTIMATE_FOR_INVOICE_QUERY,
)
Expand Down Expand Up @@ -686,6 +692,32 @@ def outgoing_payments_for_invoice(
for payment in json["outgoing_payments_for_invoice"]["payments"]
]

def incoming_payments_for_invoice(
self,
invoice_id: str,
transaction_statuses: Optional[List[TransactionStatus]] = None,
) -> List[IncomingPayment]:
"""
Fetches the incoming payments (if any) which have been made for a given invoice.
Args:
invoice_id: The encoded invoice for which to fetch the incoming payments.
transaction_statuses: The statuses of the transactions to fetch. If not specified, all transactions will be fetched.
"""

variables: Dict[str, Any] = {"invoice_id": invoice_id}
if transaction_statuses is not None:
variables["transaction_statuses"] = transaction_statuses
json = self._requester.execute_graphql(
INCOMING_PAYMENTS_FOR_INVOICE_QUERY, variables
)
if "incoming_payments_for_invoice" not in json:
return []
output = IncomingPaymentsForInvoiceQueryOutput_from_json(
self._requester, json["incoming_payments_for_invoice"]
)
return output.payments

def create_uma_invitation(
self,
inviter_uma: str,
Expand Down
21 changes: 21 additions & 0 deletions lightspark/scripts/incoming_payments_for_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from lightspark.objects.IncomingPaymentsForInvoiceQueryOutput import (
FRAGMENT as IncomingPaymentsForInvoiceQueryOutputFragment,
)

INCOMING_PAYMENTS_FOR_INVOICE_QUERY = f"""
query IncomingPaymentsForInvoice(
$invoice_id: ID!
$transaction_statuses: [TransactionStatus!]
) {{
incoming_payments_for_invoice(input: {{
invoice_id: $invoice_id
transaction_statuses: $statuses
}}) {{
...IncomingPaymentsForInvoiceQueryOutputFragment
}}
}}
{IncomingPaymentsForInvoiceQueryOutputFragment}
"""
2 changes: 1 addition & 1 deletion lightspark/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.5.1"
__version__ = "2.6.0"

0 comments on commit 5dbcf54

Please sign in to comment.