Skip to content

add create invitation with payment mutation #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,25 @@ class LightsparkFuturesClient(config: ClientConfig) {
fun setBitcoinNetwork(network: BitcoinNetwork) {
defaultBitcoinNetwork = network
}

/**
* Creates an UMA invitation with payment.
*
* @param inviterUma The UMA of the inviter.
* @param paymentAmount The payment amount.
* @param paymentCurrency The payment currency input.
* @param expiresAt The expiration date/time (ISO8601 string).
* @return The invitation that was created.
*/
fun createUmaInvitationWithPayment(
inviterUma: String,
paymentAmount: Long,
paymentCurrency: PaymentCurrencyInput,
expiresAt: String,
): CompletableFuture<UmaInvitation> =
coroutineScope.future {
coroutinesClient.createUmaInvitationWithPayment(inviterUma, paymentAmount, paymentCurrency, expiresAt)
}
}

fun <T> Query<T>.execute(client: LightsparkFuturesClient): CompletableFuture<T> = client.executeQuery(this)
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,41 @@ class LightsparkCoroutinesClient private constructor(
)
}

/**
* Creates an UMA invitation with payment.
*
* @param inviterUma The UMA of the inviter.
* @param paymentAmount The payment amount.
* @param paymentCurrency The payment currency input.
* @param expiresAt The expiration date/time (ISO8601 string).
* @return The invitation that was created.
*/
suspend fun createUmaInvitationWithPayment(
inviterUma: String,
paymentAmount: Long,
paymentCurrency: PaymentCurrencyInput,
expiresAt: String,
): UmaInvitation {
requireValidAuth()
return executeQuery(
Query(
CreateUmaInvitationWithPayment,
{
add("inviter_uma", inviterUma)
add("payment_amount", paymentAmount)
add("payment_currency", serializerFormat.encodeToJsonElement(paymentCurrency))
add("expires_at", expiresAt)
},
) {
val outputJson =
requireNotNull(it["create_uma_invitation_with_payment"]) { "No invitation output found in response" }
val invitationJson =
requireNotNull(outputJson.jsonObject["invitation"]) { "No invitation found in response" }
serializerFormat.decodeFromJsonElement(invitationJson)
},
)
}

/**
* Claims an UMA invitation. If you are part of the incentive program, you should use
* [claimUmaInvitationWithIncentives].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,25 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
asyncClient.createUmaInvitationWithIncentives(inviterUma, inviterPhoneNumberE164, inviterRegionCode)
}

/**
* Creates an UMA invitation with payment.
*
* @param inviterUma The UMA of the inviter.
* @param paymentAmount The payment amount.
* @param paymentCurrency The payment currency input.
* @param expiresAt The expiration date/time (ISO8601 string).
* @return The invitation that was created.
*/
@Throws(LightsparkException::class, LightsparkAuthenticationException::class, CancellationException::class)
fun createUmaInvitationWithPayment(
inviterUma: String,
paymentAmount: Long,
paymentCurrency: PaymentCurrencyInput,
expiresAt: String,
): UmaInvitation = runBlocking {
asyncClient.createUmaInvitationWithPayment(inviterUma, paymentAmount, paymentCurrency, expiresAt)
}

/**
* Claims an UMA invitation. If you are part of the incentive program, you should use
* [claimUmaInvitationWithIncentives].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lightspark.sdk.graphql

import com.lightspark.sdk.model.UmaInvitation

const val CreateUmaInvitationWithPayment = """
mutation CreateUmaInvitationWithPayment(
${'$'}inviter_uma: String!
${'$'}payment_amount: Long!
${'$'}payment_currency: PaymentCurrencyInput!
${'$'}expires_at: DateTime!
) {
create_uma_invitation_with_payment(input: {
inviter_uma: ${'$'}inviter_uma
payment_amount: ${'$'}payment_amount
payment_currency: ${'$'}payment_currency
expires_at: ${'$'}expires_at
}) {
invitation {
...UmaInvitationFragment
}
}
}

${UmaInvitation.FRAGMENT}
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lightspark.sdk.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* @param code The currency code (e.g., "USD", "BTC").
* @param symbol The currency symbol (e.g., "$", "₿").
* @param name The full name of the currency (e.g., "US Dollar").
* @param decimals The number of decimal places for the currency.
*/
@Serializable
@SerialName("PaymentCurrencyInput")
data class PaymentCurrencyInput(
val code: String,
val symbol: String,
val name: String,
val decimals: Int
)
Loading