Skip to content

Commit e126442

Browse files
authored
Merge pull request #6 from lightsparkdev/feat/outgoingpaymentsforinvoice
Add a call to get outgoing payments for an invoice
2 parents 5e6714e + 2f6aede commit e126442

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

examples/example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@
240240
print(f"Payment to the invoice done with ID = {payment.id}")
241241
print("")
242242

243+
outgoing_payments = client.outgoing_payments_for_invoice(
244+
encoded_invoice=test_invoice, # replace test_invoice with real encoded invoice in non-test mode
245+
)
246+
print(f"Outgoing payments for invoice {test_invoice}:")
247+
for outgoing_payment in outgoing_payments:
248+
print(f" - {outgoing_payment.id}")
249+
print("")
250+
243251
# Key Send sample
244252
#
245253
# payment = client.send_payment(

lightspark/lightspark_client.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass
55
from datetime import datetime, timedelta, timezone
66
from hashlib import sha256
7-
from typing import Any, Dict, Mapping, Optional, Tuple, Type, TypeVar
7+
from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, TypeVar
88

99
import jwt
1010
from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey
@@ -46,6 +46,7 @@
4646
from lightspark.objects.PaymentRequestData import PaymentRequestData
4747
from lightspark.objects.Permission import Permission
4848
from lightspark.objects.RiskRating import RiskRating
49+
from lightspark.objects.TransactionStatus import TransactionStatus
4950
from lightspark.objects.WithdrawalMode import WithdrawalMode
5051
from lightspark.objects.WithdrawalRequest import WithdrawalRequest
5152
from lightspark.objects.WithdrawalRequest import (
@@ -74,6 +75,9 @@
7475
from lightspark.scripts.lightning_fee_estimate_for_node import (
7576
LIGHTNING_FEE_ESTIMATE_FOR_NODE_QUERY,
7677
)
78+
from lightspark.scripts.outgoing_payments_for_invoice import (
79+
OUTGOING_PAYMENTS_FOR_INVOICE_QUERY,
80+
)
7781
from lightspark.scripts.pay_invoice import PAY_INVOICE_MUTATION
7882
from lightspark.scripts.pay_uma_invoice import PAY_UMA_INVOICE_MUTATION
7983
from lightspark.scripts.recover_node_signing_key import RECOVER_NODE_SIGNING_KEY_QUERY
@@ -621,3 +625,31 @@ def register_payment(
621625
return LightningTransaction_from_json(
622626
self._requester, json["register_payment"]["payment"]
623627
)
628+
629+
def outgoing_payments_for_invoice(
630+
self,
631+
encoded_invoice: str,
632+
transaction_statuses: Optional[List[TransactionStatus]] = None,
633+
) -> List[OutgoingPayment]:
634+
"""
635+
Fetches the outgoing payments (if any) which have been made for a given invoice.
636+
637+
Args:
638+
encoded_invoice: The encoded invoice for which to fetch the outgoing payments.
639+
transaction_statuses: The statuses of the transactions to fetch. If not specified, all transactions will be fetched.
640+
"""
641+
642+
variables: Dict[str, Any] = {"encoded_invoice": encoded_invoice}
643+
if transaction_statuses is not None:
644+
variables["transaction_statuses"] = transaction_statuses
645+
json = self._requester.execute_graphql(
646+
OUTGOING_PAYMENTS_FOR_INVOICE_QUERY, variables
647+
)
648+
if "outgoing_payments_for_invoice" not in json:
649+
return []
650+
if "payments" not in json["outgoing_payments_for_invoice"]:
651+
return []
652+
return [
653+
OutgoingPayment_from_json(self._requester, payment)
654+
for payment in json["outgoing_payments_for_invoice"]["payments"]
655+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from lightspark.objects.OutgoingPayment import FRAGMENT as OutgoingPaymentFragment
4+
5+
OUTGOING_PAYMENTS_FOR_INVOICE_QUERY = f"""
6+
query OutgoingPaymentsForInvoice(
7+
$encoded_invoice: String!,
8+
$transaction_statuses: [TransactionStatus!] = null
9+
) {{
10+
outgoing_payments_for_invoice(input: {{
11+
encoded_invoice: $encoded_invoice,
12+
statuses: $transaction_statuses
13+
}}) {{
14+
payments {{
15+
...OutgoingPaymentFragment
16+
}}
17+
}}
18+
}}
19+
20+
{OutgoingPaymentFragment}
21+
"""

0 commit comments

Comments
 (0)