Skip to content

Commit

Permalink
Add OutgoingPaymentsForInvoice query. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored Dec 21, 2023
2 parents a53a8fc + a7f0023 commit 729ffa4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/outgoing_payments_for_invoice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scripts

import "github.com/lightsparkdev/go-sdk/objects"

const OUTGOING_PAYMENTS_FOR_INVOICE_QUERY = `
query OutgoingPaymentsForInvoice(
$encoded_invoice: String!
$statuses: [PaymentStatus!]
} {
outgoing_payments_for_invoice_query(input: {
encoded_invoice: $encoded_invoice
statuses: $statuses
}) {
...OutgoingPaymentsForInvoiceQueryOutputFragment
}
}
` + objects.OutgoingPaymentsForInvoiceQueryOutputFragment
22 changes: 22 additions & 0 deletions services/lightspark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,28 @@ func (client *LightsparkClient) GetWithdrawalFeeEstimate(nodeId string, amountSa
return &feeEstimate, nil
}

func (client *LightsparkClient) FetchOutgoingPaymentsByInvoice(encodedInvoice string,
statuses *[]objects.TransactionStatus) (*objects.OutgoingPaymentsForInvoiceQueryOutput, error) {
variables := map[string]interface{}{
"encoded_invoice": encodedInvoice,
"statuses": statuses,
}

response, err := client.Requester.ExecuteGraphql(scripts.OUTGOING_PAYMENTS_FOR_INVOICE_QUERY, variables, nil)
if err != nil {
return nil, err
}

output := response["outgoing_payments_for_invoice"].(map[string]interface{})
var payments objects.OutgoingPaymentsForInvoiceQueryOutput
paymentsJson, err := json.Marshal(output)
if err != nil {
return nil, errors.New("error parsing payments")
}
json.Unmarshal(paymentsJson, &payments)
return &payments, nil
}

func hashPhoneNumber(e614PhoneNumber string) (*string, error) {
e164PhoneRegex, err := regexp.Compile(`^\+?[1-9]\d{1,14}$`)
if err != nil {
Expand Down

0 comments on commit 729ffa4

Please sign in to comment.