Skip to content

Commit

Permalink
feat(client): add various convenience setters to models (#420)
Browse files Browse the repository at this point in the history
feat(client): allow setting arbitrary JSON for top-level body params
feat(client): expose getters for `JsonField` of body params
fix(client): consistently throw on omitting required fields
fix(client): convert `JsonField` containing list type to mutable in builder
style(internal): simplify existing convenience setters on params
style(internal): move headers and query params setters below others
style(internal): explicitly add some method return types
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jan 7, 2025
1 parent 090e5bd commit 47d9bf9
Show file tree
Hide file tree
Showing 164 changed files with 16,476 additions and 6,452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ private constructor(

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}

fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }

fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }

fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }

fun headers(headers: Headers) = apply {
this.headers.clear()
putAllHeaders(headers)
Expand Down Expand Up @@ -152,16 +162,6 @@ private constructor(

fun removeAllQueryParams(keys: Set<String>) = apply { queryParams.removeAll(keys) }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}

fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }

fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }

fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }

fun fromEnv() = apply {
System.getenv("LITHIC_API_KEY")?.let { apiKey(it) }
System.getenv("LITHIC_WEBHOOK_SECRET")?.let { webhookSecret(it) }
Expand Down
145 changes: 87 additions & 58 deletions lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,23 @@ private constructor(
* Globally unique identifier for the account. This is the same as the account_token returned by
* the enroll endpoint. If using this parameter, do not include pagination.
*/
@JsonProperty("token") @ExcludeMissing fun _token() = token
@JsonProperty("token") @ExcludeMissing fun _token(): JsonField<String> = token

/**
* Timestamp of when the account was created. For accounts created before 2023-05-11, this field
* will be null.
*/
@JsonProperty("created") @ExcludeMissing fun _created() = created
@JsonProperty("created") @ExcludeMissing fun _created(): JsonField<OffsetDateTime> = created

/**
* Spend limit information for the user containing the daily, monthly, and lifetime spend limit
* of the account. Any charges to a card owned by this account will be declined once their
* transaction volume has surpassed the value in the applicable time limit (rolling). A lifetime
* limit of 0 indicates that the lifetime limit feature is disabled.
*/
@JsonProperty("spend_limit") @ExcludeMissing fun _spendLimit() = spendLimit
@JsonProperty("spend_limit")
@ExcludeMissing
fun _spendLimit(): JsonField<SpendLimit> = spendLimit

/**
* Account state:
Expand All @@ -123,26 +125,30 @@ private constructor(
* from failing to pass KYB/KYC or Lithic closing for risk/compliance reasons. Please contact
* [[email protected]](mailto:[email protected]) if you believe this was in error.
*/
@JsonProperty("state") @ExcludeMissing fun _state() = state
@JsonProperty("state") @ExcludeMissing fun _state(): JsonField<State> = state

@JsonProperty("account_holder") @ExcludeMissing fun _accountHolder() = accountHolder
@JsonProperty("account_holder")
@ExcludeMissing
fun _accountHolder(): JsonField<AccountHolder> = accountHolder

/**
* List of identifiers for the Auth Rule(s) that are applied on the account. This field is
* deprecated and will no longer be populated in the `account_holder` object. The key will be
* removed from the schema in a future release. Use the `/auth_rules` endpoints to fetch Auth
* Rule information instead.
*/
@JsonProperty("auth_rule_tokens") @ExcludeMissing fun _authRuleTokens() = authRuleTokens
@JsonProperty("auth_rule_tokens")
@ExcludeMissing
fun _authRuleTokens(): JsonField<List<String>> = authRuleTokens

/** 3-digit alphabetic ISO 4217 code for the currency of the cardholder. */
@JsonProperty("cardholder_currency")
@ExcludeMissing
fun _cardholderCurrency() = cardholderCurrency
fun _cardholderCurrency(): JsonField<String> = cardholderCurrency

@JsonProperty("verification_address")
@ExcludeMissing
fun _verificationAddress() = verificationAddress
fun _verificationAddress(): JsonField<VerificationAddress> = verificationAddress

@JsonAnyGetter
@ExcludeMissing
Expand Down Expand Up @@ -173,12 +179,12 @@ private constructor(

class Builder {

private var token: JsonField<String> = JsonMissing.of()
private var created: JsonField<OffsetDateTime> = JsonMissing.of()
private var spendLimit: JsonField<SpendLimit> = JsonMissing.of()
private var state: JsonField<State> = JsonMissing.of()
private var token: JsonField<String>? = null
private var created: JsonField<OffsetDateTime>? = null
private var spendLimit: JsonField<SpendLimit>? = null
private var state: JsonField<State>? = null
private var accountHolder: JsonField<AccountHolder> = JsonMissing.of()
private var authRuleTokens: JsonField<List<String>> = JsonMissing.of()
private var authRuleTokens: JsonField<MutableList<String>>? = null
private var cardholderCurrency: JsonField<String> = JsonMissing.of()
private var verificationAddress: JsonField<VerificationAddress> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
Expand All @@ -189,7 +195,7 @@ private constructor(
spendLimit = account.spendLimit
state = account.state
accountHolder = account.accountHolder
authRuleTokens = account.authRuleTokens
authRuleTokens = account.authRuleTokens.map { it.toMutableList() }
cardholderCurrency = account.cardholderCurrency
verificationAddress = account.verificationAddress
additionalProperties = account.additionalProperties.toMutableMap()
Expand All @@ -211,7 +217,7 @@ private constructor(
* Timestamp of when the account was created. For accounts created before 2023-05-11, this
* field will be null.
*/
fun created(created: OffsetDateTime) = created(JsonField.of(created))
fun created(created: OffsetDateTime?) = created(JsonField.ofNullable(created))

/**
* Timestamp of when the account was created. For accounts created before 2023-05-11, this
Expand Down Expand Up @@ -283,7 +289,24 @@ private constructor(
* Auth Rule information instead.
*/
fun authRuleTokens(authRuleTokens: JsonField<List<String>>) = apply {
this.authRuleTokens = authRuleTokens
this.authRuleTokens = authRuleTokens.map { it.toMutableList() }
}

/**
* List of identifiers for the Auth Rule(s) that are applied on the account. This field is
* deprecated and will no longer be populated in the `account_holder` object. The key will
* be removed from the schema in a future release. Use the `/auth_rules` endpoints to fetch
* Auth Rule information instead.
*/
fun addAuthRuleToken(authRuleToken: String) = apply {
authRuleTokens =
(authRuleTokens ?: JsonField.of(mutableListOf())).apply {
(asKnown()
?: throw IllegalStateException(
"Field was set to non-list type: ${javaClass.simpleName}"
))
.add(authRuleToken)
}
}

/** 3-digit alphabetic ISO 4217 code for the currency of the cardholder. */
Expand Down Expand Up @@ -323,12 +346,12 @@ private constructor(

fun build(): Account =
Account(
token,
created,
spendLimit,
state,
checkNotNull(token) { "`token` is required but was not set" },
checkNotNull(created) { "`created` is required but was not set" },
checkNotNull(spendLimit) { "`spendLimit` is required but was not set" },
checkNotNull(state) { "`state` is required but was not set" },
accountHolder,
authRuleTokens.map { it.toImmutable() },
(authRuleTokens ?: JsonMissing.of()).map { it.toImmutable() },
cardholderCurrency,
verificationAddress,
additionalProperties.toImmutable(),
Expand Down Expand Up @@ -368,13 +391,13 @@ private constructor(
fun monthly(): Long = monthly.getRequired("monthly")

/** Daily spend limit (in cents). */
@JsonProperty("daily") @ExcludeMissing fun _daily() = daily
@JsonProperty("daily") @ExcludeMissing fun _daily(): JsonField<Long> = daily

/** Total spend limit over account lifetime (in cents). */
@JsonProperty("lifetime") @ExcludeMissing fun _lifetime() = lifetime
@JsonProperty("lifetime") @ExcludeMissing fun _lifetime(): JsonField<Long> = lifetime

/** Monthly spend limit (in cents). */
@JsonProperty("monthly") @ExcludeMissing fun _monthly() = monthly
@JsonProperty("monthly") @ExcludeMissing fun _monthly(): JsonField<Long> = monthly

@JsonAnyGetter
@ExcludeMissing
Expand All @@ -400,9 +423,9 @@ private constructor(

class Builder {

private var daily: JsonField<Long> = JsonMissing.of()
private var lifetime: JsonField<Long> = JsonMissing.of()
private var monthly: JsonField<Long> = JsonMissing.of()
private var daily: JsonField<Long>? = null
private var lifetime: JsonField<Long>? = null
private var monthly: JsonField<Long>? = null
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(spendLimit: SpendLimit) = apply {
Expand Down Expand Up @@ -451,9 +474,9 @@ private constructor(

fun build(): SpendLimit =
SpendLimit(
daily,
lifetime,
monthly,
checkNotNull(daily) { "`daily` is required but was not set" },
checkNotNull(lifetime) { "`lifetime` is required but was not set" },
checkNotNull(monthly) { "`monthly` is required but was not set" },
additionalProperties.toImmutable(),
)
}
Expand Down Expand Up @@ -577,7 +600,7 @@ private constructor(
fun phoneNumber(): String = phoneNumber.getRequired("phone_number")

/** Globally unique identifier for the account holder. */
@JsonProperty("token") @ExcludeMissing fun _token() = token
@JsonProperty("token") @ExcludeMissing fun _token(): JsonField<String> = token

/**
* Only applicable for customers using the KYC-Exempt workflow to enroll authorized users of
Expand All @@ -586,13 +609,15 @@ private constructor(
*/
@JsonProperty("business_account_token")
@ExcludeMissing
fun _businessAccountToken() = businessAccountToken
fun _businessAccountToken(): JsonField<String> = businessAccountToken

/** Email address. */
@JsonProperty("email") @ExcludeMissing fun _email() = email
@JsonProperty("email") @ExcludeMissing fun _email(): JsonField<String> = email

/** Phone number of the individual. */
@JsonProperty("phone_number") @ExcludeMissing fun _phoneNumber() = phoneNumber
@JsonProperty("phone_number")
@ExcludeMissing
fun _phoneNumber(): JsonField<String> = phoneNumber

@JsonAnyGetter
@ExcludeMissing
Expand All @@ -619,10 +644,10 @@ private constructor(

class Builder {

private var token: JsonField<String> = JsonMissing.of()
private var businessAccountToken: JsonField<String> = JsonMissing.of()
private var email: JsonField<String> = JsonMissing.of()
private var phoneNumber: JsonField<String> = JsonMissing.of()
private var token: JsonField<String>? = null
private var businessAccountToken: JsonField<String>? = null
private var email: JsonField<String>? = null
private var phoneNumber: JsonField<String>? = null
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(accountHolder: AccountHolder) = apply {
Expand Down Expand Up @@ -691,10 +716,12 @@ private constructor(

fun build(): AccountHolder =
AccountHolder(
token,
businessAccountToken,
email,
phoneNumber,
checkNotNull(token) { "`token` is required but was not set" },
checkNotNull(businessAccountToken) {
"`businessAccountToken` is required but was not set"
},
checkNotNull(email) { "`email` is required but was not set" },
checkNotNull(phoneNumber) { "`phoneNumber` is required but was not set" },
additionalProperties.toImmutable(),
)
}
Expand Down Expand Up @@ -768,28 +795,30 @@ private constructor(
fun address2(): String? = address2.getNullable("address2")

/** Valid deliverable address (no PO boxes). */
@JsonProperty("address1") @ExcludeMissing fun _address1() = address1
@JsonProperty("address1") @ExcludeMissing fun _address1(): JsonField<String> = address1

/** City name. */
@JsonProperty("city") @ExcludeMissing fun _city() = city
@JsonProperty("city") @ExcludeMissing fun _city(): JsonField<String> = city

/** Country name. Only USA is currently supported. */
@JsonProperty("country") @ExcludeMissing fun _country() = country
@JsonProperty("country") @ExcludeMissing fun _country(): JsonField<String> = country

/**
* Valid postal code. Only USA postal codes (ZIP codes) are currently supported, entered as
* a five-digit postal code or nine-digit postal code (ZIP+4) using the format 12345-1234.
*/
@JsonProperty("postal_code") @ExcludeMissing fun _postalCode() = postalCode
@JsonProperty("postal_code")
@ExcludeMissing
fun _postalCode(): JsonField<String> = postalCode

/**
* Valid state code. Only USA state codes are currently supported, entered in uppercase ISO
* 3166-2 two-character format.
*/
@JsonProperty("state") @ExcludeMissing fun _state() = state
@JsonProperty("state") @ExcludeMissing fun _state(): JsonField<String> = state

/** Unit or apartment number (if applicable). */
@JsonProperty("address2") @ExcludeMissing fun _address2() = address2
@JsonProperty("address2") @ExcludeMissing fun _address2(): JsonField<String> = address2

@JsonAnyGetter
@ExcludeMissing
Expand Down Expand Up @@ -818,11 +847,11 @@ private constructor(

class Builder {

private var address1: JsonField<String> = JsonMissing.of()
private var city: JsonField<String> = JsonMissing.of()
private var country: JsonField<String> = JsonMissing.of()
private var postalCode: JsonField<String> = JsonMissing.of()
private var state: JsonField<String> = JsonMissing.of()
private var address1: JsonField<String>? = null
private var city: JsonField<String>? = null
private var country: JsonField<String>? = null
private var postalCode: JsonField<String>? = null
private var state: JsonField<String>? = null
private var address2: JsonField<String> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

Expand Down Expand Up @@ -907,11 +936,11 @@ private constructor(

fun build(): VerificationAddress =
VerificationAddress(
address1,
city,
country,
postalCode,
state,
checkNotNull(address1) { "`address1` is required but was not set" },
checkNotNull(city) { "`city` is required but was not set" },
checkNotNull(country) { "`country` is required but was not set" },
checkNotNull(postalCode) { "`postalCode` is required but was not set" },
checkNotNull(state) { "`state` is required but was not set" },
address2,
additionalProperties.toImmutable(),
)
Expand Down
Loading

0 comments on commit 47d9bf9

Please sign in to comment.