From 1bf0ec1d1fabb366ed595e8f65eed7798dfafd7f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:56:40 +0000 Subject: [PATCH] chore(api): adds `charge_off` functionality to FinancialAccounts (#351) - adds `CHARGED_OFF` to `financial_account_states` property - adds `charged_off_reason` property - adds `charge_off` method --- .stats.yml | 2 +- .../com/lithic/api/models/FinancialAccount.kt | 112 ++++++- .../models/FinancialAccountChargeOffParams.kt | 302 ++++++++++++++++++ .../models/FinancialAccountCreditConfig.kt | 97 +++++- .../async/FinancialAccountServiceAsync.kt | 8 + .../async/FinancialAccountServiceAsyncImpl.kt | 32 ++ .../blocking/FinancialAccountService.kt | 8 + .../blocking/FinancialAccountServiceImpl.kt | 32 ++ .../FinancialAccountChargeOffParamsTest.kt | 58 ++++ .../FinancialAccountCreditConfigTest.kt | 7 +- .../lithic/api/models/FinancialAccountTest.kt | 13 +- .../blocking/FinancialAccountServiceTest.kt | 19 ++ 12 files changed, 676 insertions(+), 14 deletions(-) create mode 100644 lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountChargeOffParams.kt create mode 100644 lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountChargeOffParamsTest.kt diff --git a/.stats.yml b/.stats.yml index 8b01dc8a..5a026d5a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 155 +configured_endpoints: 156 diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccount.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccount.kt index 1ea59307..c6557157 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccount.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccount.kt @@ -253,7 +253,9 @@ private constructor( private val externalBankAccountToken: JsonField, private val creditProductToken: JsonField, private val tier: JsonField, + private val isSpendBlocked: JsonField, private val financialAccountState: JsonField, + private val chargedOffReason: JsonField, private val additionalProperties: Map, ) { @@ -270,10 +272,16 @@ private constructor( /** Tier assigned to the financial account */ fun tier(): String? = tier.getNullable("tier") + fun isSpendBlocked(): Boolean = isSpendBlocked.getRequired("is_spend_blocked") + /** State of the financial account */ fun financialAccountState(): FinancialAccountState? = financialAccountState.getNullable("financial_account_state") + /** Reason for the financial account being marked as Charged Off */ + fun chargedOffReason(): ChargedOffReason? = + chargedOffReason.getNullable("charged_off_reason") + @JsonProperty("credit_limit") @ExcludeMissing fun _creditLimit() = creditLimit @JsonProperty("external_bank_account_token") @@ -288,11 +296,18 @@ private constructor( /** Tier assigned to the financial account */ @JsonProperty("tier") @ExcludeMissing fun _tier() = tier + @JsonProperty("is_spend_blocked") @ExcludeMissing fun _isSpendBlocked() = isSpendBlocked + /** State of the financial account */ @JsonProperty("financial_account_state") @ExcludeMissing fun _financialAccountState() = financialAccountState + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("charged_off_reason") + @ExcludeMissing + fun _chargedOffReason() = chargedOffReason + @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties @@ -303,7 +318,9 @@ private constructor( externalBankAccountToken() creditProductToken() tier() + isSpendBlocked() financialAccountState() + chargedOffReason() validated = true } } @@ -321,7 +338,9 @@ private constructor( private var externalBankAccountToken: JsonField = JsonMissing.of() private var creditProductToken: JsonField = JsonMissing.of() private var tier: JsonField = JsonMissing.of() + private var isSpendBlocked: JsonField = JsonMissing.of() private var financialAccountState: JsonField = JsonMissing.of() + private var chargedOffReason: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(financialAccountCreditConfig: FinancialAccountCreditConfig) = apply { @@ -330,7 +349,9 @@ private constructor( financialAccountCreditConfig.externalBankAccountToken this.creditProductToken = financialAccountCreditConfig.creditProductToken this.tier = financialAccountCreditConfig.tier + this.isSpendBlocked = financialAccountCreditConfig.isSpendBlocked this.financialAccountState = financialAccountCreditConfig.financialAccountState + this.chargedOffReason = financialAccountCreditConfig.chargedOffReason additionalProperties(financialAccountCreditConfig.additionalProperties) } @@ -368,6 +389,15 @@ private constructor( @ExcludeMissing fun tier(tier: JsonField) = apply { this.tier = tier } + fun isSpendBlocked(isSpendBlocked: Boolean) = + isSpendBlocked(JsonField.of(isSpendBlocked)) + + @JsonProperty("is_spend_blocked") + @ExcludeMissing + fun isSpendBlocked(isSpendBlocked: JsonField) = apply { + this.isSpendBlocked = isSpendBlocked + } + /** State of the financial account */ fun financialAccountState(financialAccountState: FinancialAccountState) = financialAccountState(JsonField.of(financialAccountState)) @@ -380,6 +410,17 @@ private constructor( this.financialAccountState = financialAccountState } + /** Reason for the financial account being marked as Charged Off */ + fun chargedOffReason(chargedOffReason: ChargedOffReason) = + chargedOffReason(JsonField.of(chargedOffReason)) + + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("charged_off_reason") + @ExcludeMissing + fun chargedOffReason(chargedOffReason: JsonField) = apply { + this.chargedOffReason = chargedOffReason + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() this.additionalProperties.putAll(additionalProperties) @@ -400,11 +441,70 @@ private constructor( externalBankAccountToken, creditProductToken, tier, + isSpendBlocked, financialAccountState, + chargedOffReason, additionalProperties.toUnmodifiable(), ) } + class ChargedOffReason + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChargedOffReason && this.value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + val DELINQUENT = ChargedOffReason(JsonField.of("DELINQUENT")) + + val FRAUD = ChargedOffReason(JsonField.of("FRAUD")) + + fun of(value: String) = ChargedOffReason(JsonField.of(value)) + } + + enum class Known { + DELINQUENT, + FRAUD, + } + + enum class Value { + DELINQUENT, + FRAUD, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + DELINQUENT -> Value.DELINQUENT + FRAUD -> Value.FRAUD + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + DELINQUENT -> Known.DELINQUENT + FRAUD -> Known.FRAUD + else -> throw LithicInvalidDataException("Unknown ChargedOffReason: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + class FinancialAccountState @JsonCreator private constructor( @@ -433,6 +533,8 @@ private constructor( val DELINQUENT = FinancialAccountState(JsonField.of("DELINQUENT")) + val CHARGED_OFF = FinancialAccountState(JsonField.of("CHARGED_OFF")) + fun of(value: String) = FinancialAccountState(JsonField.of(value)) } @@ -440,12 +542,14 @@ private constructor( PENDING, CURRENT, DELINQUENT, + CHARGED_OFF, } enum class Value { PENDING, CURRENT, DELINQUENT, + CHARGED_OFF, _UNKNOWN, } @@ -454,6 +558,7 @@ private constructor( PENDING -> Value.PENDING CURRENT -> Value.CURRENT DELINQUENT -> Value.DELINQUENT + CHARGED_OFF -> Value.CHARGED_OFF else -> Value._UNKNOWN } @@ -462,6 +567,7 @@ private constructor( PENDING -> Known.PENDING CURRENT -> Known.CURRENT DELINQUENT -> Known.DELINQUENT + CHARGED_OFF -> Known.CHARGED_OFF else -> throw LithicInvalidDataException("Unknown FinancialAccountState: $value") } @@ -474,20 +580,20 @@ private constructor( return true } - return /* spotless:off */ other is FinancialAccountCreditConfig && this.creditLimit == other.creditLimit && this.externalBankAccountToken == other.externalBankAccountToken && this.creditProductToken == other.creditProductToken && this.tier == other.tier && this.financialAccountState == other.financialAccountState && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is FinancialAccountCreditConfig && this.creditLimit == other.creditLimit && this.externalBankAccountToken == other.externalBankAccountToken && this.creditProductToken == other.creditProductToken && this.tier == other.tier && this.isSpendBlocked == other.isSpendBlocked && this.financialAccountState == other.financialAccountState && this.chargedOffReason == other.chargedOffReason && this.additionalProperties == other.additionalProperties /* spotless:on */ } private var hashCode: Int = 0 override fun hashCode(): Int { if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(creditLimit, externalBankAccountToken, creditProductToken, tier, financialAccountState, additionalProperties) /* spotless:on */ + hashCode = /* spotless:off */ Objects.hash(creditLimit, externalBankAccountToken, creditProductToken, tier, isSpendBlocked, financialAccountState, chargedOffReason, additionalProperties) /* spotless:on */ } return hashCode } override fun toString() = - "FinancialAccountCreditConfig{creditLimit=$creditLimit, externalBankAccountToken=$externalBankAccountToken, creditProductToken=$creditProductToken, tier=$tier, financialAccountState=$financialAccountState, additionalProperties=$additionalProperties}" + "FinancialAccountCreditConfig{creditLimit=$creditLimit, externalBankAccountToken=$externalBankAccountToken, creditProductToken=$creditProductToken, tier=$tier, isSpendBlocked=$isSpendBlocked, financialAccountState=$financialAccountState, chargedOffReason=$chargedOffReason, additionalProperties=$additionalProperties}" } class Type diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountChargeOffParams.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountChargeOffParams.kt new file mode 100644 index 00000000..872cd432 --- /dev/null +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountChargeOffParams.kt @@ -0,0 +1,302 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.lithic.api.models + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.lithic.api.core.Enum +import com.lithic.api.core.ExcludeMissing +import com.lithic.api.core.JsonField +import com.lithic.api.core.JsonValue +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.util.Objects + +class FinancialAccountChargeOffParams +constructor( + private val financialAccountToken: String, + private val reason: ChargedOffReason, + private val additionalQueryParams: Map>, + private val additionalHeaders: Map>, + private val additionalBodyProperties: Map, +) { + + fun financialAccountToken(): String = financialAccountToken + + fun reason(): ChargedOffReason = reason + + internal fun getBody(): FinancialAccountChargeOffBody { + return FinancialAccountChargeOffBody(reason, additionalBodyProperties) + } + + internal fun getQueryParams(): Map> = additionalQueryParams + + internal fun getHeaders(): Map> = additionalHeaders + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> financialAccountToken + else -> "" + } + } + + @JsonDeserialize(builder = FinancialAccountChargeOffBody.Builder::class) + @NoAutoDetect + class FinancialAccountChargeOffBody + internal constructor( + private val reason: ChargedOffReason?, + private val additionalProperties: Map, + ) { + + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("reason") fun reason(): ChargedOffReason? = reason + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + fun builder() = Builder() + } + + class Builder { + + private var reason: ChargedOffReason? = null + private var additionalProperties: MutableMap = mutableMapOf() + + internal fun from(financialAccountChargeOffBody: FinancialAccountChargeOffBody) = + apply { + this.reason = financialAccountChargeOffBody.reason + additionalProperties(financialAccountChargeOffBody.additionalProperties) + } + + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("reason") + fun reason(reason: ChargedOffReason) = apply { this.reason = reason } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + this.additionalProperties.putAll(additionalProperties) + } + + @JsonAnySetter + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun build(): FinancialAccountChargeOffBody = + FinancialAccountChargeOffBody( + checkNotNull(reason) { "`reason` is required but was not set" }, + additionalProperties.toUnmodifiable() + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FinancialAccountChargeOffBody && this.reason == other.reason && this.additionalProperties == other.additionalProperties /* spotless:on */ + } + + private var hashCode: Int = 0 + + override fun hashCode(): Int { + if (hashCode == 0) { + hashCode = /* spotless:off */ Objects.hash(reason, additionalProperties) /* spotless:on */ + } + return hashCode + } + + override fun toString() = + "FinancialAccountChargeOffBody{reason=$reason, additionalProperties=$additionalProperties}" + } + + fun _additionalQueryParams(): Map> = additionalQueryParams + + fun _additionalHeaders(): Map> = additionalHeaders + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FinancialAccountChargeOffParams && this.financialAccountToken == other.financialAccountToken && this.reason == other.reason && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int { + return /* spotless:off */ Objects.hash(financialAccountToken, reason, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + } + + override fun toString() = + "FinancialAccountChargeOffParams{financialAccountToken=$financialAccountToken, reason=$reason, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + + fun toBuilder() = Builder().from(this) + + companion object { + + fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var financialAccountToken: String? = null + private var reason: ChargedOffReason? = null + private var additionalQueryParams: MutableMap> = mutableMapOf() + private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + internal fun from(financialAccountChargeOffParams: FinancialAccountChargeOffParams) = + apply { + this.financialAccountToken = financialAccountChargeOffParams.financialAccountToken + this.reason = financialAccountChargeOffParams.reason + additionalQueryParams(financialAccountChargeOffParams.additionalQueryParams) + additionalHeaders(financialAccountChargeOffParams.additionalHeaders) + additionalBodyProperties(financialAccountChargeOffParams.additionalBodyProperties) + } + + fun financialAccountToken(financialAccountToken: String) = apply { + this.financialAccountToken = financialAccountToken + } + + /** Reason for the financial account being marked as Charged Off */ + fun reason(reason: ChargedOffReason) = apply { this.reason = reason } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllQueryParams(additionalQueryParams) + } + + fun putQueryParam(name: String, value: String) = apply { + this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + } + + fun putQueryParams(name: String, values: Iterable) = apply { + this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + } + + fun putAllQueryParams(additionalQueryParams: Map>) = apply { + additionalQueryParams.forEach(this::putQueryParams) + } + + fun removeQueryParam(name: String) = apply { + this.additionalQueryParams.put(name, mutableListOf()) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllHeaders(additionalHeaders) + } + + fun putHeader(name: String, value: String) = apply { + this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + } + + fun putHeaders(name: String, values: Iterable) = apply { + this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + } + + fun putAllHeaders(additionalHeaders: Map>) = apply { + additionalHeaders.forEach(this::putHeaders) + } + + fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + this.additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun build(): FinancialAccountChargeOffParams = + FinancialAccountChargeOffParams( + checkNotNull(financialAccountToken) { + "`financialAccountToken` is required but was not set" + }, + checkNotNull(reason) { "`reason` is required but was not set" }, + additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(), + additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(), + additionalBodyProperties.toUnmodifiable(), + ) + } + + class ChargedOffReason + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChargedOffReason && this.value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + val DELINQUENT = ChargedOffReason(JsonField.of("DELINQUENT")) + + val FRAUD = ChargedOffReason(JsonField.of("FRAUD")) + + fun of(value: String) = ChargedOffReason(JsonField.of(value)) + } + + enum class Known { + DELINQUENT, + FRAUD, + } + + enum class Value { + DELINQUENT, + FRAUD, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + DELINQUENT -> Value.DELINQUENT + FRAUD -> Value.FRAUD + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + DELINQUENT -> Known.DELINQUENT + FRAUD -> Known.FRAUD + else -> throw LithicInvalidDataException("Unknown ChargedOffReason: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } +} diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountCreditConfig.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountCreditConfig.kt index 5acc7827..0baf5551 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountCreditConfig.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/models/FinancialAccountCreditConfig.kt @@ -28,6 +28,7 @@ private constructor( private val tier: JsonField, private val financialAccountState: JsonField, private val isSpendBlocked: JsonField, + private val chargedOffReason: JsonField, private val additionalProperties: Map, ) { @@ -48,10 +49,13 @@ private constructor( fun tier(): String? = tier.getNullable("tier") /** State of the financial account */ - fun financialAccountState(): FinancialAccountState? = - financialAccountState.getNullable("financial_account_state") + fun financialAccountState(): FinancialAccountState = + financialAccountState.getRequired("financial_account_state") - fun isSpendBlocked(): Boolean? = isSpendBlocked.getNullable("is_spend_blocked") + fun isSpendBlocked(): Boolean = isSpendBlocked.getRequired("is_spend_blocked") + + /** Reason for the financial account being marked as Charged Off */ + fun chargedOffReason(): ChargedOffReason? = chargedOffReason.getNullable("charged_off_reason") /** Globally unique identifier for the account */ @JsonProperty("account_token") @ExcludeMissing fun _accountToken() = accountToken @@ -77,6 +81,9 @@ private constructor( @JsonProperty("is_spend_blocked") @ExcludeMissing fun _isSpendBlocked() = isSpendBlocked + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("charged_off_reason") @ExcludeMissing fun _chargedOffReason() = chargedOffReason + @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties @@ -90,6 +97,7 @@ private constructor( tier() financialAccountState() isSpendBlocked() + chargedOffReason() validated = true } } @@ -110,6 +118,7 @@ private constructor( private var tier: JsonField = JsonMissing.of() private var financialAccountState: JsonField = JsonMissing.of() private var isSpendBlocked: JsonField = JsonMissing.of() + private var chargedOffReason: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() internal fun from(financialAccountCreditConfig: FinancialAccountCreditConfig) = apply { @@ -120,6 +129,7 @@ private constructor( this.tier = financialAccountCreditConfig.tier this.financialAccountState = financialAccountCreditConfig.financialAccountState this.isSpendBlocked = financialAccountCreditConfig.isSpendBlocked + this.chargedOffReason = financialAccountCreditConfig.chargedOffReason additionalProperties(financialAccountCreditConfig.additionalProperties) } @@ -186,6 +196,17 @@ private constructor( this.isSpendBlocked = isSpendBlocked } + /** Reason for the financial account being marked as Charged Off */ + fun chargedOffReason(chargedOffReason: ChargedOffReason) = + chargedOffReason(JsonField.of(chargedOffReason)) + + /** Reason for the financial account being marked as Charged Off */ + @JsonProperty("charged_off_reason") + @ExcludeMissing + fun chargedOffReason(chargedOffReason: JsonField) = apply { + this.chargedOffReason = chargedOffReason + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() this.additionalProperties.putAll(additionalProperties) @@ -209,10 +230,68 @@ private constructor( tier, financialAccountState, isSpendBlocked, + chargedOffReason, additionalProperties.toUnmodifiable(), ) } + class ChargedOffReason + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChargedOffReason && this.value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + + companion object { + + val DELINQUENT = ChargedOffReason(JsonField.of("DELINQUENT")) + + val FRAUD = ChargedOffReason(JsonField.of("FRAUD")) + + fun of(value: String) = ChargedOffReason(JsonField.of(value)) + } + + enum class Known { + DELINQUENT, + FRAUD, + } + + enum class Value { + DELINQUENT, + FRAUD, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + DELINQUENT -> Value.DELINQUENT + FRAUD -> Value.FRAUD + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + DELINQUENT -> Known.DELINQUENT + FRAUD -> Known.FRAUD + else -> throw LithicInvalidDataException("Unknown ChargedOffReason: $value") + } + + fun asString(): String = _value().asStringOrThrow() + } + class FinancialAccountState @JsonCreator private constructor( @@ -241,6 +320,8 @@ private constructor( val DELINQUENT = FinancialAccountState(JsonField.of("DELINQUENT")) + val CHARGED_OFF = FinancialAccountState(JsonField.of("CHARGED_OFF")) + fun of(value: String) = FinancialAccountState(JsonField.of(value)) } @@ -248,12 +329,14 @@ private constructor( PENDING, CURRENT, DELINQUENT, + CHARGED_OFF, } enum class Value { PENDING, CURRENT, DELINQUENT, + CHARGED_OFF, _UNKNOWN, } @@ -262,6 +345,7 @@ private constructor( PENDING -> Value.PENDING CURRENT -> Value.CURRENT DELINQUENT -> Value.DELINQUENT + CHARGED_OFF -> Value.CHARGED_OFF else -> Value._UNKNOWN } @@ -270,6 +354,7 @@ private constructor( PENDING -> Known.PENDING CURRENT -> Known.CURRENT DELINQUENT -> Known.DELINQUENT + CHARGED_OFF -> Known.CHARGED_OFF else -> throw LithicInvalidDataException("Unknown FinancialAccountState: $value") } @@ -281,18 +366,18 @@ private constructor( return true } - return /* spotless:off */ other is FinancialAccountCreditConfig && this.accountToken == other.accountToken && this.creditLimit == other.creditLimit && this.externalBankAccountToken == other.externalBankAccountToken && this.creditProductToken == other.creditProductToken && this.tier == other.tier && this.financialAccountState == other.financialAccountState && this.isSpendBlocked == other.isSpendBlocked && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is FinancialAccountCreditConfig && this.accountToken == other.accountToken && this.creditLimit == other.creditLimit && this.externalBankAccountToken == other.externalBankAccountToken && this.creditProductToken == other.creditProductToken && this.tier == other.tier && this.financialAccountState == other.financialAccountState && this.isSpendBlocked == other.isSpendBlocked && this.chargedOffReason == other.chargedOffReason && this.additionalProperties == other.additionalProperties /* spotless:on */ } private var hashCode: Int = 0 override fun hashCode(): Int { if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(accountToken, creditLimit, externalBankAccountToken, creditProductToken, tier, financialAccountState, isSpendBlocked, additionalProperties) /* spotless:on */ + hashCode = /* spotless:off */ Objects.hash(accountToken, creditLimit, externalBankAccountToken, creditProductToken, tier, financialAccountState, isSpendBlocked, chargedOffReason, additionalProperties) /* spotless:on */ } return hashCode } override fun toString() = - "FinancialAccountCreditConfig{accountToken=$accountToken, creditLimit=$creditLimit, externalBankAccountToken=$externalBankAccountToken, creditProductToken=$creditProductToken, tier=$tier, financialAccountState=$financialAccountState, isSpendBlocked=$isSpendBlocked, additionalProperties=$additionalProperties}" + "FinancialAccountCreditConfig{accountToken=$accountToken, creditLimit=$creditLimit, externalBankAccountToken=$externalBankAccountToken, creditProductToken=$creditProductToken, tier=$tier, financialAccountState=$financialAccountState, isSpendBlocked=$isSpendBlocked, chargedOffReason=$chargedOffReason, additionalProperties=$additionalProperties}" } diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsync.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsync.kt index 9d6fcbc8..9cd5122b 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsync.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsync.kt @@ -4,7 +4,9 @@ package com.lithic.api.services.async import com.lithic.api.core.RequestOptions import com.lithic.api.models.FinancialAccount +import com.lithic.api.models.FinancialAccountChargeOffParams import com.lithic.api.models.FinancialAccountCreateParams +import com.lithic.api.models.FinancialAccountCreditConfig import com.lithic.api.models.FinancialAccountListPageAsync import com.lithic.api.models.FinancialAccountListParams import com.lithic.api.models.FinancialAccountRetrieveParams @@ -50,4 +52,10 @@ interface FinancialAccountServiceAsync { params: FinancialAccountListParams, requestOptions: RequestOptions = RequestOptions.none() ): FinancialAccountListPageAsync + + /** Update issuing account state to charged off */ + suspend fun chargeOff( + params: FinancialAccountChargeOffParams, + requestOptions: RequestOptions = RequestOptions.none() + ): FinancialAccountCreditConfig } diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsyncImpl.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsyncImpl.kt index 445b5f6f..c0ce233d 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsyncImpl.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/async/FinancialAccountServiceAsyncImpl.kt @@ -13,7 +13,9 @@ import com.lithic.api.core.http.HttpResponse.Handler import com.lithic.api.core.json import com.lithic.api.errors.LithicError import com.lithic.api.models.FinancialAccount +import com.lithic.api.models.FinancialAccountChargeOffParams import com.lithic.api.models.FinancialAccountCreateParams +import com.lithic.api.models.FinancialAccountCreditConfig import com.lithic.api.models.FinancialAccountListPageAsync import com.lithic.api.models.FinancialAccountListParams import com.lithic.api.models.FinancialAccountRetrieveParams @@ -177,4 +179,34 @@ constructor( .let { FinancialAccountListPageAsync.of(this, params, it) } } } + + private val chargeOffHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + .withErrorHandler(errorHandler) + + /** Update issuing account state to charged off */ + override suspend fun chargeOff( + params: FinancialAccountChargeOffParams, + requestOptions: RequestOptions + ): FinancialAccountCreditConfig { + val request = + HttpRequest.builder() + .method(HttpMethod.PATCH) + .addPathSegments("v1", "financial_accounts", params.getPathParam(0), "charge_off") + .putAllQueryParams(clientOptions.queryParams) + .putAllQueryParams(params.getQueryParams()) + .putAllHeaders(clientOptions.headers) + .putAllHeaders(params.getHeaders()) + .body(json(clientOptions.jsonMapper, params.getBody())) + .build() + return clientOptions.httpClient.executeAsync(request, requestOptions).let { response -> + response + .use { chargeOffHandler.handle(it) } + .apply { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + validate() + } + } + } + } } diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountService.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountService.kt index aa7f15ac..ed407c58 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountService.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountService.kt @@ -4,7 +4,9 @@ package com.lithic.api.services.blocking import com.lithic.api.core.RequestOptions import com.lithic.api.models.FinancialAccount +import com.lithic.api.models.FinancialAccountChargeOffParams import com.lithic.api.models.FinancialAccountCreateParams +import com.lithic.api.models.FinancialAccountCreditConfig import com.lithic.api.models.FinancialAccountListPage import com.lithic.api.models.FinancialAccountListParams import com.lithic.api.models.FinancialAccountRetrieveParams @@ -50,4 +52,10 @@ interface FinancialAccountService { params: FinancialAccountListParams, requestOptions: RequestOptions = RequestOptions.none() ): FinancialAccountListPage + + /** Update issuing account state to charged off */ + fun chargeOff( + params: FinancialAccountChargeOffParams, + requestOptions: RequestOptions = RequestOptions.none() + ): FinancialAccountCreditConfig } diff --git a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceImpl.kt b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceImpl.kt index b5da89fa..b34a0642 100644 --- a/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceImpl.kt +++ b/lithic-kotlin-core/src/main/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceImpl.kt @@ -13,7 +13,9 @@ import com.lithic.api.core.http.HttpResponse.Handler import com.lithic.api.core.json import com.lithic.api.errors.LithicError import com.lithic.api.models.FinancialAccount +import com.lithic.api.models.FinancialAccountChargeOffParams import com.lithic.api.models.FinancialAccountCreateParams +import com.lithic.api.models.FinancialAccountCreditConfig import com.lithic.api.models.FinancialAccountListPage import com.lithic.api.models.FinancialAccountListParams import com.lithic.api.models.FinancialAccountRetrieveParams @@ -175,4 +177,34 @@ constructor( .let { FinancialAccountListPage.of(this, params, it) } } } + + private val chargeOffHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + .withErrorHandler(errorHandler) + + /** Update issuing account state to charged off */ + override fun chargeOff( + params: FinancialAccountChargeOffParams, + requestOptions: RequestOptions + ): FinancialAccountCreditConfig { + val request = + HttpRequest.builder() + .method(HttpMethod.PATCH) + .addPathSegments("v1", "financial_accounts", params.getPathParam(0), "charge_off") + .putAllQueryParams(clientOptions.queryParams) + .putAllQueryParams(params.getQueryParams()) + .putAllHeaders(clientOptions.headers) + .putAllHeaders(params.getHeaders()) + .body(json(clientOptions.jsonMapper, params.getBody())) + .build() + return clientOptions.httpClient.execute(request, requestOptions).let { response -> + response + .use { chargeOffHandler.handle(it) } + .apply { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + validate() + } + } + } + } } diff --git a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountChargeOffParamsTest.kt b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountChargeOffParamsTest.kt new file mode 100644 index 00000000..32f9d2f1 --- /dev/null +++ b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountChargeOffParamsTest.kt @@ -0,0 +1,58 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.lithic.api.models + +import com.lithic.api.models.* +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class FinancialAccountChargeOffParamsTest { + + @Test + fun createFinancialAccountChargeOffParams() { + FinancialAccountChargeOffParams.builder() + .financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .reason(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + .build() + } + + @Test + fun getBody() { + val params = + FinancialAccountChargeOffParams.builder() + .financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .reason(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + .build() + val body = params.getBody() + assertThat(body).isNotNull + assertThat(body.reason()) + .isEqualTo(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + } + + @Test + fun getBodyWithoutOptionalFields() { + val params = + FinancialAccountChargeOffParams.builder() + .financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .reason(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + .build() + val body = params.getBody() + assertThat(body).isNotNull + assertThat(body.reason()) + .isEqualTo(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + } + + @Test + fun getPathParam() { + val params = + FinancialAccountChargeOffParams.builder() + .financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .reason(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + .build() + assertThat(params).isNotNull + // path param "financialAccountToken" + assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + // out-of-bound path param + assertThat(params.getPathParam(1)).isEqualTo("") + } +} diff --git a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountCreditConfigTest.kt b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountCreditConfigTest.kt index c4656f80..54b0a566 100644 --- a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountCreditConfigTest.kt +++ b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountCreditConfigTest.kt @@ -12,24 +12,27 @@ class FinancialAccountCreditConfigTest { val financialAccountCreditConfig = FinancialAccountCreditConfig.builder() .accountToken("b68b7424-aa69-4cbc-a946-30d90181b621") + .chargedOffReason(FinancialAccountCreditConfig.ChargedOffReason.DELINQUENT) .creditLimit(123L) .creditProductToken("credit_product_token") .externalBankAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .tier("tier") .financialAccountState(FinancialAccountCreditConfig.FinancialAccountState.PENDING) .isSpendBlocked(true) + .tier("tier") .build() assertThat(financialAccountCreditConfig).isNotNull assertThat(financialAccountCreditConfig.accountToken()) .isEqualTo("b68b7424-aa69-4cbc-a946-30d90181b621") + assertThat(financialAccountCreditConfig.chargedOffReason()) + .isEqualTo(FinancialAccountCreditConfig.ChargedOffReason.DELINQUENT) assertThat(financialAccountCreditConfig.creditLimit()).isEqualTo(123L) assertThat(financialAccountCreditConfig.creditProductToken()) .isEqualTo("credit_product_token") assertThat(financialAccountCreditConfig.externalBankAccountToken()) .isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(financialAccountCreditConfig.tier()).isEqualTo("tier") assertThat(financialAccountCreditConfig.financialAccountState()) .isEqualTo(FinancialAccountCreditConfig.FinancialAccountState.PENDING) assertThat(financialAccountCreditConfig.isSpendBlocked()).isEqualTo(true) + assertThat(financialAccountCreditConfig.tier()).isEqualTo("tier") } } diff --git a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountTest.kt b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountTest.kt index 35e1c1b5..19781734 100644 --- a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountTest.kt +++ b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/models/FinancialAccountTest.kt @@ -17,14 +17,19 @@ class FinancialAccountTest { .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .creditConfiguration( FinancialAccount.FinancialAccountCreditConfig.builder() + .chargedOffReason( + FinancialAccount.FinancialAccountCreditConfig.ChargedOffReason + .DELINQUENT + ) .creditLimit(123L) .creditProductToken("credit_product_token") .externalBankAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .tier("tier") .financialAccountState( FinancialAccount.FinancialAccountCreditConfig.FinancialAccountState .PENDING ) + .isSpendBlocked(true) + .tier("tier") .build() ) .isForBenefitOf(true) @@ -43,13 +48,17 @@ class FinancialAccountTest { assertThat(financialAccount.creditConfiguration()) .isEqualTo( FinancialAccount.FinancialAccountCreditConfig.builder() + .chargedOffReason( + FinancialAccount.FinancialAccountCreditConfig.ChargedOffReason.DELINQUENT + ) .creditLimit(123L) .creditProductToken("credit_product_token") .externalBankAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .tier("tier") .financialAccountState( FinancialAccount.FinancialAccountCreditConfig.FinancialAccountState.PENDING ) + .isSpendBlocked(true) + .tier("tier") .build() ) assertThat(financialAccount.isForBenefitOf()).isEqualTo(true) diff --git a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceTest.kt b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceTest.kt index 294dad15..a4dc3c6b 100644 --- a/lithic-kotlin-core/src/test/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceTest.kt +++ b/lithic-kotlin-core/src/test/kotlin/com/lithic/api/services/blocking/FinancialAccountServiceTest.kt @@ -83,4 +83,23 @@ class FinancialAccountServiceTest { println(financialAccountsResponse) financialAccountsResponse.data().forEach { it.validate() } } + + @Test + fun callChargeOff() { + val client = + LithicOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My Lithic API Key") + .build() + val financialAccountService = client.financialAccounts() + val financialAccountCreditConfig = + financialAccountService.chargeOff( + FinancialAccountChargeOffParams.builder() + .financialAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .reason(FinancialAccountChargeOffParams.ChargedOffReason.DELINQUENT) + .build() + ) + println(financialAccountCreditConfig) + financialAccountCreditConfig.validate() + } }