Skip to content

Commit 48444d4

Browse files
feat(api): introduce dedicated model for SpendLimitDuration
1 parent 1c7b405 commit 48444d4

6 files changed

Lines changed: 65 additions & 178 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 165
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-a0d3bcd9c54616729a7e43847e3134205e0695d78f357cc7a25c2775b588dbbd.yml
3-
openapi_spec_hash: 36c423c286ca426f7510b27fadbdd66f
4-
config_hash: 56632a1c934324aa46c1e5c610c2de85
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-cf48017e61eb3ac8aeaaa9d933186532f476b2f3c7e12fa9c962d52e5a9a272b.yml
3+
openapi_spec_hash: b58989fdc04768fc1eb758e180c5f128
4+
config_hash: e4d87bd83b304f6ab3f032db994e0093

lithic-java-core/src/main/kotlin/com/lithic/api/models/Card.kt

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private constructor(
3131
private val lastFour: JsonField<String>,
3232
private val pinStatus: JsonField<NonPciCard.PinStatus>,
3333
private val spendLimit: JsonField<Long>,
34-
private val spendLimitDuration: JsonField<NonPciCard.SpendLimitDuration>,
34+
private val spendLimitDuration: JsonField<SpendLimitDuration>,
3535
private val state: JsonField<NonPciCard.State>,
3636
private val type: JsonField<NonPciCard.Type>,
3737
private val authRuleTokens: JsonField<List<String>>,
@@ -71,7 +71,7 @@ private constructor(
7171
@JsonProperty("spend_limit") @ExcludeMissing spendLimit: JsonField<Long> = JsonMissing.of(),
7272
@JsonProperty("spend_limit_duration")
7373
@ExcludeMissing
74-
spendLimitDuration: JsonField<NonPciCard.SpendLimitDuration> = JsonMissing.of(),
74+
spendLimitDuration: JsonField<SpendLimitDuration> = JsonMissing.of(),
7575
@JsonProperty("state")
7676
@ExcludeMissing
7777
state: JsonField<NonPciCard.State> = JsonMissing.of(),
@@ -216,12 +216,20 @@ private constructor(
216216
fun spendLimit(): Long = spendLimit.getRequired("spend_limit")
217217

218218
/**
219-
* Spend limit duration
219+
* Spend limit duration values:
220+
* - `ANNUALLY` - Card will authorize transactions up to spend limit for the trailing year.
221+
* - `FOREVER` - Card will authorize only up to spend limit for the entire lifetime of the card.
222+
* - `MONTHLY` - Card will authorize transactions up to spend limit for the trailing month. To
223+
* support recurring monthly payments, which can occur on different day every month, the time
224+
* window we consider for monthly velocity starts 6 days after the current calendar date one
225+
* month prior.
226+
* - `TRANSACTION` - Card will authorize multiple transactions if each individual transaction is
227+
* under the spend limit.
220228
*
221229
* @throws LithicInvalidDataException if the JSON field has an unexpected type or is
222230
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
223231
*/
224-
fun spendLimitDuration(): NonPciCard.SpendLimitDuration =
232+
fun spendLimitDuration(): SpendLimitDuration =
225233
spendLimitDuration.getRequired("spend_limit_duration")
226234

227235
/**
@@ -440,7 +448,7 @@ private constructor(
440448
*/
441449
@JsonProperty("spend_limit_duration")
442450
@ExcludeMissing
443-
fun _spendLimitDuration(): JsonField<NonPciCard.SpendLimitDuration> = spendLimitDuration
451+
fun _spendLimitDuration(): JsonField<SpendLimitDuration> = spendLimitDuration
444452

445453
/**
446454
* Returns the raw JSON value of [state].
@@ -599,7 +607,7 @@ private constructor(
599607
private var lastFour: JsonField<String>? = null
600608
private var pinStatus: JsonField<NonPciCard.PinStatus>? = null
601609
private var spendLimit: JsonField<Long>? = null
602-
private var spendLimitDuration: JsonField<NonPciCard.SpendLimitDuration>? = null
610+
private var spendLimitDuration: JsonField<SpendLimitDuration>? = null
603611
private var state: JsonField<NonPciCard.State>? = null
604612
private var type: JsonField<NonPciCard.Type>? = null
605613
private var authRuleTokens: JsonField<MutableList<String>>? = null
@@ -752,21 +760,31 @@ private constructor(
752760
*/
753761
fun spendLimit(spendLimit: JsonField<Long>) = apply { this.spendLimit = spendLimit }
754762

755-
/** Spend limit duration */
756-
fun spendLimitDuration(spendLimitDuration: NonPciCard.SpendLimitDuration) =
763+
/**
764+
* Spend limit duration values:
765+
* - `ANNUALLY` - Card will authorize transactions up to spend limit for the trailing year.
766+
* - `FOREVER` - Card will authorize only up to spend limit for the entire lifetime of the
767+
* card.
768+
* - `MONTHLY` - Card will authorize transactions up to spend limit for the trailing month.
769+
* To support recurring monthly payments, which can occur on different day every month,
770+
* the time window we consider for monthly velocity starts 6 days after the current
771+
* calendar date one month prior.
772+
* - `TRANSACTION` - Card will authorize multiple transactions if each individual
773+
* transaction is under the spend limit.
774+
*/
775+
fun spendLimitDuration(spendLimitDuration: SpendLimitDuration) =
757776
spendLimitDuration(JsonField.of(spendLimitDuration))
758777

759778
/**
760779
* Sets [Builder.spendLimitDuration] to an arbitrary JSON value.
761780
*
762781
* You should usually call [Builder.spendLimitDuration] with a well-typed
763-
* [NonPciCard.SpendLimitDuration] value instead. This method is primarily for setting the
764-
* field to an undocumented or not yet supported value.
782+
* [SpendLimitDuration] value instead. This method is primarily for setting the field to an
783+
* undocumented or not yet supported value.
765784
*/
766-
fun spendLimitDuration(spendLimitDuration: JsonField<NonPciCard.SpendLimitDuration>) =
767-
apply {
768-
this.spendLimitDuration = spendLimitDuration
769-
}
785+
fun spendLimitDuration(spendLimitDuration: JsonField<SpendLimitDuration>) = apply {
786+
this.spendLimitDuration = spendLimitDuration
787+
}
770788

771789
/**
772790
* Card state values: _ `CLOSED` - Card will no longer approve authorizations. Closing a

lithic-java-core/src/main/kotlin/com/lithic/api/models/NonPciCard.kt

Lines changed: 21 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,15 @@ private constructor(
184184
fun spendLimit(): Long = spendLimit.getRequired("spend_limit")
185185

186186
/**
187-
* Spend limit duration
187+
* Spend limit duration values:
188+
* - `ANNUALLY` - Card will authorize transactions up to spend limit for the trailing year.
189+
* - `FOREVER` - Card will authorize only up to spend limit for the entire lifetime of the card.
190+
* - `MONTHLY` - Card will authorize transactions up to spend limit for the trailing month. To
191+
* support recurring monthly payments, which can occur on different day every month, the time
192+
* window we consider for monthly velocity starts 6 days after the current calendar date one
193+
* month prior.
194+
* - `TRANSACTION` - Card will authorize multiple transactions if each individual transaction is
195+
* under the spend limit.
188196
*
189197
* @throws LithicInvalidDataException if the JSON field has an unexpected type or is
190198
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
@@ -677,7 +685,18 @@ private constructor(
677685
*/
678686
fun spendLimit(spendLimit: JsonField<Long>) = apply { this.spendLimit = spendLimit }
679687

680-
/** Spend limit duration */
688+
/**
689+
* Spend limit duration values:
690+
* - `ANNUALLY` - Card will authorize transactions up to spend limit for the trailing year.
691+
* - `FOREVER` - Card will authorize only up to spend limit for the entire lifetime of the
692+
* card.
693+
* - `MONTHLY` - Card will authorize transactions up to spend limit for the trailing month.
694+
* To support recurring monthly payments, which can occur on different day every month,
695+
* the time window we consider for monthly velocity starts 6 days after the current
696+
* calendar date one month prior.
697+
* - `TRANSACTION` - Card will authorize multiple transactions if each individual
698+
* transaction is under the spend limit.
699+
*/
681700
fun spendLimitDuration(spendLimitDuration: SpendLimitDuration) =
682701
spendLimitDuration(JsonField.of(spendLimitDuration))
683702

@@ -1867,155 +1886,6 @@ private constructor(
18671886
override fun toString() = value.toString()
18681887
}
18691888

1870-
/** Spend limit duration */
1871-
class SpendLimitDuration
1872-
@JsonCreator
1873-
private constructor(private val value: JsonField<String>) : Enum {
1874-
1875-
/**
1876-
* Returns this class instance's raw value.
1877-
*
1878-
* This is usually only useful if this instance was deserialized from data that doesn't
1879-
* match any known member, and you want to know that value. For example, if the SDK is on an
1880-
* older version than the API, then the API may respond with new members that the SDK is
1881-
* unaware of.
1882-
*/
1883-
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
1884-
1885-
companion object {
1886-
1887-
@JvmField val ANNUALLY = of("ANNUALLY")
1888-
1889-
@JvmField val FOREVER = of("FOREVER")
1890-
1891-
@JvmField val MONTHLY = of("MONTHLY")
1892-
1893-
@JvmField val TRANSACTION = of("TRANSACTION")
1894-
1895-
@JvmField val DAILY = of("DAILY")
1896-
1897-
@JvmStatic fun of(value: String) = SpendLimitDuration(JsonField.of(value))
1898-
}
1899-
1900-
/** An enum containing [SpendLimitDuration]'s known values. */
1901-
enum class Known {
1902-
ANNUALLY,
1903-
FOREVER,
1904-
MONTHLY,
1905-
TRANSACTION,
1906-
DAILY,
1907-
}
1908-
1909-
/**
1910-
* An enum containing [SpendLimitDuration]'s known values, as well as an [_UNKNOWN] member.
1911-
*
1912-
* An instance of [SpendLimitDuration] can contain an unknown value in a couple of cases:
1913-
* - It was deserialized from data that doesn't match any known member. For example, if the
1914-
* SDK is on an older version than the API, then the API may respond with new members that
1915-
* the SDK is unaware of.
1916-
* - It was constructed with an arbitrary value using the [of] method.
1917-
*/
1918-
enum class Value {
1919-
ANNUALLY,
1920-
FOREVER,
1921-
MONTHLY,
1922-
TRANSACTION,
1923-
DAILY,
1924-
/**
1925-
* An enum member indicating that [SpendLimitDuration] was instantiated with an unknown
1926-
* value.
1927-
*/
1928-
_UNKNOWN,
1929-
}
1930-
1931-
/**
1932-
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
1933-
* if the class was instantiated with an unknown value.
1934-
*
1935-
* Use the [known] method instead if you're certain the value is always known or if you want
1936-
* to throw for the unknown case.
1937-
*/
1938-
fun value(): Value =
1939-
when (this) {
1940-
ANNUALLY -> Value.ANNUALLY
1941-
FOREVER -> Value.FOREVER
1942-
MONTHLY -> Value.MONTHLY
1943-
TRANSACTION -> Value.TRANSACTION
1944-
DAILY -> Value.DAILY
1945-
else -> Value._UNKNOWN
1946-
}
1947-
1948-
/**
1949-
* Returns an enum member corresponding to this class instance's value.
1950-
*
1951-
* Use the [value] method instead if you're uncertain the value is always known and don't
1952-
* want to throw for the unknown case.
1953-
*
1954-
* @throws LithicInvalidDataException if this class instance's value is a not a known
1955-
* member.
1956-
*/
1957-
fun known(): Known =
1958-
when (this) {
1959-
ANNUALLY -> Known.ANNUALLY
1960-
FOREVER -> Known.FOREVER
1961-
MONTHLY -> Known.MONTHLY
1962-
TRANSACTION -> Known.TRANSACTION
1963-
DAILY -> Known.DAILY
1964-
else -> throw LithicInvalidDataException("Unknown SpendLimitDuration: $value")
1965-
}
1966-
1967-
/**
1968-
* Returns this class instance's primitive wire representation.
1969-
*
1970-
* This differs from the [toString] method because that method is primarily for debugging
1971-
* and generally doesn't throw.
1972-
*
1973-
* @throws LithicInvalidDataException if this class instance's value does not have the
1974-
* expected primitive type.
1975-
*/
1976-
fun asString(): String =
1977-
_value().asString().orElseThrow { LithicInvalidDataException("Value is not a String") }
1978-
1979-
private var validated: Boolean = false
1980-
1981-
fun validate(): SpendLimitDuration = apply {
1982-
if (validated) {
1983-
return@apply
1984-
}
1985-
1986-
known()
1987-
validated = true
1988-
}
1989-
1990-
fun isValid(): Boolean =
1991-
try {
1992-
validate()
1993-
true
1994-
} catch (e: LithicInvalidDataException) {
1995-
false
1996-
}
1997-
1998-
/**
1999-
* Returns a score indicating how many valid values are contained in this object
2000-
* recursively.
2001-
*
2002-
* Used for best match union deserialization.
2003-
*/
2004-
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
2005-
2006-
override fun equals(other: Any?): Boolean {
2007-
if (this === other) {
2008-
return true
2009-
}
2010-
2011-
return /* spotless:off */ other is SpendLimitDuration && value == other.value /* spotless:on */
2012-
}
2013-
2014-
override fun hashCode() = value.hashCode()
2015-
2016-
override fun toString() = value.toString()
2017-
}
2018-
20191889
/**
20201890
* Card state values: _ `CLOSED` - Card will no longer approve authorizations. Closing a card
20211891
* cannot be undone. _ `OPEN` - Card will approve authorizations (if they match card and account

lithic-java-core/src/test/kotlin/com/lithic/api/models/CardListPageResponseTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal class CardListPageResponseTest {
3434
.lastFour("xxxx")
3535
.pinStatus(NonPciCard.PinStatus.OK)
3636
.spendLimit(1000L)
37-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
37+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
3838
.state(NonPciCard.State.CLOSED)
3939
.type(NonPciCard.Type.MERCHANT_LOCKED)
4040
.addAuthRuleToken("string")
@@ -73,7 +73,7 @@ internal class CardListPageResponseTest {
7373
.lastFour("xxxx")
7474
.pinStatus(NonPciCard.PinStatus.OK)
7575
.spendLimit(1000L)
76-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
76+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
7777
.state(NonPciCard.State.CLOSED)
7878
.type(NonPciCard.Type.MERCHANT_LOCKED)
7979
.addAuthRuleToken("string")
@@ -116,7 +116,7 @@ internal class CardListPageResponseTest {
116116
.lastFour("xxxx")
117117
.pinStatus(NonPciCard.PinStatus.OK)
118118
.spendLimit(1000L)
119-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
119+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
120120
.state(NonPciCard.State.CLOSED)
121121
.type(NonPciCard.Type.MERCHANT_LOCKED)
122122
.addAuthRuleToken("string")

lithic-java-core/src/test/kotlin/com/lithic/api/models/CardTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class CardTest {
3333
.lastFour("xxxx")
3434
.pinStatus(NonPciCard.PinStatus.OK)
3535
.spendLimit(1000L)
36-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
36+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
3737
.state(NonPciCard.State.CLOSED)
3838
.type(NonPciCard.Type.MERCHANT_LOCKED)
3939
.addAuthRuleToken("string")
@@ -69,7 +69,7 @@ internal class CardTest {
6969
assertThat(card.lastFour()).isEqualTo("xxxx")
7070
assertThat(card.pinStatus()).isEqualTo(NonPciCard.PinStatus.OK)
7171
assertThat(card.spendLimit()).isEqualTo(1000L)
72-
assertThat(card.spendLimitDuration()).isEqualTo(NonPciCard.SpendLimitDuration.ANNUALLY)
72+
assertThat(card.spendLimitDuration()).isEqualTo(SpendLimitDuration.ANNUALLY)
7373
assertThat(card.state()).isEqualTo(NonPciCard.State.CLOSED)
7474
assertThat(card.type()).isEqualTo(NonPciCard.Type.MERCHANT_LOCKED)
7575
assertThat(card.authRuleTokens().getOrNull()).containsExactly("string")
@@ -109,7 +109,7 @@ internal class CardTest {
109109
.lastFour("xxxx")
110110
.pinStatus(NonPciCard.PinStatus.OK)
111111
.spendLimit(1000L)
112-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
112+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
113113
.state(NonPciCard.State.CLOSED)
114114
.type(NonPciCard.Type.MERCHANT_LOCKED)
115115
.addAuthRuleToken("string")

lithic-java-core/src/test/kotlin/com/lithic/api/models/NonPciCardTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class NonPciCardTest {
3333
.lastFour("xxxx")
3434
.pinStatus(NonPciCard.PinStatus.OK)
3535
.spendLimit(1000L)
36-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
36+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
3737
.state(NonPciCard.State.CLOSED)
3838
.type(NonPciCard.Type.MERCHANT_LOCKED)
3939
.addAuthRuleToken("string")
@@ -67,8 +67,7 @@ internal class NonPciCardTest {
6767
assertThat(nonPciCard.lastFour()).isEqualTo("xxxx")
6868
assertThat(nonPciCard.pinStatus()).isEqualTo(NonPciCard.PinStatus.OK)
6969
assertThat(nonPciCard.spendLimit()).isEqualTo(1000L)
70-
assertThat(nonPciCard.spendLimitDuration())
71-
.isEqualTo(NonPciCard.SpendLimitDuration.ANNUALLY)
70+
assertThat(nonPciCard.spendLimitDuration()).isEqualTo(SpendLimitDuration.ANNUALLY)
7271
assertThat(nonPciCard.state()).isEqualTo(NonPciCard.State.CLOSED)
7372
assertThat(nonPciCard.type()).isEqualTo(NonPciCard.Type.MERCHANT_LOCKED)
7473
assertThat(nonPciCard.authRuleTokens().getOrNull()).containsExactly("string")
@@ -107,7 +106,7 @@ internal class NonPciCardTest {
107106
.lastFour("xxxx")
108107
.pinStatus(NonPciCard.PinStatus.OK)
109108
.spendLimit(1000L)
110-
.spendLimitDuration(NonPciCard.SpendLimitDuration.ANNUALLY)
109+
.spendLimitDuration(SpendLimitDuration.ANNUALLY)
111110
.state(NonPciCard.State.CLOSED)
112111
.type(NonPciCard.Type.MERCHANT_LOCKED)
113112
.addAuthRuleToken("string")

0 commit comments

Comments
 (0)