Skip to content

Commit f41b86c

Browse files
authored
Merge pull request #195 from lightsparkdev/release/lightspark-sdk-v0.16.0
Merge release/lightspark-sdk-v0.16.0 into main
2 parents 3cc7db6 + d2cd40a commit f41b86c

File tree

14 files changed

+172
-3
lines changed

14 files changed

+172
-3
lines changed

lightspark-sdk/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Start by installing the SDK from maven:
1717
**build.gradle:**
1818
```groovy
1919
dependencies {
20-
implementation "com.lightspark:lightspark-sdk:0.15.1"
20+
implementation "com.lightspark:lightspark-sdk:0.16.0"
2121
}
2222
```
2323

2424
or with **build.gradle.kts:**
2525
```kotlin
2626
dependencies {
27-
implementation("com.lightspark:lightspark-sdk:0.15.1")
27+
implementation("com.lightspark:lightspark-sdk:0.16.0")
2828
}
2929
```
3030

lightspark-sdk/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GROUP=com.lightspark
22
POM_ARTIFACT_ID=lightspark-sdk
33
# Don't bump this manually. Run `scripts/versions.main.kt <new_version>` to bump the version instead.
4-
VERSION_NAME=0.15.1
4+
VERSION_NAME=0.16.0
55

66
POM_DESCRIPTION=The Lightspark API SDK for Kotlin and Java.
77
POM_INCEPTION_YEAR=2023

lightspark-sdk/src/commonJvmAndroidMain/kotlin/com/lightspark/sdk/LightsparkFuturesClient.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,22 @@ class LightsparkFuturesClient(config: ClientConfig) {
576576
coroutinesClient.getOutgoingPaymentsForInvoice(encodedInvoice, transactionStatuses)
577577
}
578578

