Skip to content

Commit

Permalink
feat(api): updates (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Nov 16, 2023
1 parent b8618b0 commit 3d2b816
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.lithic.api.core.toUnmodifiable
import com.lithic.api.errors.LithicInvalidDataException
import java.time.OffsetDateTime
import java.util.Objects
import java.util.Optional

@JsonDeserialize(builder = DigitalCardArt.Builder::class)
@NoAutoDetect
Expand All @@ -24,6 +25,7 @@ private constructor(
private val token: JsonField<String>,
private val cardProgramToken: JsonField<String>,
private val isEnabled: JsonField<Boolean>,
private val isCardProgramDefault: JsonField<Boolean>,
private val created: JsonField<OffsetDateTime>,
private val network: JsonField<Network>,
private val description: JsonField<String>,
Expand All @@ -43,6 +45,10 @@ private constructor(
/** Whether the card art is enabled. */
fun isEnabled(): Boolean = isEnabled.getRequired("is_enabled")

/** Whether the card art is the default card art to be added upon tokenization. */
fun isCardProgramDefault(): Optional<Boolean> =
Optional.ofNullable(isCardProgramDefault.getNullable("is_card_program_default"))

/** Timestamp of when card art was created. */
fun created(): OffsetDateTime = created.getRequired("created")

Expand All @@ -61,6 +67,11 @@ private constructor(
/** Whether the card art is enabled. */
@JsonProperty("is_enabled") @ExcludeMissing fun _isEnabled() = isEnabled

/** Whether the card art is the default card art to be added upon tokenization. */
@JsonProperty("is_card_program_default")
@ExcludeMissing
fun _isCardProgramDefault() = isCardProgramDefault

/** Timestamp of when card art was created. */
@JsonProperty("created") @ExcludeMissing fun _created() = created

Expand All @@ -79,6 +90,7 @@ private constructor(
token()
cardProgramToken()
isEnabled()
isCardProgramDefault()
created()
network()
description()
Expand All @@ -97,6 +109,7 @@ private constructor(
this.token == other.token &&
this.cardProgramToken == other.cardProgramToken &&
this.isEnabled == other.isEnabled &&
this.isCardProgramDefault == other.isCardProgramDefault &&
this.created == other.created &&
this.network == other.network &&
this.description == other.description &&
Expand All @@ -110,6 +123,7 @@ private constructor(
token,
cardProgramToken,
isEnabled,
isCardProgramDefault,
created,
network,
description,
Expand All @@ -120,7 +134,7 @@ private constructor(
}

override fun toString() =
"DigitalCardArt{token=$token, cardProgramToken=$cardProgramToken, isEnabled=$isEnabled, created=$created, network=$network, description=$description, additionalProperties=$additionalProperties}"
"DigitalCardArt{token=$token, cardProgramToken=$cardProgramToken, isEnabled=$isEnabled, isCardProgramDefault=$isCardProgramDefault, created=$created, network=$network, description=$description, additionalProperties=$additionalProperties}"

companion object {

Expand All @@ -132,6 +146,7 @@ private constructor(
private var token: JsonField<String> = JsonMissing.of()
private var cardProgramToken: JsonField<String> = JsonMissing.of()
private var isEnabled: JsonField<Boolean> = JsonMissing.of()
private var isCardProgramDefault: JsonField<Boolean> = JsonMissing.of()
private var created: JsonField<OffsetDateTime> = JsonMissing.of()
private var network: JsonField<Network> = JsonMissing.of()
private var description: JsonField<String> = JsonMissing.of()
Expand All @@ -142,6 +157,7 @@ private constructor(
this.token = digitalCardArt.token
this.cardProgramToken = digitalCardArt.cardProgramToken
this.isEnabled = digitalCardArt.isEnabled
this.isCardProgramDefault = digitalCardArt.isCardProgramDefault
this.created = digitalCardArt.created
this.network = digitalCardArt.network
this.description = digitalCardArt.description
Expand Down Expand Up @@ -175,6 +191,17 @@ private constructor(
@ExcludeMissing
fun isEnabled(isEnabled: JsonField<Boolean>) = apply { this.isEnabled = isEnabled }

/** Whether the card art is the default card art to be added upon tokenization. */
fun isCardProgramDefault(isCardProgramDefault: Boolean) =
isCardProgramDefault(JsonField.of(isCardProgramDefault))

/** Whether the card art is the default card art to be added upon tokenization. */
@JsonProperty("is_card_program_default")
@ExcludeMissing
fun isCardProgramDefault(isCardProgramDefault: JsonField<Boolean>) = apply {
this.isCardProgramDefault = isCardProgramDefault
}

/** Timestamp of when card art was created. */
fun created(created: OffsetDateTime) = created(JsonField.of(created))

Expand Down Expand Up @@ -218,6 +245,7 @@ private constructor(
token,
cardProgramToken,
isEnabled,
isCardProgramDefault,
created,
network,
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import com.lithic.api.core.NoAutoDetect
import com.lithic.api.core.toUnmodifiable
import com.lithic.api.errors.LithicInvalidDataException
import com.lithic.api.models.*
import java.time.OffsetDateTime
import java.util.Objects
import java.util.Optional

class PaymentListParams
constructor(
private val begin: OffsetDateTime?,
private val end: OffsetDateTime?,
private val endingBefore: String?,
private val financialAccountToken: String?,
private val pageSize: Long?,
Expand All @@ -24,6 +27,10 @@ constructor(
private val additionalHeaders: Map<String, List<String>>,
) {

fun begin(): Optional<OffsetDateTime> = Optional.ofNullable(begin)

fun end(): Optional<OffsetDateTime> = Optional.ofNullable(end)

fun endingBefore(): Optional<String> = Optional.ofNullable(endingBefore)

fun financialAccountToken(): Optional<String> = Optional.ofNullable(financialAccountToken)
Expand All @@ -39,6 +46,8 @@ constructor(
@JvmSynthetic
internal fun getQueryParams(): Map<String, List<String>> {
val params = mutableMapOf<String, List<String>>()
this.begin?.let { params.put("begin", listOf(it.toString())) }
this.end?.let { params.put("end", listOf(it.toString())) }
this.endingBefore?.let { params.put("ending_before", listOf(it.toString())) }
this.financialAccountToken?.let {
params.put("financial_account_token", listOf(it.toString()))
Expand All @@ -63,6 +72,8 @@ constructor(
}

return other is PaymentListParams &&
this.begin == other.begin &&
this.end == other.end &&
this.endingBefore == other.endingBefore &&
this.financialAccountToken == other.financialAccountToken &&
this.pageSize == other.pageSize &&
Expand All @@ -75,6 +86,8 @@ constructor(

override fun hashCode(): Int {
return Objects.hash(
begin,
end,
endingBefore,
financialAccountToken,
pageSize,
Expand All @@ -87,7 +100,7 @@ constructor(
}

override fun toString() =
"PaymentListParams{endingBefore=$endingBefore, financialAccountToken=$financialAccountToken, pageSize=$pageSize, result=$result, startingAfter=$startingAfter, status=$status, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}"
"PaymentListParams{begin=$begin, end=$end, endingBefore=$endingBefore, financialAccountToken=$financialAccountToken, pageSize=$pageSize, result=$result, startingAfter=$startingAfter, status=$status, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}"

fun toBuilder() = Builder().from(this)

Expand All @@ -99,6 +112,8 @@ constructor(
@NoAutoDetect
class Builder {

private var begin: OffsetDateTime? = null
private var end: OffsetDateTime? = null
private var endingBefore: String? = null
private var financialAccountToken: String? = null
private var pageSize: Long? = null
Expand All @@ -110,6 +125,8 @@ constructor(

@JvmSynthetic
internal fun from(paymentListParams: PaymentListParams) = apply {
this.begin = paymentListParams.begin
this.end = paymentListParams.end
this.endingBefore = paymentListParams.endingBefore
this.financialAccountToken = paymentListParams.financialAccountToken
this.pageSize = paymentListParams.pageSize
Expand All @@ -120,6 +137,18 @@ constructor(
additionalHeaders(paymentListParams.additionalHeaders)
}

/**
* Date string in RFC 3339 format. Only entries created after the specified time will be
* included. UTC time zone.
*/
fun begin(begin: OffsetDateTime) = apply { this.begin = begin }

/**
* Date string in RFC 3339 format. Only entries created before the specified time will be
* included. UTC time zone.
*/
fun end(end: OffsetDateTime) = apply { this.end = end }

/**
* A cursor representing an item's token before which a page of results should end. Used to
* retrieve the previous page of results before this item.
Expand Down Expand Up @@ -185,6 +214,8 @@ constructor(

fun build(): PaymentListParams =
PaymentListParams(
begin,
end,
endingBefore,
financialAccountToken,
pageSize,
Expand Down Expand Up @@ -275,53 +306,47 @@ constructor(

companion object {

@JvmField val DECLINED = Status(JsonField.of("DECLINED"))

@JvmField val PENDING = Status(JsonField.of("PENDING"))

@JvmField val VOIDED = Status(JsonField.of("VOIDED"))
@JvmField val RETURNED = Status(JsonField.of("RETURNED"))

@JvmField val SETTLED = Status(JsonField.of("SETTLED"))

@JvmField val DECLINED = Status(JsonField.of("DECLINED"))

@JvmField val EXPIRED = Status(JsonField.of("EXPIRED"))

@JvmStatic fun of(value: String) = Status(JsonField.of(value))
}

enum class Known {
DECLINED,
PENDING,
VOIDED,
RETURNED,
SETTLED,
DECLINED,
EXPIRED,
}

enum class Value {
DECLINED,
PENDING,
VOIDED,
RETURNED,
SETTLED,
DECLINED,
EXPIRED,
_UNKNOWN,
}

fun value(): Value =
when (this) {
DECLINED -> Value.DECLINED
PENDING -> Value.PENDING
VOIDED -> Value.VOIDED
RETURNED -> Value.RETURNED
SETTLED -> Value.SETTLED
DECLINED -> Value.DECLINED
EXPIRED -> Value.EXPIRED
else -> Value._UNKNOWN
}

fun known(): Known =
when (this) {
DECLINED -> Known.DECLINED
PENDING -> Known.PENDING
VOIDED -> Known.VOIDED
RETURNED -> Known.RETURNED
SETTLED -> Known.SETTLED
DECLINED -> Known.DECLINED
EXPIRED -> Known.EXPIRED
else -> throw LithicInvalidDataException("Unknown Status: $value")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DigitalCardArtTest {
.description("string")
.isEnabled(true)
.network(DigitalCardArt.Network.MASTERCARD)
.isCardProgramDefault(true)
.build()
assertThat(digitalCardArt).isNotNull
assertThat(digitalCardArt.token()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
Expand All @@ -28,5 +29,6 @@ class DigitalCardArtTest {
assertThat(digitalCardArt.description()).isEqualTo("string")
assertThat(digitalCardArt.isEnabled()).isEqualTo(true)
assertThat(digitalCardArt.network()).isEqualTo(DigitalCardArt.Network.MASTERCARD)
assertThat(digitalCardArt.isCardProgramDefault()).contains(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.lithic.api.models

import com.lithic.api.models.*
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand All @@ -11,33 +12,39 @@ class PaymentListParamsTest {
@Test
fun createPaymentListParams() {
PaymentListParams.builder()
.begin(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
.end(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
.endingBefore("string")
.financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.pageSize(123L)
.result(PaymentListParams.Result.APPROVED)
.startingAfter("string")
.status(PaymentListParams.Status.PENDING)
.status(PaymentListParams.Status.DECLINED)
.build()
}

@Test
fun getQueryParams() {
val params =
PaymentListParams.builder()
.begin(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
.end(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
.endingBefore("string")
.financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.pageSize(123L)
.result(PaymentListParams.Result.APPROVED)
.startingAfter("string")
.status(PaymentListParams.Status.PENDING)
.status(PaymentListParams.Status.DECLINED)
.build()
val expected = mutableMapOf<String, List<String>>()
expected.put("begin", listOf("2019-12-27T18:11:19.117Z"))
expected.put("end", listOf("2019-12-27T18:11:19.117Z"))
expected.put("ending_before", listOf("string"))
expected.put("financial_account_token", listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"))
expected.put("page_size", listOf("123"))
expected.put("result", listOf(PaymentListParams.Result.APPROVED.toString()))
expected.put("starting_after", listOf("string"))
expected.put("status", listOf(PaymentListParams.Status.PENDING.toString()))
expected.put("status", listOf(PaymentListParams.Status.DECLINED.toString()))
assertThat(params.getQueryParams()).isEqualTo(expected)
}

Expand Down

0 comments on commit 3d2b816

Please sign in to comment.