579+
/**
580+
* Fetch incoming payments for a given payment hash.
581+
*
582+
* @param paymentHash The payment hash of the invoice for which to fetch the incoming payments.
583+
* @param transactionStatuses The transaction statuses to filter the payments by. If null, all payments will be
584+
* returned.
585+
* @return The list of incoming payments for the payment hash.
586+
*/
587+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class)
588+
fun getIncomingPaymentsForPaymentHash(
589+
paymentHash: String,
590+
transactionStatuses: List<TransactionStatus>? = null,
591+
): CompletableFuture<List<IncomingPayment>> = coroutineScope.future {
592+
coroutinesClient.getIncomingPaymentsForPaymentHash(paymentHash, transactionStatuses)
593+
}
594+
579595
/**
580596
* Creates an UMA invitation. If you are part of the incentive program you should use
581597
* [createUmaInvitationWithIncentives].

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkCoroutinesClient.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,37 @@ class LightsparkCoroutinesClient private constructor(
10051005
)
10061006
}
10071007

1008+
/**
1009+
* Fetch incoming payments for a given payment hash.
1010+
*
1011+
* @param paymentHash The payment hash of the invoice for which to fetch the incoming payments.
1012+
* @param transactionStatuses The transaction statuses to filter the payments by. If null, all payments will be
1013+
* returned.
1014+
*/
1015+
suspend fun getIncomingPaymentsForPaymentHash(
1016+
paymentHash: String,
1017+
transactionStatuses: List<TransactionStatus>? = null,
1018+
): List<IncomingPayment> {
1019+
requireValidAuth()
1020+
return executeQuery(
1021+
Query(
1022+
IncomingPaymentsForPaymentHashQuery,
1023+
{
1024+
add("paymentHash", paymentHash)
1025+
transactionStatuses?.let {
1026+
add("transactionStatuses", serializerFormat.encodeToJsonElement(it))
1027+
}
1028+
},
1029+
) {
1030+
val outputJson =
1031+
requireNotNull(it["incoming_payments_for_payment_hash"]) { "No payment output found in response" }
1032+
val paymentsJson =
1033+
requireNotNull(outputJson.jsonObject["payments"]) { "No payments found in response" }
1034+
serializerFormat.decodeFromJsonElement(paymentsJson)
1035+
},
1036+
)
1037+
}
1038+
10081039
/**
10091040
* Creates an UMA invitation. If you are part of the incentive program you should use
10101041
* [createUmaInvitationWithIncentives].

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkSyncClient.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,22 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
560560
asyncClient.getOutgoingPaymentsForInvoice(encodedInvoice, transactionStatuses)
561561
}
562562

563+
/**
564+
* Fetch incoming payments for a given payment hash.
565+
*
566+
* @param paymentHash The payment hash of the invoice for which to fetch the incoming payments.
567+
* @param transactionStatuses The transaction statuses to filter the payments by. If null, all payments will be
568+
* returned.
569+
* @return The list of incoming payments for the payment hash.
570+
*/
571+
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
572+
fun getIncomingPaymentsForPaymentHash(
573+
paymentHash: String,
574+
transactionStatuses: List<TransactionStatus>? = null,
575+
): List<IncomingPayment> = runBlocking {
576+
asyncClient.getIncomingPaymentsForPaymentHash(paymentHash, transactionStatuses)
577+
}
578+
563579
/**
564580
* Creates an UMA invitation. If you are part of the incentive program you should use
565581
* [createUmaInvitationWithIncentives].
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.lightspark.sdk.graphql
2+
3+
import com.lightspark.sdk.model.IncomingPayment
4+
5+
const val IncomingPaymentsForPaymentHashQuery = """
6+
query OutgoingPaymentsForInvoice(
7+
${'$'}paymentHash: Hash32!,
8+
${'$'}transactionStatuses: [TransactionStatus!] = null
9+
) {
10+
incoming_payments_for_payment_hash(input: {
11+
payment_hash: ${'$'}paymentHash,
12+
statuses: ${'$'}transactionStatuses
13+
}) {
14+
payments {
15+
...IncomingPaymentFragment
16+
}
17+
}
18+
}
19+
20+
${IncomingPayment.FRAGMENT}
21+
"""

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/model/Account.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,8 @@ query FetchAccountToPaymentRequestsConnection(${'$'}first: Int, ${'$'}after: Str
16651665
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
16661666
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
16671667
}
1668+
invoice_is_uma: is_uma
1669+
invoice_is_lnurl: is_lnurl
16681670
}
16691671
}
16701672
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2+
@file:Suppress("ktlint:standard:max-line-length")
3+
4+
package com.lightspark.sdk.model
5+
6+
import kotlinx.serialization.SerialName
7+
import kotlinx.serialization.Serializable
8+
9+
/**
10+
*
11+
* @param paymentHash The 32-byte hash of the payment preimage for which to fetch payments
12+
* @param statuses An optional filter to only query incoming payments of given statuses.
13+
*/
14+
@Serializable
15+
@SerialName("IncomingPaymentsForPaymentHashQueryInput")
16+
data class IncomingPaymentsForPaymentHashQueryInput(
17+
val paymentHash: String,
18+
val statuses: List<TransactionStatus>? = null,
19+
) {
20+
companion object {
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2+
@file:Suppress("ktlint:standard:max-line-length")
3+
4+
package com.lightspark.sdk.model
5+
6+
import kotlinx.serialization.SerialName
7+
import kotlinx.serialization.Serializable
8+
9+
/**
10+
*
11+
*/
12+
@Serializable
13+
@SerialName("IncomingPaymentsForPaymentHashQueryOutput")
14+
data class IncomingPaymentsForPaymentHashQueryOutput(
15+
@SerialName("incoming_payments_for_payment_hash_query_output_payments")
16+
val payments: List<IncomingPayment>,
17+
) {
18+
companion object {
19+
const val FRAGMENT = """
20+
fragment IncomingPaymentsForPaymentHashQueryOutputFragment on IncomingPaymentsForPaymentHashQueryOutput {
21+
type: __typename
22+
incoming_payments_for_payment_hash_query_output_payments: payments {
23+
id
24+
}
25+
}"""
26+
}
27+
}

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/model/Invoice.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import kotlinx.serialization.json.decodeFromJsonElement
1919
* @param data The details of the invoice.
2020
* @param status The status of the payment request.
2121
* @param amountPaid The total amount that has been paid to this invoice.
22+
* @param isUma Whether this invoice is an UMA invoice or not. NOTE: this field is only set if the invoice was created using the recommended `create_uma_invoice` function.
23+
* @param isLnurl Whether this invoice is an LNURL invoice or not. NOTE: this field is only set if the invoice was created using the recommended `create_lnurl_invoice` function.
2224
*/
2325
@Serializable
2426
@SerialName("Invoice")
@@ -35,6 +37,10 @@ data class Invoice(
3537
override val status: PaymentRequestStatus,
3638
@SerialName("invoice_amount_paid")
3739
val amountPaid: CurrencyAmount? = null,
40+
@SerialName("invoice_is_uma")
41+
val isUma: Boolean? = null,
42+
@SerialName("invoice_is_lnurl")
43+
val isLnurl: Boolean? = null,
3844
) : PaymentRequest,
3945
Entity {
4046
companion object {
@@ -363,6 +369,8 @@ fragment InvoiceFragment on Invoice {
363369
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
364370
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
365371
}
372+
invoice_is_uma: is_uma
373+
invoice_is_lnurl: is_lnurl
366374
}"""
367375
}
368376
}

0 commit comments

Comments
 (0)