From a6c8aabdecb7f8fdd1bb3c979a6d9550c3d420bb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 11 Nov 2025 12:31:32 +0000 Subject: [PATCH 1/3] feat(api): re-add rules metadata to tokenization events fix(api): adjust Auth Rules spec for better SDK structure feat(api): remove deprecated fields from Cardholder Authentication object --- .stats.yml | 6 +- .../api/models/AuthRuleV2CreateParams.kt | 6714 +++-------------- .../api/models/AuthRuleV2DraftParams.kt | 1433 +--- ...onditionalAuthorizationActionParameters.kt | 1392 ++++ .../com/lithic/api/models/Tokenization.kt | 1088 ++- .../com/lithic/api/models/Transaction.kt | 835 +- .../com/lithic/api/models/V2CreateResponse.kt | 2912 +------ .../com/lithic/api/models/V2DraftResponse.kt | 2912 +------ .../com/lithic/api/models/V2ListResponse.kt | 2912 +------ .../lithic/api/models/V2PromoteResponse.kt | 2912 +------ .../api/models/V2RetrieveFeaturesResponse.kt | 52 +- .../lithic/api/models/V2RetrieveResponse.kt | 2912 +------ .../com/lithic/api/models/V2UpdateResponse.kt | 2912 +------ .../lithic/api/models/VelocityLimitParams.kt | 57 +- ...PeriodWindow.kt => VelocityLimitPeriod.kt} | 71 +- .../models/AccountActivityListResponseTest.kt | 30 +- ...ActivityRetrieveTransactionResponseTest.kt | 30 +- .../api/models/AuthRuleV2CreateParamsTest.kt | 70 +- ...tionalAuthorizationActionParametersTest.kt | 68 + .../TokenizationListPageResponseTest.kt | 59 + .../TokenizationSimulateResponseTest.kt | 59 + .../com/lithic/api/models/TokenizationTest.kt | 53 + ...izationUpdateDigitalCardArtResponseTest.kt | 59 + .../models/TransactionListPageResponseTest.kt | 50 +- .../com/lithic/api/models/TransactionTest.kt | 42 +- .../models/V2RetrieveFeaturesResponseTest.kt | 16 +- .../VelocityLimitParamsPeriodWindowTest.kt | 232 - .../api/models/VelocityLimitParamsTest.kt | 14 +- .../api/models/VelocityLimitPeriodTest.kt | 219 + .../async/authRules/V2ServiceAsyncTest.kt | 20 +- .../blocking/authRules/V2ServiceTest.kt | 20 +- 31 files changed, 4339 insertions(+), 25822 deletions(-) create mode 100644 lithic-java-core/src/main/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParameters.kt rename lithic-java-core/src/main/kotlin/com/lithic/api/models/{VelocityLimitParamsPeriodWindow.kt => VelocityLimitPeriod.kt} (96%) create mode 100644 lithic-java-core/src/test/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParametersTest.kt delete mode 100644 lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindowTest.kt create mode 100644 lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitPeriodTest.kt diff --git a/.stats.yml b/.stats.yml index 61c0e26a..a080bc22 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 168 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-2cfd81dfd3ad2c5a4e98161e54dbac5ddee125c058f9163f29aad4632cadf08d.yml -openapi_spec_hash: 400a2563ad969fba47b3eb0f02372b1e -config_hash: f5a16e702bac54729afed6e50b0de3ff +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-c3f6c23018d70fd1b259b21cfd377b5d905872f0d3c5ce2cdb8013f4b6daa338.yml +openapi_spec_hash: b551344da9d29eb4c5374874ed84a9b0 +config_hash: 012f050e575d1bbfe8db56a9eeaa5fcd diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2CreateParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2CreateParams.kt index c4fa7dea..727366e2 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2CreateParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2CreateParams.kt @@ -81,26 +81,16 @@ private constructor( fun body(body: Body) = apply { this.body = body } - /** - * Alias for calling [body] with - * `Body.ofCreateAuthRuleRequestAccountTokens(createAuthRuleRequestAccountTokens)`. - */ - fun body(createAuthRuleRequestAccountTokens: Body.CreateAuthRuleRequestAccountTokens) = - body(Body.ofCreateAuthRuleRequestAccountTokens(createAuthRuleRequestAccountTokens)) + /** Alias for calling [body] with `Body.ofAccountLevelRule(accountLevelRule)`. */ + fun body(accountLevelRule: Body.AccountLevelRule) = + body(Body.ofAccountLevelRule(accountLevelRule)) - /** - * Alias for calling [body] with - * `Body.ofCreateAuthRuleRequestCardTokens(createAuthRuleRequestCardTokens)`. - */ - fun body(createAuthRuleRequestCardTokens: Body.CreateAuthRuleRequestCardTokens) = - body(Body.ofCreateAuthRuleRequestCardTokens(createAuthRuleRequestCardTokens)) + /** Alias for calling [body] with `Body.ofCardLevelRule(cardLevelRule)`. */ + fun body(cardLevelRule: Body.CardLevelRule) = body(Body.ofCardLevelRule(cardLevelRule)) - /** - * Alias for calling [body] with - * `Body.ofCreateAuthRuleRequestProgramLevel(createAuthRuleRequestProgramLevel)`. - */ - fun body(createAuthRuleRequestProgramLevel: Body.CreateAuthRuleRequestProgramLevel) = - body(Body.ofCreateAuthRuleRequestProgramLevel(createAuthRuleRequestProgramLevel)) + /** Alias for calling [body] with `Body.ofProgramLevelRule(programLevelRule)`. */ + fun body(programLevelRule: Body.ProgramLevelRule) = + body(Body.ofProgramLevelRule(programLevelRule)) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -230,52 +220,37 @@ private constructor( @JsonSerialize(using = Body.Serializer::class) class Body private constructor( - private val createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens? = null, - private val createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens? = null, - private val createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel? = null, + private val accountLevelRule: AccountLevelRule? = null, + private val cardLevelRule: CardLevelRule? = null, + private val programLevelRule: ProgramLevelRule? = null, private val _json: JsonValue? = null, ) { - fun createAuthRuleRequestAccountTokens(): Optional = - Optional.ofNullable(createAuthRuleRequestAccountTokens) + fun accountLevelRule(): Optional = Optional.ofNullable(accountLevelRule) - fun createAuthRuleRequestCardTokens(): Optional = - Optional.ofNullable(createAuthRuleRequestCardTokens) + fun cardLevelRule(): Optional = Optional.ofNullable(cardLevelRule) - fun createAuthRuleRequestProgramLevel(): Optional = - Optional.ofNullable(createAuthRuleRequestProgramLevel) + fun programLevelRule(): Optional = Optional.ofNullable(programLevelRule) - fun isCreateAuthRuleRequestAccountTokens(): Boolean = - createAuthRuleRequestAccountTokens != null + fun isAccountLevelRule(): Boolean = accountLevelRule != null - fun isCreateAuthRuleRequestCardTokens(): Boolean = createAuthRuleRequestCardTokens != null + fun isCardLevelRule(): Boolean = cardLevelRule != null - fun isCreateAuthRuleRequestProgramLevel(): Boolean = - createAuthRuleRequestProgramLevel != null + fun isProgramLevelRule(): Boolean = programLevelRule != null - fun asCreateAuthRuleRequestAccountTokens(): CreateAuthRuleRequestAccountTokens = - createAuthRuleRequestAccountTokens.getOrThrow("createAuthRuleRequestAccountTokens") + fun asAccountLevelRule(): AccountLevelRule = accountLevelRule.getOrThrow("accountLevelRule") - fun asCreateAuthRuleRequestCardTokens(): CreateAuthRuleRequestCardTokens = - createAuthRuleRequestCardTokens.getOrThrow("createAuthRuleRequestCardTokens") + fun asCardLevelRule(): CardLevelRule = cardLevelRule.getOrThrow("cardLevelRule") - fun asCreateAuthRuleRequestProgramLevel(): CreateAuthRuleRequestProgramLevel = - createAuthRuleRequestProgramLevel.getOrThrow("createAuthRuleRequestProgramLevel") + fun asProgramLevelRule(): ProgramLevelRule = programLevelRule.getOrThrow("programLevelRule") fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = when { - createAuthRuleRequestAccountTokens != null -> - visitor.visitCreateAuthRuleRequestAccountTokens( - createAuthRuleRequestAccountTokens - ) - createAuthRuleRequestCardTokens != null -> - visitor.visitCreateAuthRuleRequestCardTokens(createAuthRuleRequestCardTokens) - createAuthRuleRequestProgramLevel != null -> - visitor.visitCreateAuthRuleRequestProgramLevel( - createAuthRuleRequestProgramLevel - ) + accountLevelRule != null -> visitor.visitAccountLevelRule(accountLevelRule) + cardLevelRule != null -> visitor.visitCardLevelRule(cardLevelRule) + programLevelRule != null -> visitor.visitProgramLevelRule(programLevelRule) else -> visitor.unknown(_json) } @@ -288,22 +263,16 @@ private constructor( accept( object : Visitor { - override fun visitCreateAuthRuleRequestAccountTokens( - createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens - ) { - createAuthRuleRequestAccountTokens.validate() + override fun visitAccountLevelRule(accountLevelRule: AccountLevelRule) { + accountLevelRule.validate() } - override fun visitCreateAuthRuleRequestCardTokens( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ) { - createAuthRuleRequestCardTokens.validate() + override fun visitCardLevelRule(cardLevelRule: CardLevelRule) { + cardLevelRule.validate() } - override fun visitCreateAuthRuleRequestProgramLevel( - createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel - ) { - createAuthRuleRequestProgramLevel.validate() + override fun visitProgramLevelRule(programLevelRule: ProgramLevelRule) { + programLevelRule.validate() } } ) @@ -328,17 +297,14 @@ private constructor( internal fun validity(): Int = accept( object : Visitor { - override fun visitCreateAuthRuleRequestAccountTokens( - createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens - ) = createAuthRuleRequestAccountTokens.validity() + override fun visitAccountLevelRule(accountLevelRule: AccountLevelRule) = + accountLevelRule.validity() - override fun visitCreateAuthRuleRequestCardTokens( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ) = createAuthRuleRequestCardTokens.validity() + override fun visitCardLevelRule(cardLevelRule: CardLevelRule) = + cardLevelRule.validity() - override fun visitCreateAuthRuleRequestProgramLevel( - createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel - ) = createAuthRuleRequestProgramLevel.validity() + override fun visitProgramLevelRule(programLevelRule: ProgramLevelRule) = + programLevelRule.validity() override fun unknown(json: JsonValue?) = 0 } @@ -350,26 +316,19 @@ private constructor( } return other is Body && - createAuthRuleRequestAccountTokens == other.createAuthRuleRequestAccountTokens && - createAuthRuleRequestCardTokens == other.createAuthRuleRequestCardTokens && - createAuthRuleRequestProgramLevel == other.createAuthRuleRequestProgramLevel + accountLevelRule == other.accountLevelRule && + cardLevelRule == other.cardLevelRule && + programLevelRule == other.programLevelRule } override fun hashCode(): Int = - Objects.hash( - createAuthRuleRequestAccountTokens, - createAuthRuleRequestCardTokens, - createAuthRuleRequestProgramLevel, - ) + Objects.hash(accountLevelRule, cardLevelRule, programLevelRule) override fun toString(): String = when { - createAuthRuleRequestAccountTokens != null -> - "Body{createAuthRuleRequestAccountTokens=$createAuthRuleRequestAccountTokens}" - createAuthRuleRequestCardTokens != null -> - "Body{createAuthRuleRequestCardTokens=$createAuthRuleRequestCardTokens}" - createAuthRuleRequestProgramLevel != null -> - "Body{createAuthRuleRequestProgramLevel=$createAuthRuleRequestProgramLevel}" + accountLevelRule != null -> "Body{accountLevelRule=$accountLevelRule}" + cardLevelRule != null -> "Body{cardLevelRule=$cardLevelRule}" + programLevelRule != null -> "Body{programLevelRule=$programLevelRule}" _json != null -> "Body{_unknown=$_json}" else -> throw IllegalStateException("Invalid Body") } @@ -377,35 +336,25 @@ private constructor( companion object { @JvmStatic - fun ofCreateAuthRuleRequestAccountTokens( - createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens - ) = Body(createAuthRuleRequestAccountTokens = createAuthRuleRequestAccountTokens) + fun ofAccountLevelRule(accountLevelRule: AccountLevelRule) = + Body(accountLevelRule = accountLevelRule) @JvmStatic - fun ofCreateAuthRuleRequestCardTokens( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ) = Body(createAuthRuleRequestCardTokens = createAuthRuleRequestCardTokens) + fun ofCardLevelRule(cardLevelRule: CardLevelRule) = Body(cardLevelRule = cardLevelRule) @JvmStatic - fun ofCreateAuthRuleRequestProgramLevel( - createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel - ) = Body(createAuthRuleRequestProgramLevel = createAuthRuleRequestProgramLevel) + fun ofProgramLevelRule(programLevelRule: ProgramLevelRule) = + Body(programLevelRule = programLevelRule) } /** An interface that defines how to map each variant of [Body] to a value of type [T]. */ interface Visitor { - fun visitCreateAuthRuleRequestAccountTokens( - createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens - ): T + fun visitAccountLevelRule(accountLevelRule: AccountLevelRule): T - fun visitCreateAuthRuleRequestCardTokens( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ): T + fun visitCardLevelRule(cardLevelRule: CardLevelRule): T - fun visitCreateAuthRuleRequestProgramLevel( - createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel - ): T + fun visitProgramLevelRule(programLevelRule: ProgramLevelRule): T /** * Maps an unknown variant of [Body] to a value of type [T]. @@ -428,20 +377,15 @@ private constructor( val bestMatches = sequenceOf( - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Body(createAuthRuleRequestAccountTokens = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef()) - ?.let { Body(createAuthRuleRequestCardTokens = it, _json = json) }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Body(createAuthRuleRequestProgramLevel = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + Body(accountLevelRule = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Body(cardLevelRule = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Body(programLevelRule = it, _json = json) + }, ) .filterNotNull() .allMaxBy { it.validity() } @@ -467,32 +411,35 @@ private constructor( provider: SerializerProvider, ) { when { - value.createAuthRuleRequestAccountTokens != null -> - generator.writeObject(value.createAuthRuleRequestAccountTokens) - value.createAuthRuleRequestCardTokens != null -> - generator.writeObject(value.createAuthRuleRequestCardTokens) - value.createAuthRuleRequestProgramLevel != null -> - generator.writeObject(value.createAuthRuleRequestProgramLevel) + value.accountLevelRule != null -> generator.writeObject(value.accountLevelRule) + value.cardLevelRule != null -> generator.writeObject(value.cardLevelRule) + value.programLevelRule != null -> generator.writeObject(value.programLevelRule) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Body") } } } - class CreateAuthRuleRequestAccountTokens + class AccountLevelRule @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val parameters: JsonField, + private val type: JsonField, private val accountTokens: JsonField>, private val businessAccountTokens: JsonField>, private val eventStream: JsonField, private val name: JsonField, - private val parameters: JsonField, - private val type: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), @JsonProperty("account_tokens") @ExcludeMissing accountTokens: JsonField> = JsonMissing.of(), @@ -503,22 +450,40 @@ private constructor( @ExcludeMissing eventStream: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), ) : this( + parameters, + type, accountTokens, businessAccountTokens, eventStream, name, - parameters, - type, mutableMapOf(), ) + /** + * Parameters for the Auth Rule + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun parameters(): Parameters = parameters.getRequired("parameters") + + /** + * The type of Auth Rule. For certain rule types, this determines the event stream + * during which it will be evaluated. For rules that can be applied to one of several + * event streams, the effective one is defined by the separate `event_stream` field. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): AuthRuleType = type.getRequired("type") + /** * Account tokens to which the Auth Rule applies. * @@ -554,26 +519,21 @@ private constructor( fun name(): Optional = name.getOptional("name") /** - * Parameters for the Auth Rule + * Returns the raw JSON value of [parameters]. * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun parameters(): Optional = parameters.getOptional("parameters") + @JsonProperty("parameters") + @ExcludeMissing + fun _parameters(): JsonField = parameters /** - * The type of Auth Rule. For certain rule types, this determines the event stream - * during which it will be evaluated. For rules that can be applied to one of several - * event streams, the effective one is defined by the separate `event_stream` field. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * Returns the raw JSON value of [type]. * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - fun type(): Optional = type.getOptional("type") + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [accountTokens]. @@ -612,23 +572,6 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** - * Returns the raw JSON value of [parameters]. - * - * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("parameters") - @ExcludeMissing - fun _parameters(): JsonField = parameters - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -644,41 +587,113 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [CreateAuthRuleRequestAccountTokens]. + * Returns a mutable builder for constructing an instance of [AccountLevelRule]. + * + * The following fields are required: + * ```java + * .parameters() + * .type() + * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [CreateAuthRuleRequestAccountTokens]. */ + /** A builder for [AccountLevelRule]. */ class Builder internal constructor() { + private var parameters: JsonField? = null + private var type: JsonField? = null private var accountTokens: JsonField>? = null private var businessAccountTokens: JsonField>? = null private var eventStream: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() - private var parameters: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from( - createAuthRuleRequestAccountTokens: CreateAuthRuleRequestAccountTokens - ) = apply { - accountTokens = - createAuthRuleRequestAccountTokens.accountTokens.map { it.toMutableList() } + internal fun from(accountLevelRule: AccountLevelRule) = apply { + parameters = accountLevelRule.parameters + type = accountLevelRule.type + accountTokens = accountLevelRule.accountTokens.map { it.toMutableList() } businessAccountTokens = - createAuthRuleRequestAccountTokens.businessAccountTokens.map { - it.toMutableList() - } - eventStream = createAuthRuleRequestAccountTokens.eventStream - name = createAuthRuleRequestAccountTokens.name - parameters = createAuthRuleRequestAccountTokens.parameters - type = createAuthRuleRequestAccountTokens.type - additionalProperties = - createAuthRuleRequestAccountTokens.additionalProperties.toMutableMap() + accountLevelRule.businessAccountTokens.map { it.toMutableList() } + eventStream = accountLevelRule.eventStream + name = accountLevelRule.name + additionalProperties = accountLevelRule.additionalProperties.toMutableMap() + } + + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) + + /** + * Sets [Builder.parameters] to an arbitrary JSON value. + * + * You should usually call [Builder.parameters] with a well-typed [Parameters] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun parameters(parameters: JsonField) = apply { + this.parameters = parameters } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) + + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) + + /** + * Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. + */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) + + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) + + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. + */ + fun parameters( + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters + ) = + parameters( + Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) + ) + + /** + * The type of Auth Rule. For certain rule types, this determines the event stream + * during which it will be evaluated. For rules that can be applied to one of + * several event streams, the effective one is defined by the separate + * `event_stream` field. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + */ + fun type(type: AuthRuleType) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [AuthRuleType] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + /** Account tokens to which the Auth Rule applies. */ fun accountTokens(accountTokens: List) = accountTokens(JsonField.of(accountTokens)) @@ -762,80 +777,6 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } - /** Parameters for the Auth Rule */ - fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - - /** - * Sets [Builder.parameters] to an arbitrary JSON value. - * - * You should usually call [Builder.parameters] with a well-typed [Parameters] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun parameters(parameters: JsonField) = apply { - this.parameters = parameters - } - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditionalBlock(conditionalBlock)`. - */ - fun parameters(conditionalBlock: ConditionalBlockParameters) = - parameters(Parameters.ofConditionalBlock(conditionalBlock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. - */ - fun parameters(velocityLimitParams: VelocityLimitParams) = - parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - - /** - * Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. - */ - fun parameters(merchantLock: MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. - */ - fun parameters( - conditionalAuthorizationAction: - Parameters.ConditionalAuthorizationActionParameters - ) = - parameters( - Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) - ) - - /** - * The type of Auth Rule. For certain rule types, this determines the event stream - * during which it will be evaluated. For rules that can be applied to one of - * several event streams, the effective one is defined by the separate - * `event_stream` field. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. - */ - fun type(type: AuthRuleType) = type(JsonField.of(type)) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [AuthRuleType] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun type(type: JsonField) = apply { this.type = type } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -859,35 +800,43 @@ private constructor( } /** - * Returns an immutable instance of [CreateAuthRuleRequestAccountTokens]. + * Returns an immutable instance of [AccountLevelRule]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): CreateAuthRuleRequestAccountTokens = - CreateAuthRuleRequestAccountTokens( + fun build(): AccountLevelRule = + AccountLevelRule( + checkRequired("parameters", parameters), + checkRequired("type", type), (accountTokens ?: JsonMissing.of()).map { it.toImmutable() }, (businessAccountTokens ?: JsonMissing.of()).map { it.toImmutable() }, eventStream, name, - parameters, - type, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): CreateAuthRuleRequestAccountTokens = apply { + fun validate(): AccountLevelRule = apply { if (validated) { return@apply } + parameters().validate() + type().validate() accountTokens() businessAccountTokens() eventStream().ifPresent { it.validate() } name() - parameters().ifPresent { it.validate() } - type().ifPresent { it.validate() } validated = true } @@ -907,145 +856,12 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (accountTokens.asKnown().getOrNull()?.size ?: 0) + + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (accountTokens.asKnown().getOrNull()?.size ?: 0) + (businessAccountTokens.asKnown().getOrNull()?.size ?: 0) + (eventStream.asKnown().getOrNull()?.validity() ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - /** The event stream during which the rule will be evaluated. */ - class EventStream - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val AUTHORIZATION = of("AUTHORIZATION") - - @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") - - @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) - } - - /** An enum containing [EventStream]'s known values. */ - enum class Known { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - } - - /** - * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [EventStream] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - /** - * An enum member indicating that [EventStream] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - AUTHORIZATION -> Value.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - AUTHORIZATION -> Known.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION - else -> throw LithicInvalidDataException("Unknown EventStream: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): EventStream = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is EventStream && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } + (if (name.asKnown().isPresent) 1 else 0) /** Parameters for the Auth Rule */ @JsonDeserialize(using = Parameters.Deserializer::class) @@ -1378,1512 +1194,164 @@ private constructor( } } } + } - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun action(): Action = action.getRequired("action") + /** + * The type of Auth Rule. For certain rule types, this determines the event stream + * during which it will be evaluated. For rules that can be applied to one of several + * event streams, the effective one is defined by the separate `event_stream` field. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + */ + class AuthRuleType + @JsonCreator + private constructor(private val value: JsonField) : Enum { - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun conditions(): List = conditions.getRequired("conditions") + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("action") - @ExcludeMissing - fun _action(): JsonField = action + companion object { - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions + @JvmField val CONDITIONAL_BLOCK = of("CONDITIONAL_BLOCK") - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + @JvmField val VELOCITY_LIMIT = of("VELOCITY_LIMIT") - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + @JvmField val MERCHANT_LOCK = of("MERCHANT_LOCK") - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } + @JvmField val CONDITIONAL_ACTION = of("CONDITIONAL_ACTION") - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } + @JvmStatic fun of(value: String) = AuthRuleType(JsonField.of(value)) + } - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } + /** An enum containing [AuthRuleType]'s known values. */ + enum class Known { + CONDITIONAL_BLOCK, + VELOCITY_LIMIT, + MERCHANT_LOCK, + CONDITIONAL_ACTION, + } - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * An enum containing [AuthRuleType]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [AuthRuleType] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + CONDITIONAL_BLOCK, + VELOCITY_LIMIT, + MERCHANT_LOCK, + CONDITIONAL_ACTION, + /** + * An enum member indicating that [AuthRuleType] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + CONDITIONAL_BLOCK -> Value.CONDITIONAL_BLOCK + VELOCITY_LIMIT -> Value.VELOCITY_LIMIT + MERCHANT_LOCK -> Value.MERCHANT_LOCK + CONDITIONAL_ACTION -> Value.CONDITIONAL_ACTION + else -> Value._UNKNOWN + } - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + CONDITIONAL_BLOCK -> Known.CONDITIONAL_BLOCK + VELOCITY_LIMIT -> Known.VELOCITY_LIMIT + MERCHANT_LOCK -> Known.MERCHANT_LOCK + CONDITIONAL_ACTION -> Known.CONDITIONAL_ACTION + else -> throw LithicInvalidDataException("Unknown AuthRuleType: $value") + } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + private var validated: Boolean = false - /** - * Returns an immutable instance of - * [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) + fun validate(): AuthRuleType = apply { + if (validated) { + return@apply } - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Action] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("value") - @ExcludeMissing - fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: - * (1) all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and - * (3) ANT for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to - * the issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary - * account number (PAN) was entered. Valid values are `AUTO_ENTRY`, - * `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, - * `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, - * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, - * `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus - * the acquirer fee field in the settlement/cardholder billing - * currency. This is the amount the issuer should authorize against - * unless the issuer is paying the acquirer fee on behalf of the - * cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authorization. Scores are on a range of - * 0-999, with 0 representing the lowest risk and 999 representing the - * highest risk. For Visa transactions, where the raw score has a - * range of 0-99, Lithic will normalize the score by multiplying the - * raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the - * card in the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card - * in the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the - * card in the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, - * indicates the source of the token. Valid values are `APPLE_PAY`, - * `GOOGLE_PAY`, `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, - * `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid - * values are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed - * [Attribute] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed - * [Operation] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with - * `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Attribute] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException( - "Unknown Attribute: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField - val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Operation] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException( - "Unknown Operation: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> - visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings( - listOfStrings: List - ) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings( - listOfStrings: List - ) = listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = - Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a - * value of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the - * API may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { Value(regex = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { - Value(listOfStrings = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode + known() + validated = true + } - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } + return other is AuthRuleType && value == other.value + } - override fun hashCode(): Int = hashCode + override fun hashCode() = value.hashCode() - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } + override fun toString() = value.toString() } - /** - * The type of Auth Rule. For certain rule types, this determines the event stream - * during which it will be evaluated. For rules that can be applied to one of several - * event streams, the effective one is defined by the separate `event_stream` field. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. - */ - class AuthRuleType + /** The event stream during which the rule will be evaluated. */ + class EventStream @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -2899,43 +1367,34 @@ private constructor( companion object { - @JvmField val CONDITIONAL_BLOCK = of("CONDITIONAL_BLOCK") - - @JvmField val VELOCITY_LIMIT = of("VELOCITY_LIMIT") - - @JvmField val MERCHANT_LOCK = of("MERCHANT_LOCK") + @JvmField val AUTHORIZATION = of("AUTHORIZATION") - @JvmField val CONDITIONAL_ACTION = of("CONDITIONAL_ACTION") + @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") - @JvmStatic fun of(value: String) = AuthRuleType(JsonField.of(value)) + @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) } - /** An enum containing [AuthRuleType]'s known values. */ + /** An enum containing [EventStream]'s known values. */ enum class Known { - CONDITIONAL_BLOCK, - VELOCITY_LIMIT, - MERCHANT_LOCK, - CONDITIONAL_ACTION, + AUTHORIZATION, + THREE_DS_AUTHENTICATION, } /** - * An enum containing [AuthRuleType]'s known values, as well as an [_UNKNOWN] - * member. + * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [AuthRuleType] can contain an unknown value in a couple of cases: + * An instance of [EventStream] can contain an unknown value in a couple of cases: * - It was deserialized from data that doesn't match any known member. For example, * if the SDK is on an older version than the API, then the API may respond with * new members that the SDK is unaware of. * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - CONDITIONAL_BLOCK, - VELOCITY_LIMIT, - MERCHANT_LOCK, - CONDITIONAL_ACTION, + AUTHORIZATION, + THREE_DS_AUTHENTICATION, /** - * An enum member indicating that [AuthRuleType] was instantiated with an - * unknown value. + * An enum member indicating that [EventStream] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -2949,10 +1408,8 @@ private constructor( */ fun value(): Value = when (this) { - CONDITIONAL_BLOCK -> Value.CONDITIONAL_BLOCK - VELOCITY_LIMIT -> Value.VELOCITY_LIMIT - MERCHANT_LOCK -> Value.MERCHANT_LOCK - CONDITIONAL_ACTION -> Value.CONDITIONAL_ACTION + AUTHORIZATION -> Value.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION else -> Value._UNKNOWN } @@ -2967,11 +1424,9 @@ private constructor( */ fun known(): Known = when (this) { - CONDITIONAL_BLOCK -> Known.CONDITIONAL_BLOCK - VELOCITY_LIMIT -> Known.VELOCITY_LIMIT - MERCHANT_LOCK -> Known.MERCHANT_LOCK - CONDITIONAL_ACTION -> Known.CONDITIONAL_ACTION - else -> throw LithicInvalidDataException("Unknown AuthRuleType: $value") + AUTHORIZATION -> Known.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION + else -> throw LithicInvalidDataException("Unknown EventStream: $value") } /** @@ -2990,7 +1445,7 @@ private constructor( private var validated: Boolean = false - fun validate(): AuthRuleType = apply { + fun validate(): EventStream = apply { if (validated) { return@apply } @@ -3020,7 +1475,7 @@ private constructor( return true } - return other is AuthRuleType && value == other.value + return other is EventStream && value == other.value } override fun hashCode() = value.hashCode() @@ -3033,24 +1488,24 @@ private constructor( return true } - return other is CreateAuthRuleRequestAccountTokens && + return other is AccountLevelRule && + parameters == other.parameters && + type == other.type && accountTokens == other.accountTokens && businessAccountTokens == other.businessAccountTokens && eventStream == other.eventStream && name == other.name && - parameters == other.parameters && - type == other.type && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { Objects.hash( + parameters, + type, accountTokens, businessAccountTokens, eventStream, name, - parameters, - type, additionalProperties, ) } @@ -3058,17 +1513,17 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "CreateAuthRuleRequestAccountTokens{accountTokens=$accountTokens, businessAccountTokens=$businessAccountTokens, eventStream=$eventStream, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" + "AccountLevelRule{parameters=$parameters, type=$type, accountTokens=$accountTokens, businessAccountTokens=$businessAccountTokens, eventStream=$eventStream, name=$name, additionalProperties=$additionalProperties}" } - class CreateAuthRuleRequestCardTokens + class CardLevelRule @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val cardTokens: JsonField>, - private val eventStream: JsonField, - private val name: JsonField, private val parameters: JsonField, private val type: JsonField, + private val eventStream: JsonField, + private val name: JsonField, private val additionalProperties: MutableMap, ) { @@ -3077,17 +1532,17 @@ private constructor( @JsonProperty("card_tokens") @ExcludeMissing cardTokens: JsonField> = JsonMissing.of(), - @JsonProperty("event_stream") - @ExcludeMissing - eventStream: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("parameters") @ExcludeMissing parameters: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(cardTokens, eventStream, name, parameters, type, mutableMapOf()) + @JsonProperty("event_stream") + @ExcludeMissing + eventStream: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(cardTokens, parameters, type, eventStream, name, mutableMapOf()) /** * Card tokens to which the Auth Rule applies. @@ -3099,42 +1554,44 @@ private constructor( fun cardTokens(): List = cardTokens.getRequired("card_tokens") /** - * The event stream during which the rule will be evaluated. + * Parameters for the Auth Rule * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - fun eventStream(): Optional = eventStream.getOptional("event_stream") + fun parameters(): Parameters = parameters.getRequired("parameters") /** - * Auth Rule Name - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun name(): Optional = name.getOptional("name") + * The type of Auth Rule. For certain rule types, this determines the event stream + * during which it will be evaluated. For rules that can be applied to one of several + * event streams, the effective one is defined by the separate `event_stream` field. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): AuthRuleType = type.getRequired("type") /** - * Parameters for the Auth Rule + * The event stream during which the rule will be evaluated. * * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun parameters(): Optional = parameters.getOptional("parameters") + fun eventStream(): Optional = eventStream.getOptional("event_stream") /** - * The type of Auth Rule. For certain rule types, this determines the event stream - * during which it will be evaluated. For rules that can be applied to one of several - * event streams, the effective one is defined by the separate `event_stream` field. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * Auth Rule Name * * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun type(): Optional = type.getOptional("type") + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [cardTokens]. @@ -3147,38 +1604,38 @@ private constructor( fun _cardTokens(): JsonField> = cardTokens /** - * Returns the raw JSON value of [eventStream]. + * Returns the raw JSON value of [parameters]. * - * Unlike [eventStream], this method doesn't throw if the JSON field has an unexpected + * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("event_stream") + @JsonProperty("parameters") @ExcludeMissing - fun _eventStream(): JsonField = eventStream + fun _parameters(): JsonField = parameters /** - * Returns the raw JSON value of [name]. + * Returns the raw JSON value of [type]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** - * Returns the raw JSON value of [parameters]. + * Returns the raw JSON value of [eventStream]. * - * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected + * Unlike [eventStream], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("parameters") + @JsonProperty("event_stream") @ExcludeMissing - fun _parameters(): JsonField = parameters + fun _eventStream(): JsonField = eventStream /** - * Returns the raw JSON value of [type]. + * Returns the raw JSON value of [name]. * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -3195,39 +1652,36 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [CreateAuthRuleRequestCardTokens]. + * Returns a mutable builder for constructing an instance of [CardLevelRule]. * * The following fields are required: * ```java * .cardTokens() + * .parameters() + * .type() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [CreateAuthRuleRequestCardTokens]. */ + /** A builder for [CardLevelRule]. */ class Builder internal constructor() { private var cardTokens: JsonField>? = null + private var parameters: JsonField? = null + private var type: JsonField? = null private var eventStream: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() - private var parameters: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ) = apply { - cardTokens = - createAuthRuleRequestCardTokens.cardTokens.map { it.toMutableList() } - eventStream = createAuthRuleRequestCardTokens.eventStream - name = createAuthRuleRequestCardTokens.name - parameters = createAuthRuleRequestCardTokens.parameters - type = createAuthRuleRequestCardTokens.type - additionalProperties = - createAuthRuleRequestCardTokens.additionalProperties.toMutableMap() + internal fun from(cardLevelRule: CardLevelRule) = apply { + cardTokens = cardLevelRule.cardTokens.map { it.toMutableList() } + parameters = cardLevelRule.parameters + type = cardLevelRule.type + eventStream = cardLevelRule.eventStream + name = cardLevelRule.name + additionalProperties = cardLevelRule.additionalProperties.toMutableMap() } /** Card tokens to which the Auth Rule applies. */ @@ -3256,35 +1710,6 @@ private constructor( } } - /** The event stream during which the rule will be evaluated. */ - fun eventStream(eventStream: EventStream) = eventStream(JsonField.of(eventStream)) - - /** - * Sets [Builder.eventStream] to an arbitrary JSON value. - * - * You should usually call [Builder.eventStream] with a well-typed [EventStream] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun eventStream(eventStream: JsonField) = apply { - this.eventStream = eventStream - } - - /** Auth Rule Name */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun name(name: JsonField) = apply { this.name = name } - /** Parameters for the Auth Rule */ fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) @@ -3331,8 +1756,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: - Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3359,6 +1783,35 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + /** The event stream during which the rule will be evaluated. */ + fun eventStream(eventStream: EventStream) = eventStream(JsonField.of(eventStream)) + + /** + * Sets [Builder.eventStream] to an arbitrary JSON value. + * + * You should usually call [Builder.eventStream] with a well-typed [EventStream] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun eventStream(eventStream: JsonField) = apply { + this.eventStream = eventStream + } + + /** Auth Rule Name */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3382,40 +1835,42 @@ private constructor( } /** - * Returns an immutable instance of [CreateAuthRuleRequestCardTokens]. + * Returns an immutable instance of [CardLevelRule]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java * .cardTokens() + * .parameters() + * .type() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): CreateAuthRuleRequestCardTokens = - CreateAuthRuleRequestCardTokens( + fun build(): CardLevelRule = + CardLevelRule( checkRequired("cardTokens", cardTokens).map { it.toImmutable() }, + checkRequired("parameters", parameters), + checkRequired("type", type), eventStream, name, - parameters, - type, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): CreateAuthRuleRequestCardTokens = apply { + fun validate(): CardLevelRule = apply { if (validated) { return@apply } cardTokens() + parameters().validate() + type().validate() eventStream().ifPresent { it.validate() } name() - parameters().ifPresent { it.validate() } - type().ifPresent { it.validate() } validated = true } @@ -3436,143 +1891,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (cardTokens.asKnown().getOrNull()?.size ?: 0) + - (eventStream.asKnown().getOrNull()?.validity() ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - /** The event stream during which the rule will be evaluated. */ - class EventStream - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val AUTHORIZATION = of("AUTHORIZATION") - - @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") - - @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) - } - - /** An enum containing [EventStream]'s known values. */ - enum class Known { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - } - - /** - * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [EventStream] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - /** - * An enum member indicating that [EventStream] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - AUTHORIZATION -> Value.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - AUTHORIZATION -> Known.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION - else -> throw LithicInvalidDataException("Unknown EventStream: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): EventStream = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is EventStream && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } + (type.asKnown().getOrNull()?.validity() ?: 0) + + (eventStream.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) /** Parameters for the Auth Rule */ @JsonDeserialize(using = Parameters.Deserializer::class) @@ -3905,1501 +2227,7 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("action") - @ExcludeMissing - fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of - * [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Action] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("value") - @ExcludeMissing - fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: - * (1) all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and - * (3) ANT for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to - * the issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary - * account number (PAN) was entered. Valid values are `AUTO_ENTRY`, - * `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, - * `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, - * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, - * `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus - * the acquirer fee field in the settlement/cardholder billing - * currency. This is the amount the issuer should authorize against - * unless the issuer is paying the acquirer fee on behalf of the - * cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authorization. Scores are on a range of - * 0-999, with 0 representing the lowest risk and 999 representing the - * highest risk. For Visa transactions, where the raw score has a - * range of 0-99, Lithic will normalize the score by multiplying the - * raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the - * card in the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card - * in the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the - * card in the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, - * indicates the source of the token. Valid values are `APPLE_PAY`, - * `GOOGLE_PAY`, `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, - * `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid - * values are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed - * [Attribute] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed - * [Operation] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with - * `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Attribute] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException( - "Unknown Attribute: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField - val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Operation] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException( - "Unknown Operation: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> - visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings( - listOfStrings: List - ) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings( - listOfStrings: List - ) = listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = - Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a - * value of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the - * API may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { Value(regex = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { - Value(listOfStrings = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } + } /** * The type of Auth Rule. For certain rule types, this determines the event stream @@ -5555,79 +2383,236 @@ private constructor( override fun toString() = value.toString() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The event stream during which the rule will be evaluated. */ + class EventStream + @JsonCreator + private constructor(private val value: JsonField) : Enum { - return other is CreateAuthRuleRequestCardTokens && - cardTokens == other.cardTokens && - eventStream == other.eventStream && - name == other.name && - parameters == other.parameters && - type == other.type && - additionalProperties == other.additionalProperties - } + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - private val hashCode: Int by lazy { - Objects.hash(cardTokens, eventStream, name, parameters, type, additionalProperties) - } + companion object { - override fun hashCode(): Int = hashCode + @JvmField val AUTHORIZATION = of("AUTHORIZATION") - override fun toString() = - "CreateAuthRuleRequestCardTokens{cardTokens=$cardTokens, eventStream=$eventStream, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" - } + @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") - class CreateAuthRuleRequestProgramLevel - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val programLevel: JsonField, - private val eventStream: JsonField, - private val excludedCardTokens: JsonField>, - private val name: JsonField, - private val parameters: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { + @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) + } - @JsonCreator - private constructor( - @JsonProperty("program_level") - @ExcludeMissing - programLevel: JsonField = JsonMissing.of(), - @JsonProperty("event_stream") - @ExcludeMissing - eventStream: JsonField = JsonMissing.of(), - @JsonProperty("excluded_card_tokens") - @ExcludeMissing - excludedCardTokens: JsonField> = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - type: JsonField = JsonMissing.of(), - ) : this( - programLevel, - eventStream, - excludedCardTokens, - name, - parameters, - type, - mutableMapOf(), - ) + /** An enum containing [EventStream]'s known values. */ + enum class Known { + AUTHORIZATION, + THREE_DS_AUTHENTICATION, + } - /** - * Whether the Auth Rule applies to all authorizations on the card program. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected + /** + * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventStream] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + AUTHORIZATION, + THREE_DS_AUTHENTICATION, + /** + * An enum member indicating that [EventStream] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + AUTHORIZATION -> Value.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHORIZATION -> Known.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION + else -> throw LithicInvalidDataException("Unknown EventStream: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventStream = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventStream && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CardLevelRule && + cardTokens == other.cardTokens && + parameters == other.parameters && + type == other.type && + eventStream == other.eventStream && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(cardTokens, parameters, type, eventStream, name, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CardLevelRule{cardTokens=$cardTokens, parameters=$parameters, type=$type, eventStream=$eventStream, name=$name, additionalProperties=$additionalProperties}" + } + + class ProgramLevelRule + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val parameters: JsonField, + private val programLevel: JsonField, + private val type: JsonField, + private val eventStream: JsonField, + private val excludedCardTokens: JsonField>, + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("program_level") + @ExcludeMissing + programLevel: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), + @JsonProperty("event_stream") + @ExcludeMissing + eventStream: JsonField = JsonMissing.of(), + @JsonProperty("excluded_card_tokens") + @ExcludeMissing + excludedCardTokens: JsonField> = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this( + parameters, + programLevel, + type, + eventStream, + excludedCardTokens, + name, + mutableMapOf(), + ) + + /** + * Parameters for the Auth Rule + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun parameters(): Parameters = parameters.getRequired("parameters") + + /** + * Whether the Auth Rule applies to all authorizations on the card program. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected * value). */ fun programLevel(): Boolean = programLevel.getRequired("program_level") + /** + * The type of Auth Rule. For certain rule types, this determines the event stream + * during which it will be evaluated. For rules that can be applied to one of several + * event streams, the effective one is defined by the separate `event_stream` field. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun type(): AuthRuleType = type.getRequired("type") + /** * The event stream during which the rule will be evaluated. * @@ -5654,26 +2639,14 @@ private constructor( fun name(): Optional = name.getOptional("name") /** - * Parameters for the Auth Rule - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun parameters(): Optional = parameters.getOptional("parameters") - - /** - * The type of Auth Rule. For certain rule types, this determines the event stream - * during which it will be evaluated. For rules that can be applied to one of several - * event streams, the effective one is defined by the separate `event_stream` field. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_ACTION`: AUTHORIZATION or THREE_DS_AUTHENTICATION event stream. + * Returns the raw JSON value of [parameters]. * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun type(): Optional = type.getOptional("type") + @JsonProperty("parameters") + @ExcludeMissing + fun _parameters(): JsonField = parameters /** * Returns the raw JSON value of [programLevel]. @@ -5685,6 +2658,13 @@ private constructor( @ExcludeMissing fun _programLevel(): JsonField = programLevel + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** * Returns the raw JSON value of [eventStream]. * @@ -5712,23 +2692,6 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - /** - * Returns the raw JSON value of [parameters]. - * - * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("parameters") - @ExcludeMissing - fun _parameters(): JsonField = parameters - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -5744,127 +2707,53 @@ private constructor( companion object { /** - * Returns a mutable builder for constructing an instance of - * [CreateAuthRuleRequestProgramLevel]. + * Returns a mutable builder for constructing an instance of [ProgramLevelRule]. * * The following fields are required: * ```java + * .parameters() * .programLevel() + * .type() * ``` */ @JvmStatic fun builder() = Builder() } - /** A builder for [CreateAuthRuleRequestProgramLevel]. */ + /** A builder for [ProgramLevelRule]. */ class Builder internal constructor() { + private var parameters: JsonField? = null private var programLevel: JsonField? = null + private var type: JsonField? = null private var eventStream: JsonField = JsonMissing.of() private var excludedCardTokens: JsonField>? = null private var name: JsonField = JsonMissing.of() - private var parameters: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from( - createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel - ) = apply { - programLevel = createAuthRuleRequestProgramLevel.programLevel - eventStream = createAuthRuleRequestProgramLevel.eventStream + internal fun from(programLevelRule: ProgramLevelRule) = apply { + parameters = programLevelRule.parameters + programLevel = programLevelRule.programLevel + type = programLevelRule.type + eventStream = programLevelRule.eventStream excludedCardTokens = - createAuthRuleRequestProgramLevel.excludedCardTokens.map { - it.toMutableList() - } - name = createAuthRuleRequestProgramLevel.name - parameters = createAuthRuleRequestProgramLevel.parameters - type = createAuthRuleRequestProgramLevel.type - additionalProperties = - createAuthRuleRequestProgramLevel.additionalProperties.toMutableMap() + programLevelRule.excludedCardTokens.map { it.toMutableList() } + name = programLevelRule.name + additionalProperties = programLevelRule.additionalProperties.toMutableMap() } - /** Whether the Auth Rule applies to all authorizations on the card program. */ - fun programLevel(programLevel: Boolean) = programLevel(JsonField.of(programLevel)) + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) /** - * Sets [Builder.programLevel] to an arbitrary JSON value. + * Sets [Builder.parameters] to an arbitrary JSON value. * - * You should usually call [Builder.programLevel] with a well-typed [Boolean] value + * You should usually call [Builder.parameters] with a well-typed [Parameters] value * instead. This method is primarily for setting the field to an undocumented or not * yet supported value. */ - fun programLevel(programLevel: JsonField) = apply { - this.programLevel = programLevel - } - - /** The event stream during which the rule will be evaluated. */ - fun eventStream(eventStream: EventStream) = eventStream(JsonField.of(eventStream)) - - /** - * Sets [Builder.eventStream] to an arbitrary JSON value. - * - * You should usually call [Builder.eventStream] with a well-typed [EventStream] - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun eventStream(eventStream: JsonField) = apply { - this.eventStream = eventStream - } - - /** Card tokens to which the Auth Rule does not apply. */ - fun excludedCardTokens(excludedCardTokens: List) = - excludedCardTokens(JsonField.of(excludedCardTokens)) - - /** - * Sets [Builder.excludedCardTokens] to an arbitrary JSON value. - * - * You should usually call [Builder.excludedCardTokens] with a well-typed - * `List` value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - fun excludedCardTokens(excludedCardTokens: JsonField>) = apply { - this.excludedCardTokens = excludedCardTokens.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [excludedCardTokens]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addExcludedCardToken(excludedCardToken: String) = apply { - excludedCardTokens = - (excludedCardTokens ?: JsonField.of(mutableListOf())).also { - checkKnown("excludedCardTokens", it).add(excludedCardToken) - } - } - - /** Auth Rule Name */ - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun name(name: JsonField) = apply { this.name = name } - - /** Parameters for the Auth Rule */ - fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - - /** - * Sets [Builder.parameters] to an arbitrary JSON value. - * - * You should usually call [Builder.parameters] with a well-typed [Parameters] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun parameters(parameters: JsonField) = apply { - this.parameters = parameters + fun parameters(parameters: JsonField) = apply { + this.parameters = parameters } /** @@ -5899,13 +2788,26 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: - Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) ) + /** Whether the Auth Rule applies to all authorizations on the card program. */ + fun programLevel(programLevel: Boolean) = programLevel(JsonField.of(programLevel)) + + /** + * Sets [Builder.programLevel] to an arbitrary JSON value. + * + * You should usually call [Builder.programLevel] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun programLevel(programLevel: JsonField) = apply { + this.programLevel = programLevel + } + /** * The type of Auth Rule. For certain rule types, this determines the event stream * during which it will be evaluated. For rules that can be applied to one of @@ -5927,6 +2829,62 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + /** The event stream during which the rule will be evaluated. */ + fun eventStream(eventStream: EventStream) = eventStream(JsonField.of(eventStream)) + + /** + * Sets [Builder.eventStream] to an arbitrary JSON value. + * + * You should usually call [Builder.eventStream] with a well-typed [EventStream] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun eventStream(eventStream: JsonField) = apply { + this.eventStream = eventStream + } + + /** Card tokens to which the Auth Rule does not apply. */ + fun excludedCardTokens(excludedCardTokens: List) = + excludedCardTokens(JsonField.of(excludedCardTokens)) + + /** + * Sets [Builder.excludedCardTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.excludedCardTokens] with a well-typed + * `List` value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun excludedCardTokens(excludedCardTokens: JsonField>) = apply { + this.excludedCardTokens = excludedCardTokens.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [excludedCardTokens]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addExcludedCardToken(excludedCardToken: String) = apply { + excludedCardTokens = + (excludedCardTokens ?: JsonField.of(mutableListOf())).also { + checkKnown("excludedCardTokens", it).add(excludedCardToken) + } + } + + /** Auth Rule Name */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -5950,42 +2908,44 @@ private constructor( } /** - * Returns an immutable instance of [CreateAuthRuleRequestProgramLevel]. + * Returns an immutable instance of [ProgramLevelRule]. * * Further updates to this [Builder] will not mutate the returned instance. * * The following fields are required: * ```java + * .parameters() * .programLevel() + * .type() * ``` * * @throws IllegalStateException if any required field is unset. */ - fun build(): CreateAuthRuleRequestProgramLevel = - CreateAuthRuleRequestProgramLevel( + fun build(): ProgramLevelRule = + ProgramLevelRule( + checkRequired("parameters", parameters), checkRequired("programLevel", programLevel), + checkRequired("type", type), eventStream, (excludedCardTokens ?: JsonMissing.of()).map { it.toImmutable() }, name, - parameters, - type, additionalProperties.toMutableMap(), ) } private var validated: Boolean = false - fun validate(): CreateAuthRuleRequestProgramLevel = apply { + fun validate(): ProgramLevelRule = apply { if (validated) { return@apply } + parameters().validate() programLevel() + type().validate() eventStream().ifPresent { it.validate() } excludedCardTokens() name() - parameters().ifPresent { it.validate() } - type().ifPresent { it.validate() } validated = true } @@ -6005,193 +2965,60 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (programLevel.asKnown().isPresent) 1 else 0) + + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (programLevel.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + (eventStream.asKnown().getOrNull()?.validity() ?: 0) + (excludedCardTokens.asKnown().getOrNull()?.size ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) - /** The event stream during which the rule will be evaluated. */ - class EventStream - @JsonCreator - private constructor(private val value: JsonField) : Enum { + /** Parameters for the Auth Rule */ + @JsonDeserialize(using = Parameters.Deserializer::class) + @JsonSerialize(using = Parameters.Serializer::class) + class Parameters + private constructor( + private val conditionalBlock: ConditionalBlockParameters? = null, + private val velocityLimitParams: VelocityLimitParams? = null, + private val merchantLock: MerchantLockParameters? = null, + private val conditional3dsAction: Conditional3dsActionParameters? = null, + private val conditionalAuthorizationAction: + ConditionalAuthorizationActionParameters? = + null, + private val _json: JsonValue? = null, + ) { - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - companion object { + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - @JvmField val AUTHORIZATION = of("AUTHORIZATION") + fun merchantLock(): Optional = + Optional.ofNullable(merchantLock) - @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) - } + fun conditionalAuthorizationAction(): + Optional = + Optional.ofNullable(conditionalAuthorizationAction) - /** An enum containing [EventStream]'s known values. */ - enum class Known { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - } + fun isConditionalBlock(): Boolean = conditionalBlock != null - /** - * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [EventStream] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - AUTHORIZATION, - THREE_DS_AUTHENTICATION, - /** - * An enum member indicating that [EventStream] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - AUTHORIZATION -> Value.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION - else -> Value._UNKNOWN - } + fun isMerchantLock(): Boolean = merchantLock != null - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - AUTHORIZATION -> Known.AUTHORIZATION - THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION - else -> throw LithicInvalidDataException("Unknown EventStream: $value") - } + fun isConditional3dsAction(): Boolean = conditional3dsAction != null - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } + fun isConditionalAuthorizationAction(): Boolean = + conditionalAuthorizationAction != null - private var validated: Boolean = false + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - fun validate(): EventStream = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is EventStream && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** Parameters for the Auth Rule */ - @JsonDeserialize(using = Parameters.Deserializer::class) - @JsonSerialize(using = Parameters.Serializer::class) - class Parameters - private constructor( - private val conditionalBlock: ConditionalBlockParameters? = null, - private val velocityLimitParams: VelocityLimitParams? = null, - private val merchantLock: MerchantLockParameters? = null, - private val conditional3dsAction: Conditional3dsActionParameters? = null, - private val conditionalAuthorizationAction: - ConditionalAuthorizationActionParameters? = - null, - private val _json: JsonValue? = null, - ) { - - fun conditionalBlock(): Optional = - Optional.ofNullable(conditionalBlock) - - fun velocityLimitParams(): Optional = - Optional.ofNullable(velocityLimitParams) - - fun merchantLock(): Optional = - Optional.ofNullable(merchantLock) - - fun conditional3dsAction(): Optional = - Optional.ofNullable(conditional3dsAction) - - fun conditionalAuthorizationAction(): - Optional = - Optional.ofNullable(conditionalAuthorizationAction) - - fun isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun isConditionalAuthorizationAction(): Boolean = - conditionalAuthorizationAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") @@ -6355,1620 +3182,126 @@ private constructor( @JvmStatic fun ofConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = Parameters(conditional3dsAction = conditional3dsAction) - - @JvmStatic - fun ofConditionalAuthorizationAction( - conditionalAuthorizationAction: ConditionalAuthorizationActionParameters - ) = Parameters(conditionalAuthorizationAction = conditionalAuthorizationAction) - } - - /** - * An interface that defines how to map each variant of [Parameters] to a value of - * type [T]. - */ - interface Visitor { - - fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - - fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - - fun visitMerchantLock(merchantLock: MerchantLockParameters): T - - fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ): T - - fun visitConditionalAuthorizationAction( - conditionalAuthorizationAction: ConditionalAuthorizationActionParameters - ): T - - /** - * Maps an unknown variant of [Parameters] to a value of type [T]. - * - * An instance of [Parameters] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, if - * the SDK is on an older version than the API, then the API may respond with - * new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Parameters: $json") - } - } - - internal class Deserializer : BaseDeserializer(Parameters::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Parameters { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { Parameters(conditionalBlock = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef()) - ?.let { - Parameters(velocityLimitParams = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef()) - ?.let { Parameters(merchantLock = it, _json = json) }, - tryDeserialize( - node, - jacksonTypeRef(), - ) - ?.let { - Parameters(conditional3dsAction = it, _json = json) - }, - tryDeserialize( - node, - jacksonTypeRef< - ConditionalAuthorizationActionParameters - >(), - ) - ?.let { - Parameters( - conditionalAuthorizationAction = it, - _json = json, - ) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing from - // boolean). - 0 -> Parameters(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then use - // the first completely valid match, or simply the first match if none - // are completely valid. - else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Parameters::class) { - - override fun serialize( - value: Parameters, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.conditionalBlock != null -> - generator.writeObject(value.conditionalBlock) - value.velocityLimitParams != null -> - generator.writeObject(value.velocityLimitParams) - value.merchantLock != null -> generator.writeObject(value.merchantLock) - value.conditional3dsAction != null -> - generator.writeObject(value.conditional3dsAction) - value.conditionalAuthorizationAction != null -> - generator.writeObject(value.conditionalAuthorizationAction) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * or is unexpectedly missing or null (e.g. if the server responded with an - * unexpected value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("action") - @ExcludeMissing - fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of - * [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Action] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("value") - @ExcludeMissing - fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: - * (1) all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and - * (3) ANT for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to - * the issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary - * account number (PAN) was entered. Valid values are `AUTO_ENTRY`, - * `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, - * `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, - * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, - * `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus - * the acquirer fee field in the settlement/cardholder billing - * currency. This is the amount the issuer should authorize against - * unless the issuer is paying the acquirer fee on behalf of the - * cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authorization. Scores are on a range of - * 0-999, with 0 representing the lowest risk and 999 representing the - * highest risk. For Visa transactions, where the raw score has a - * range of 0-99, Lithic will normalize the score by multiplying the - * raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the - * card in the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card - * in the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the - * card in the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, - * indicates the source of the token. Valid values are `APPLE_PAY`, - * `GOOGLE_PAY`, `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, - * `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid - * values are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed - * [Attribute] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed - * [Operation] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with - * `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Attribute] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException( - "Unknown Attribute: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from - * data that doesn't match any known member, and you want to know that - * value. For example, if the SDK is on an older version than the API, - * then the API may respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField - val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an - * [_UNKNOWN] member. - * - * An instance of [Operation] can contain an unknown value in a couple - * of cases: - * - It was deserialized from data that doesn't match any known member. - * For example, if the SDK is on an older version than the API, then - * the API may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, - * or [Value._UNKNOWN] if the class was instantiated with an unknown - * value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is - * always known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is - * a not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException( - "Unknown Operation: $value" - ) - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is - * primarily for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value - * does not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> - visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings( - listOfStrings: List - ) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in - * this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings( - listOfStrings: List - ) = listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = - Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } + conditional3dsAction: Conditional3dsActionParameters + ) = Parameters(conditional3dsAction = conditional3dsAction) - /** - * An interface that defines how to map each variant of [Value] to a - * value of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the - * API may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } + @JvmStatic + fun ofConditionalAuthorizationAction( + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters + ) = Parameters(conditionalAuthorizationAction = conditionalAuthorizationAction) + } - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef()) - ?.let { Value(regex = it, _json = json) }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { - Value(listOfStrings = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } + /** + * An interface that defines how to map each variant of [Parameters] to a value of + * type [T]. + */ + interface Visitor { - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - override fun hashCode(): Int = hashCode + fun visitConditionalAuthorizationAction( + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters + ): T - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" + /** + * Maps an unknown variant of [Parameters] to a value of type [T]. + * + * An instance of [Parameters] can contain an unknown variant if it was + * deserialized from data that doesn't match any known variant. For example, if + * the SDK is on an older version than the API, then the API may respond with + * new variants that the SDK is unaware of. + * + * @throws LithicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LithicInvalidDataException("Unknown Parameters: $json") } + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Parameters(conditionalBlock = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { + Parameters(velocityLimitParams = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Parameters(merchantLock = it, _json = json) }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Parameters(conditional3dsAction = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef< + ConditionalAuthorizationActionParameters + >(), + ) + ?.let { + Parameters( + conditionalAuthorizationAction = it, + _json = json, + ) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants (e.g. deserializing from + // boolean). + 0 -> Parameters(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } } + } - override fun hashCode(): Int = hashCode + internal class Serializer : BaseSerializer(Parameters::class) { - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" + override fun serialize( + value: Parameters, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.conditionalBlock != null -> + generator.writeObject(value.conditionalBlock) + value.velocityLimitParams != null -> + generator.writeObject(value.velocityLimitParams) + value.merchantLock != null -> generator.writeObject(value.merchantLock) + value.conditional3dsAction != null -> + generator.writeObject(value.conditional3dsAction) + value.conditionalAuthorizationAction != null -> + generator.writeObject(value.conditionalAuthorizationAction) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } + } } } @@ -8126,29 +3459,162 @@ private constructor( override fun toString() = value.toString() } + /** The event stream during which the rule will be evaluated. */ + class EventStream + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AUTHORIZATION = of("AUTHORIZATION") + + @JvmField val THREE_DS_AUTHENTICATION = of("THREE_DS_AUTHENTICATION") + + @JvmStatic fun of(value: String) = EventStream(JsonField.of(value)) + } + + /** An enum containing [EventStream]'s known values. */ + enum class Known { + AUTHORIZATION, + THREE_DS_AUTHENTICATION, + } + + /** + * An enum containing [EventStream]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [EventStream] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + AUTHORIZATION, + THREE_DS_AUTHENTICATION, + /** + * An enum member indicating that [EventStream] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + AUTHORIZATION -> Value.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Value.THREE_DS_AUTHENTICATION + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + AUTHORIZATION -> Known.AUTHORIZATION + THREE_DS_AUTHENTICATION -> Known.THREE_DS_AUTHENTICATION + else -> throw LithicInvalidDataException("Unknown EventStream: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): EventStream = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is EventStream && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is CreateAuthRuleRequestProgramLevel && + return other is ProgramLevelRule && + parameters == other.parameters && programLevel == other.programLevel && + type == other.type && eventStream == other.eventStream && excludedCardTokens == other.excludedCardTokens && name == other.name && - parameters == other.parameters && - type == other.type && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { Objects.hash( + parameters, programLevel, + type, eventStream, excludedCardTokens, name, - parameters, - type, additionalProperties, ) } @@ -8156,7 +3622,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "CreateAuthRuleRequestProgramLevel{programLevel=$programLevel, eventStream=$eventStream, excludedCardTokens=$excludedCardTokens, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" + "ProgramLevelRule{parameters=$parameters, programLevel=$programLevel, type=$type, eventStream=$eventStream, excludedCardTokens=$excludedCardTokens, name=$name, additionalProperties=$additionalProperties}" } } diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2DraftParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2DraftParams.kt index ffbb84f7..da480f2e 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2DraftParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/AuthRuleV2DraftParams.kt @@ -15,19 +15,15 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.lithic.api.core.BaseDeserializer import com.lithic.api.core.BaseSerializer -import com.lithic.api.core.Enum import com.lithic.api.core.ExcludeMissing import com.lithic.api.core.JsonField import com.lithic.api.core.JsonMissing import com.lithic.api.core.JsonValue import com.lithic.api.core.Params import com.lithic.api.core.allMaxBy -import com.lithic.api.core.checkKnown -import com.lithic.api.core.checkRequired import com.lithic.api.core.getOrThrow import com.lithic.api.core.http.Headers import com.lithic.api.core.http.QueryParams -import com.lithic.api.core.toImmutable import com.lithic.api.errors.LithicInvalidDataException import java.util.Collections import java.util.Objects @@ -161,9 +157,10 @@ private constructor( * Alias for calling [parameters] with * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ - fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters - ) = apply { body.parameters(conditionalAuthorizationAction) } + fun parameters(conditionalAuthorizationAction: ConditionalAuthorizationActionParameters) = + apply { + body.parameters(conditionalAuthorizationAction) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) @@ -416,7 +413,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -797,1426 +794,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties.toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action @JsonCreator private constructor(private val value: JsonField) : - Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a - * business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all ISO - * 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for Netherlands - * Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of - * the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer - * applies to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or - * `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number - * (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`, - * `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, - * `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, - * `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer - * fee field in the settlement/cardholder billing currency. This is the amount the - * issuer should authorize against unless the issuer is paying the acquirer fee on - * behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). This - * represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing the - * lowest risk and 999 representing the highest risk. For Visa transactions, where - * the raw score has a range of 0-99, Lithic will normalize the score by - * multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the transaction. - * Valid values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`, - * `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, `SAMSUNG_PAY`, - * `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction indicates - * the source of the token. Valid values are `CARDHOLDER`, `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [Condition]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition(attribute, operation, value, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a - * business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all ISO - * 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for Netherlands - * Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of - * the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer - * applies to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or - * `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number - * (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`, - * `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, - * `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, - * `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer - * fee field in the settlement/cardholder billing currency. This is the amount the - * issuer should authorize against unless the issuer is paying the acquirer fee on - * behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). This - * represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing the - * lowest risk and 999 representing the highest risk. For Visa transactions, where - * the raw score has a range of 0-99, Lithic will normalize the score by - * multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the transaction. - * Valid values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`, - * `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, `SAMSUNG_PAY`, - * `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction indicates - * the source of the token. Valid values are `CARDHOLDER`, `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, - * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or - * `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, - * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or - * `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value of - * type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For example, - * if the SDK is on an older version than the API, then the API may respond - * with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>())?.let { - Value(listOfStrings = it, _json = json) - }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. deserializing - // from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, then - // use the first completely valid match, or simply the first match - // if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParameters.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParameters.kt new file mode 100644 index 00000000..9a928f25 --- /dev/null +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParameters.kt @@ -0,0 +1,1392 @@ +// 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.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.lithic.api.core.BaseDeserializer +import com.lithic.api.core.BaseSerializer +import com.lithic.api.core.Enum +import com.lithic.api.core.ExcludeMissing +import com.lithic.api.core.JsonField +import com.lithic.api.core.JsonMissing +import com.lithic.api.core.JsonValue +import com.lithic.api.core.allMaxBy +import com.lithic.api.core.checkKnown +import com.lithic.api.core.checkRequired +import com.lithic.api.core.getOrThrow +import com.lithic.api.core.toImmutable +import com.lithic.api.errors.LithicInvalidDataException +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class ConditionalAuthorizationActionParameters +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val action: JsonField, + private val conditions: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("action") @ExcludeMissing action: JsonField = JsonMissing.of(), + @JsonProperty("conditions") + @ExcludeMissing + conditions: JsonField> = JsonMissing.of(), + ) : this(action, conditions, mutableMapOf()) + + /** + * The action to take if the conditions are met. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun action(): Action = action.getRequired("action") + + /** + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun conditions(): List = conditions.getRequired("conditions") + + /** + * Returns the raw JSON value of [action]. + * + * Unlike [action], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action + + /** + * Returns the raw JSON value of [conditions]. + * + * Unlike [conditions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("conditions") + @ExcludeMissing + fun _conditions(): JsonField> = conditions + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ConditionalAuthorizationActionParameters]. + * + * The following fields are required: + * ```java + * .action() + * .conditions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ConditionalAuthorizationActionParameters]. */ + class Builder internal constructor() { + + private var action: JsonField? = null + private var conditions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + conditionalAuthorizationActionParameters: ConditionalAuthorizationActionParameters + ) = apply { + action = conditionalAuthorizationActionParameters.action + conditions = + conditionalAuthorizationActionParameters.conditions.map { it.toMutableList() } + additionalProperties = + conditionalAuthorizationActionParameters.additionalProperties.toMutableMap() + } + + /** The action to take if the conditions are met. */ + fun action(action: Action) = action(JsonField.of(action)) + + /** + * Sets [Builder.action] to an arbitrary JSON value. + * + * You should usually call [Builder.action] with a well-typed [Action] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun action(action: JsonField) = apply { this.action = action } + + fun conditions(conditions: List) = conditions(JsonField.of(conditions)) + + /** + * Sets [Builder.conditions] to an arbitrary JSON value. + * + * You should usually call [Builder.conditions] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun conditions(conditions: JsonField>) = apply { + this.conditions = conditions.map { it.toMutableList() } + } + + /** + * Adds a single [Condition] to [conditions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCondition(condition: Condition) = apply { + conditions = + (conditions ?: JsonField.of(mutableListOf())).also { + checkKnown("conditions", it).add(condition) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .action() + * .conditions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConditionalAuthorizationActionParameters = + ConditionalAuthorizationActionParameters( + checkRequired("action", action), + checkRequired("conditions", conditions).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ConditionalAuthorizationActionParameters = apply { + if (validated) { + return@apply + } + + action().validate() + conditions().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (action.asKnown().getOrNull()?.validity() ?: 0) + + (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** The action to take if the conditions are met. */ + class Action @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val DECLINE = of("DECLINE") + + @JvmField val CHALLENGE = of("CHALLENGE") + + @JvmStatic fun of(value: String) = Action(JsonField.of(value)) + } + + /** An enum containing [Action]'s known values. */ + enum class Known { + DECLINE, + CHALLENGE, + } + + /** + * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Action] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + DECLINE, + CHALLENGE, + /** An enum member indicating that [Action] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + DECLINE -> Value.DECLINE + CHALLENGE -> Value.CHALLENGE + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + DECLINE -> Known.DECLINE + CHALLENGE -> Known.CHALLENGE + else -> throw LithicInvalidDataException("Unknown Action: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { LithicInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + fun validate(): Action = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Action && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Condition + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attribute: JsonField, + private val operation: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attribute") + @ExcludeMissing + attribute: JsonField = JsonMissing.of(), + @JsonProperty("operation") + @ExcludeMissing + operation: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(attribute, operation, value, mutableMapOf()) + + /** + * The attribute to target. + * + * The following attributes may be targeted: + * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a business + * by the types of goods or services it provides. + * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all ISO 3166-1 + * alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for Netherlands Antilles. + * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of the + * transaction. + * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor (merchant). + * * `DESCRIPTOR`: Short description of card acceptor. + * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer applies + * to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or + * `TOKEN_AUTHENTICATED`. + * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number (PAN) was + * entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, + * `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, + * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or + * `ECOMMERCE`. + * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer fee + * field in the settlement/cardholder billing currency. This is the amount the issuer + * should authorize against unless the issuer is paying the acquirer fee on behalf of the + * cardholder. + * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). This + * represents the amount of cash being withdrawn or advanced. + * * `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authorization. Scores are on a range of 0-999, with 0 representing the lowest risk and + * 999 representing the highest risk. For Visa transactions, where the raw score has a + * range of 0-99, Lithic will normalize the score by multiplying the raw score by 10x. + * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the trailing 15 + * minutes before the authorization. + * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the trailing + * hour up and until the authorization. + * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the trailing 24 + * hours up and until the authorization. + * * `CARD_STATE`: The current state of the card associated with the transaction. Valid + * values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. + * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. Valid values + * are `TRUE`, `FALSE`. + * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, `OK`, + * `BLOCKED`. + * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the source of + * the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, `SAMSUNG_PAY`, `MASTERPASS`, + * `MERCHANT`, `OTHER`, `NONE`. + * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction indicates the source + * of the token. Valid values are `CARDHOLDER`, `MERCHANT`, `UNKNOWN`. + * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address data with + * the cardholder KYC data if it exists. Valid values are `MATCH`, `MATCH_ADDRESS_ONLY`, + * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attribute(): Optional = attribute.getOptional("attribute") + + /** + * The operation to apply to the attribute + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun operation(): Optional = operation.getOptional("operation") + + /** + * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun value(): Optional = value.getOptional("value") + + /** + * Returns the raw JSON value of [attribute]. + * + * Unlike [attribute], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attribute") + @ExcludeMissing + fun _attribute(): JsonField = attribute + + /** + * Returns the raw JSON value of [operation]. + * + * Unlike [operation], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("operation") + @ExcludeMissing + fun _operation(): JsonField = operation + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Condition]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Condition]. */ + class Builder internal constructor() { + + private var attribute: JsonField = JsonMissing.of() + private var operation: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(condition: Condition) = apply { + attribute = condition.attribute + operation = condition.operation + value = condition.value + additionalProperties = condition.additionalProperties.toMutableMap() + } + + /** + * The attribute to target. + * + * The following attributes may be targeted: + * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a + * business by the types of goods or services it provides. + * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all ISO + * 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for Netherlands + * Antilles. + * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of the + * transaction. + * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor + * (merchant). + * * `DESCRIPTOR`: Short description of card acceptor. + * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer + * applies to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or + * `TOKEN_AUTHENTICATED`. + * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number (PAN) + * was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, + * `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, + * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, + * or `ECOMMERCE`. + * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer fee + * field in the settlement/cardholder billing currency. This is the amount the issuer + * should authorize against unless the issuer is paying the acquirer fee on behalf of + * the cardholder. + * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). This + * represents the amount of cash being withdrawn or advanced. + * * `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authorization. Scores are on a range of 0-999, with 0 representing the lowest risk + * and 999 representing the highest risk. For Visa transactions, where the raw score + * has a range of 0-99, Lithic will normalize the score by multiplying the raw score + * by 10x. + * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the + * trailing 15 minutes before the authorization. + * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the trailing + * hour up and until the authorization. + * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the + * trailing 24 hours up and until the authorization. + * * `CARD_STATE`: The current state of the card associated with the transaction. Valid + * values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. + * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. Valid + * values are `TRUE`, `FALSE`. + * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, `OK`, + * `BLOCKED`. + * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the source + * of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, `SAMSUNG_PAY`, + * `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. + * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction indicates the + * source of the token. Valid values are `CARDHOLDER`, `MERCHANT`, `UNKNOWN`. + * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address data + * with the cardholder KYC data if it exists. Valid values are `MATCH`, + * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. + */ + fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) + + /** + * Sets [Builder.attribute] to an arbitrary JSON value. + * + * You should usually call [Builder.attribute] with a well-typed [Attribute] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attribute(attribute: JsonField) = apply { this.attribute = attribute } + + /** The operation to apply to the attribute */ + fun operation(operation: Operation) = operation(JsonField.of(operation)) + + /** + * Sets [Builder.operation] to an arbitrary JSON value. + * + * You should usually call [Builder.operation] with a well-typed [Operation] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun operation(operation: JsonField) = apply { this.operation = operation } + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + fun value(value: Value) = value(JsonField.of(value)) + + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun value(value: JsonField) = apply { this.value = value } + + /** Alias for calling [value] with `Value.ofRegex(regex)`. */ + fun value(regex: String) = value(Value.ofRegex(regex)) + + /** Alias for calling [value] with `Value.ofNumber(number)`. */ + fun value(number: Long) = value(Value.ofNumber(number)) + + /** Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. */ + fun valueOfListOfStrings(listOfStrings: List) = + value(Value.ofListOfStrings(listOfStrings)) + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Condition]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Condition = + Condition(attribute, operation, value, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Condition = apply { + if (validated) { + return@apply + } + + attribute().ifPresent { it.validate() } + operation().ifPresent { it.validate() } + value().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (attribute.asKnown().getOrNull()?.validity() ?: 0) + + (operation.asKnown().getOrNull()?.validity() ?: 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) + + /** + * The attribute to target. + * + * The following attributes may be targeted: + * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a business + * by the types of goods or services it provides. + * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all ISO 3166-1 + * alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for Netherlands Antilles. + * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of the + * transaction. + * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor (merchant). + * * `DESCRIPTOR`: Short description of card acceptor. + * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer applies + * to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or + * `TOKEN_AUTHENTICATED`. + * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number (PAN) was + * entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`, `ECOMMERCE`, + * `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, + * `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or + * `ECOMMERCE`. + * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer fee + * field in the settlement/cardholder billing currency. This is the amount the issuer + * should authorize against unless the issuer is paying the acquirer fee on behalf of the + * cardholder. + * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). This + * represents the amount of cash being withdrawn or advanced. + * * `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authorization. Scores are on a range of 0-999, with 0 representing the lowest risk and + * 999 representing the highest risk. For Visa transactions, where the raw score has a + * range of 0-99, Lithic will normalize the score by multiplying the raw score by 10x. + * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the trailing 15 + * minutes before the authorization. + * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the trailing + * hour up and until the authorization. + * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the trailing 24 + * hours up and until the authorization. + * * `CARD_STATE`: The current state of the card associated with the transaction. Valid + * values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. + * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. Valid values + * are `TRUE`, `FALSE`. + * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, `OK`, + * `BLOCKED`. + * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the source of + * the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, `SAMSUNG_PAY`, `MASTERPASS`, + * `MERCHANT`, `OTHER`, `NONE`. + * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction indicates the source + * of the token. Valid values are `CARDHOLDER`, `MERCHANT`, `UNKNOWN`. + * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address data with + * the cardholder KYC data if it exists. Valid values are `MATCH`, `MATCH_ADDRESS_ONLY`, + * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. + */ + class Attribute @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MCC = of("MCC") + + @JvmField val COUNTRY = of("COUNTRY") + + @JvmField val CURRENCY = of("CURRENCY") + + @JvmField val MERCHANT_ID = of("MERCHANT_ID") + + @JvmField val DESCRIPTOR = of("DESCRIPTOR") + + @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") + + @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") + + @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") + + @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") + + @JvmField val RISK_SCORE = of("RISK_SCORE") + + @JvmField val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") + + @JvmField val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") + + @JvmField val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") + + @JvmField val CARD_STATE = of("CARD_STATE") + + @JvmField val PIN_ENTERED = of("PIN_ENTERED") + + @JvmField val PIN_STATUS = of("PIN_STATUS") + + @JvmField val WALLET_TYPE = of("WALLET_TYPE") + + @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") + + @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") + + @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) + } + + /** An enum containing [Attribute]'s known values. */ + enum class Known { + MCC, + COUNTRY, + CURRENCY, + MERCHANT_ID, + DESCRIPTOR, + LIABILITY_SHIFT, + PAN_ENTRY_MODE, + TRANSACTION_AMOUNT, + CASH_AMOUNT, + RISK_SCORE, + CARD_TRANSACTION_COUNT_15_M, + CARD_TRANSACTION_COUNT_1_H, + CARD_TRANSACTION_COUNT_24_H, + CARD_STATE, + PIN_ENTERED, + PIN_STATUS, + WALLET_TYPE, + TRANSACTION_INITIATOR, + ADDRESS_MATCH, + } + + /** + * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Attribute] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MCC, + COUNTRY, + CURRENCY, + MERCHANT_ID, + DESCRIPTOR, + LIABILITY_SHIFT, + PAN_ENTRY_MODE, + TRANSACTION_AMOUNT, + CASH_AMOUNT, + RISK_SCORE, + CARD_TRANSACTION_COUNT_15_M, + CARD_TRANSACTION_COUNT_1_H, + CARD_TRANSACTION_COUNT_24_H, + CARD_STATE, + PIN_ENTERED, + PIN_STATUS, + WALLET_TYPE, + TRANSACTION_INITIATOR, + ADDRESS_MATCH, + /** + * An enum member indicating that [Attribute] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MCC -> Value.MCC + COUNTRY -> Value.COUNTRY + CURRENCY -> Value.CURRENCY + MERCHANT_ID -> Value.MERCHANT_ID + DESCRIPTOR -> Value.DESCRIPTOR + LIABILITY_SHIFT -> Value.LIABILITY_SHIFT + PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE + TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT + CASH_AMOUNT -> Value.CASH_AMOUNT + RISK_SCORE -> Value.RISK_SCORE + CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M + CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H + CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H + CARD_STATE -> Value.CARD_STATE + PIN_ENTERED -> Value.PIN_ENTERED + PIN_STATUS -> Value.PIN_STATUS + WALLET_TYPE -> Value.WALLET_TYPE + TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR + ADDRESS_MATCH -> Value.ADDRESS_MATCH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MCC -> Known.MCC + COUNTRY -> Known.COUNTRY + CURRENCY -> Known.CURRENCY + MERCHANT_ID -> Known.MERCHANT_ID + DESCRIPTOR -> Known.DESCRIPTOR + LIABILITY_SHIFT -> Known.LIABILITY_SHIFT + PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE + TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT + CASH_AMOUNT -> Known.CASH_AMOUNT + RISK_SCORE -> Known.RISK_SCORE + CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M + CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H + CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H + CARD_STATE -> Known.CARD_STATE + PIN_ENTERED -> Known.PIN_ENTERED + PIN_STATUS -> Known.PIN_STATUS + WALLET_TYPE -> Known.WALLET_TYPE + TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR + ADDRESS_MATCH -> Known.ADDRESS_MATCH + else -> throw LithicInvalidDataException("Unknown Attribute: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Attribute = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Attribute && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The operation to apply to the attribute */ + class Operation @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val IS_ONE_OF = of("IS_ONE_OF") + + @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + + @JvmField val MATCHES = of("MATCHES") + + @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + + @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") + + @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") + + @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + + @JvmField val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") + + @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + + @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") + + @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) + } + + /** An enum containing [Operation]'s known values. */ + enum class Known { + IS_ONE_OF, + IS_NOT_ONE_OF, + MATCHES, + DOES_NOT_MATCH, + IS_EQUAL_TO, + IS_NOT_EQUAL_TO, + IS_GREATER_THAN, + IS_GREATER_THAN_OR_EQUAL_TO, + IS_LESS_THAN, + IS_LESS_THAN_OR_EQUAL_TO, + } + + /** + * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Operation] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + IS_ONE_OF, + IS_NOT_ONE_OF, + MATCHES, + DOES_NOT_MATCH, + IS_EQUAL_TO, + IS_NOT_EQUAL_TO, + IS_GREATER_THAN, + IS_GREATER_THAN_OR_EQUAL_TO, + IS_LESS_THAN, + IS_LESS_THAN_OR_EQUAL_TO, + /** + * An enum member indicating that [Operation] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + IS_ONE_OF -> Value.IS_ONE_OF + IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF + MATCHES -> Value.MATCHES + DOES_NOT_MATCH -> Value.DOES_NOT_MATCH + IS_EQUAL_TO -> Value.IS_EQUAL_TO + IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO + IS_GREATER_THAN -> Value.IS_GREATER_THAN + IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO + IS_LESS_THAN -> Value.IS_LESS_THAN + IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + IS_ONE_OF -> Known.IS_ONE_OF + IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF + MATCHES -> Known.MATCHES + DOES_NOT_MATCH -> Known.DOES_NOT_MATCH + IS_EQUAL_TO -> Known.IS_EQUAL_TO + IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO + IS_GREATER_THAN -> Known.IS_GREATER_THAN + IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO + IS_LESS_THAN -> Known.IS_LESS_THAN + IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO + else -> throw LithicInvalidDataException("Unknown Operation: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Operation = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Operation && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val regex: String? = null, + private val number: Long? = null, + private val listOfStrings: List? = null, + private val _json: JsonValue? = null, + ) { + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + fun regex(): Optional = Optional.ofNullable(regex) + + /** + * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, + * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` + */ + fun number(): Optional = Optional.ofNullable(number) + + /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ + fun listOfStrings(): Optional> = Optional.ofNullable(listOfStrings) + + fun isRegex(): Boolean = regex != null + + fun isNumber(): Boolean = number != null + + fun isListOfStrings(): Boolean = listOfStrings != null + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + fun asRegex(): String = regex.getOrThrow("regex") + + /** + * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, + * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` + */ + fun asNumber(): Long = number.getOrThrow("number") + + /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ + fun asListOfStrings(): List = listOfStrings.getOrThrow("listOfStrings") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + regex != null -> visitor.visitRegex(regex) + number != null -> visitor.visitNumber(number) + listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitRegex(regex: String) {} + + override fun visitNumber(number: Long) {} + + override fun visitListOfStrings(listOfStrings: List) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitRegex(regex: String) = 1 + + override fun visitNumber(number: Long) = 1 + + override fun visitListOfStrings(listOfStrings: List) = + listOfStrings.size + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Value && + regex == other.regex && + number == other.number && + listOfStrings == other.listOfStrings + } + + override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) + + override fun toString(): String = + when { + regex != null -> "Value{regex=$regex}" + number != null -> "Value{number=$number}" + listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + + /** + * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, + * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` + */ + @JvmStatic fun ofNumber(number: Long) = Value(number = number) + + /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ + @JvmStatic + fun ofListOfStrings(listOfStrings: List) = + Value(listOfStrings = listOfStrings.toImmutable()) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of type [T]. + */ + interface Visitor { + + /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ + fun visitRegex(regex: String): T + + /** + * A number, to be used with `IS_GREATER_THAN`, `IS_GREATER_THAN_OR_EQUAL_TO`, + * `IS_LESS_THAN`, `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` + */ + fun visitNumber(number: Long): T + + /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ + fun visitListOfStrings(listOfStrings: List): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is + * unaware of. + * + * @throws LithicInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw LithicInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(regex = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Value(listOfStrings = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible + // with all the possible variants (e.g. deserializing from object). + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the + // first completely valid match, or simply the first match if none are + // completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.regex != null -> generator.writeObject(value.regex) + value.number != null -> generator.writeObject(value.number) + value.listOfStrings != null -> generator.writeObject(value.listOfStrings) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Condition && + attribute == other.attribute && + operation == other.operation && + value == other.value && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(attribute, operation, value, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConditionalAuthorizationActionParameters && + action == other.action && + conditions == other.conditions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" +} diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Tokenization.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Tokenization.kt index c0588ad5..02cbd2ce 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Tokenization.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Tokenization.kt @@ -1236,6 +1236,9 @@ private constructor( private val token: JsonField, private val createdAt: JsonField, private val result: JsonField, + private val ruleResults: JsonField>, + private val tokenizationDeclineReasons: JsonField>, + private val tokenizationTfaReasons: JsonField>, private val type: JsonField, private val additionalProperties: MutableMap, ) { @@ -1249,8 +1252,27 @@ private constructor( @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + @JsonProperty("rule_results") + @ExcludeMissing + ruleResults: JsonField> = JsonMissing.of(), + @JsonProperty("tokenization_decline_reasons") + @ExcludeMissing + tokenizationDeclineReasons: JsonField> = + JsonMissing.of(), + @JsonProperty("tokenization_tfa_reasons") + @ExcludeMissing + tokenizationTfaReasons: JsonField> = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(token, createdAt, result, type, mutableMapOf()) + ) : this( + token, + createdAt, + result, + ruleResults, + tokenizationDeclineReasons, + tokenizationTfaReasons, + type, + mutableMapOf(), + ) /** * Globally unique identifier for a Tokenization Event @@ -1276,6 +1298,33 @@ private constructor( */ fun result(): Optional = result.getOptional("result") + /** + * Results from rules that were evaluated for this tokenization + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun ruleResults(): Optional> = + ruleResults.getOptional("rule_results") + + /** + * List of reasons why the tokenization was declined + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tokenizationDeclineReasons(): Optional> = + tokenizationDeclineReasons.getOptional("tokenization_decline_reasons") + + /** + * List of reasons why two-factor authentication was required + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tokenizationTfaReasons(): Optional> = + tokenizationTfaReasons.getOptional("tokenization_tfa_reasons") + /** * Enum representing the type of tokenization event that occurred * @@ -1309,6 +1358,37 @@ private constructor( @ExcludeMissing fun _result(): JsonField = result + /** + * Returns the raw JSON value of [ruleResults]. + * + * Unlike [ruleResults], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("rule_results") + @ExcludeMissing + fun _ruleResults(): JsonField> = ruleResults + + /** + * Returns the raw JSON value of [tokenizationDeclineReasons]. + * + * Unlike [tokenizationDeclineReasons], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tokenization_decline_reasons") + @ExcludeMissing + fun _tokenizationDeclineReasons(): JsonField> = + tokenizationDeclineReasons + + /** + * Returns the raw JSON value of [tokenizationTfaReasons]. + * + * Unlike [tokenizationTfaReasons], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("tokenization_tfa_reasons") + @ExcludeMissing + fun _tokenizationTfaReasons(): JsonField> = + tokenizationTfaReasons + /** * Returns the raw JSON value of [type]. * @@ -1340,6 +1420,12 @@ private constructor( private var token: JsonField = JsonMissing.of() private var createdAt: JsonField = JsonMissing.of() private var result: JsonField = JsonMissing.of() + private var ruleResults: JsonField>? = null + private var tokenizationDeclineReasons: + JsonField>? = + null + private var tokenizationTfaReasons: JsonField>? = + null private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -1348,6 +1434,11 @@ private constructor( token = tokenizationEvent.token createdAt = tokenizationEvent.createdAt result = tokenizationEvent.result + ruleResults = tokenizationEvent.ruleResults.map { it.toMutableList() } + tokenizationDeclineReasons = + tokenizationEvent.tokenizationDeclineReasons.map { it.toMutableList() } + tokenizationTfaReasons = + tokenizationEvent.tokenizationTfaReasons.map { it.toMutableList() } type = tokenizationEvent.type additionalProperties = tokenizationEvent.additionalProperties.toMutableMap() } @@ -1390,6 +1481,95 @@ private constructor( */ fun result(result: JsonField) = apply { this.result = result } + /** Results from rules that were evaluated for this tokenization */ + fun ruleResults(ruleResults: List) = + ruleResults(JsonField.of(ruleResults)) + + /** + * Sets [Builder.ruleResults] to an arbitrary JSON value. + * + * You should usually call [Builder.ruleResults] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun ruleResults(ruleResults: JsonField>) = apply { + this.ruleResults = ruleResults.map { it.toMutableList() } + } + + /** + * Adds a single [TokenizationRuleResult] to [ruleResults]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRuleResult(ruleResult: TokenizationRuleResult) = apply { + ruleResults = + (ruleResults ?: JsonField.of(mutableListOf())).also { + checkKnown("ruleResults", it).add(ruleResult) + } + } + + /** List of reasons why the tokenization was declined */ + fun tokenizationDeclineReasons( + tokenizationDeclineReasons: List + ) = tokenizationDeclineReasons(JsonField.of(tokenizationDeclineReasons)) + + /** + * Sets [Builder.tokenizationDeclineReasons] to an arbitrary JSON value. + * + * You should usually call [Builder.tokenizationDeclineReasons] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun tokenizationDeclineReasons( + tokenizationDeclineReasons: JsonField> + ) = apply { + this.tokenizationDeclineReasons = + tokenizationDeclineReasons.map { it.toMutableList() } + } + + /** + * Adds a single [TokenizationDeclineReason] to [tokenizationDeclineReasons]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTokenizationDeclineReason(tokenizationDeclineReason: TokenizationDeclineReason) = + apply { + tokenizationDeclineReasons = + (tokenizationDeclineReasons ?: JsonField.of(mutableListOf())).also { + checkKnown("tokenizationDeclineReasons", it) + .add(tokenizationDeclineReason) + } + } + + /** List of reasons why two-factor authentication was required */ + fun tokenizationTfaReasons(tokenizationTfaReasons: List) = + tokenizationTfaReasons(JsonField.of(tokenizationTfaReasons)) + + /** + * Sets [Builder.tokenizationTfaReasons] to an arbitrary JSON value. + * + * You should usually call [Builder.tokenizationTfaReasons] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun tokenizationTfaReasons( + tokenizationTfaReasons: JsonField> + ) = apply { + this.tokenizationTfaReasons = tokenizationTfaReasons.map { it.toMutableList() } + } + + /** + * Adds a single [TokenizationTfaReason] to [tokenizationTfaReasons]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTokenizationTfaReason(tokenizationTfaReason: TokenizationTfaReason) = apply { + tokenizationTfaReasons = + (tokenizationTfaReasons ?: JsonField.of(mutableListOf())).also { + checkKnown("tokenizationTfaReasons", it).add(tokenizationTfaReason) + } + } + /** Enum representing the type of tokenization event that occurred */ fun type(type: Type) = type(JsonField.of(type)) @@ -1431,6 +1611,9 @@ private constructor( token, createdAt, result, + (ruleResults ?: JsonMissing.of()).map { it.toImmutable() }, + (tokenizationDeclineReasons ?: JsonMissing.of()).map { it.toImmutable() }, + (tokenizationTfaReasons ?: JsonMissing.of()).map { it.toImmutable() }, type, additionalProperties.toMutableMap(), ) @@ -1446,6 +1629,9 @@ private constructor( token() createdAt() result().ifPresent { it.validate() } + ruleResults().ifPresent { it.forEach { it.validate() } } + tokenizationDeclineReasons().ifPresent { it.forEach { it.validate() } } + tokenizationTfaReasons().ifPresent { it.forEach { it.validate() } } type().ifPresent { it.validate() } validated = true } @@ -1469,6 +1655,11 @@ private constructor( (if (token.asKnown().isPresent) 1 else 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + (result.asKnown().getOrNull()?.validity() ?: 0) + + (ruleResults.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (tokenizationDeclineReasons.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + + (tokenizationTfaReasons.asKnown().getOrNull()?.sumOf { it.validity().toInt() } + ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) /** Enum representing the result of the tokenization event */ @@ -1669,6 +1860,885 @@ private constructor( override fun toString() = value.toString() } + class TokenizationRuleResult + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val authRuleToken: JsonField, + private val explanation: JsonField, + private val name: JsonField, + private val result: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("auth_rule_token") + @ExcludeMissing + authRuleToken: JsonField = JsonMissing.of(), + @JsonProperty("explanation") + @ExcludeMissing + explanation: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonField = JsonMissing.of(), + ) : this(authRuleToken, explanation, name, result, mutableMapOf()) + + /** + * The Auth Rule Token associated with the rule. If this is set to null, then the result + * was not associated with a customer-configured rule. This may happen in cases where a + * tokenization is declined or requires TFA due to a Lithic-configured security or + * compliance rule, for example. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun authRuleToken(): Optional = authRuleToken.getOptional("auth_rule_token") + + /** + * A human-readable explanation outlining the motivation for the rule's result + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun explanation(): Optional = explanation.getOptional("explanation") + + /** + * The name for the rule, if any was configured + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * The result associated with this rule + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun result(): Result = result.getRequired("result") + + /** + * Returns the raw JSON value of [authRuleToken]. + * + * Unlike [authRuleToken], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("auth_rule_token") + @ExcludeMissing + fun _authRuleToken(): JsonField = authRuleToken + + /** + * Returns the raw JSON value of [explanation]. + * + * Unlike [explanation], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("explanation") + @ExcludeMissing + fun _explanation(): JsonField = explanation + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [result]. + * + * Unlike [result], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonField = result + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [TokenizationRuleResult]. + * + * The following fields are required: + * ```java + * .authRuleToken() + * .explanation() + * .name() + * .result() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [TokenizationRuleResult]. */ + class Builder internal constructor() { + + private var authRuleToken: JsonField? = null + private var explanation: JsonField? = null + private var name: JsonField? = null + private var result: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tokenizationRuleResult: TokenizationRuleResult) = apply { + authRuleToken = tokenizationRuleResult.authRuleToken + explanation = tokenizationRuleResult.explanation + name = tokenizationRuleResult.name + result = tokenizationRuleResult.result + additionalProperties = + tokenizationRuleResult.additionalProperties.toMutableMap() + } + + /** + * The Auth Rule Token associated with the rule. If this is set to null, then the + * result was not associated with a customer-configured rule. This may happen in + * cases where a tokenization is declined or requires TFA due to a Lithic-configured + * security or compliance rule, for example. + */ + fun authRuleToken(authRuleToken: String?) = + authRuleToken(JsonField.ofNullable(authRuleToken)) + + /** Alias for calling [Builder.authRuleToken] with `authRuleToken.orElse(null)`. */ + fun authRuleToken(authRuleToken: Optional) = + authRuleToken(authRuleToken.getOrNull()) + + /** + * Sets [Builder.authRuleToken] to an arbitrary JSON value. + * + * You should usually call [Builder.authRuleToken] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun authRuleToken(authRuleToken: JsonField) = apply { + this.authRuleToken = authRuleToken + } + + /** A human-readable explanation outlining the motivation for the rule's result */ + fun explanation(explanation: String?) = + explanation(JsonField.ofNullable(explanation)) + + /** Alias for calling [Builder.explanation] with `explanation.orElse(null)`. */ + fun explanation(explanation: Optional) = + explanation(explanation.getOrNull()) + + /** + * Sets [Builder.explanation] to an arbitrary JSON value. + * + * You should usually call [Builder.explanation] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun explanation(explanation: JsonField) = apply { + this.explanation = explanation + } + + /** The name for the rule, if any was configured */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The result associated with this rule */ + fun result(result: Result) = result(JsonField.of(result)) + + /** + * Sets [Builder.result] to an arbitrary JSON value. + * + * You should usually call [Builder.result] with a well-typed [Result] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun result(result: JsonField) = apply { this.result = result } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [TokenizationRuleResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .authRuleToken() + * .explanation() + * .name() + * .result() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): TokenizationRuleResult = + TokenizationRuleResult( + checkRequired("authRuleToken", authRuleToken), + checkRequired("explanation", explanation), + checkRequired("name", name), + checkRequired("result", result), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): TokenizationRuleResult = apply { + if (validated) { + return@apply + } + + authRuleToken() + explanation() + name() + result().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (authRuleToken.asKnown().isPresent) 1 else 0) + + (if (explanation.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (result.asKnown().getOrNull()?.validity() ?: 0) + + /** The result associated with this rule */ + class Result @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val APPROVED = of("APPROVED") + + @JvmField val DECLINED = of("DECLINED") + + @JvmField val REQUIRE_TFA = of("REQUIRE_TFA") + + @JvmField val ERROR = of("ERROR") + + @JvmStatic fun of(value: String) = Result(JsonField.of(value)) + } + + /** An enum containing [Result]'s known values. */ + enum class Known { + APPROVED, + DECLINED, + REQUIRE_TFA, + ERROR, + } + + /** + * An enum containing [Result]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Result] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + APPROVED, + DECLINED, + REQUIRE_TFA, + ERROR, + /** + * An enum member indicating that [Result] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + APPROVED -> Value.APPROVED + DECLINED -> Value.DECLINED + REQUIRE_TFA -> Value.REQUIRE_TFA + ERROR -> Value.ERROR + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a + * known member. + */ + fun known(): Known = + when (this) { + APPROVED -> Known.APPROVED + DECLINED -> Known.DECLINED + REQUIRE_TFA -> Known.REQUIRE_TFA + ERROR -> Known.ERROR + else -> throw LithicInvalidDataException("Unknown Result: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Result = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Result && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TokenizationRuleResult && + authRuleToken == other.authRuleToken && + explanation == other.explanation && + name == other.name && + result == other.result && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(authRuleToken, explanation, name, result, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TokenizationRuleResult{authRuleToken=$authRuleToken, explanation=$explanation, name=$name, result=$result, additionalProperties=$additionalProperties}" + } + + /** Reason code for why a tokenization was declined */ + class TokenizationDeclineReason + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ACCOUNT_SCORE_1 = of("ACCOUNT_SCORE_1") + + @JvmField val DEVICE_SCORE_1 = of("DEVICE_SCORE_1") + + @JvmField + val ALL_WALLET_DECLINE_REASONS_PRESENT = of("ALL_WALLET_DECLINE_REASONS_PRESENT") + + @JvmField + val WALLET_RECOMMENDED_DECISION_RED = of("WALLET_RECOMMENDED_DECISION_RED") + + @JvmField val CVC_MISMATCH = of("CVC_MISMATCH") + + @JvmField val CARD_EXPIRY_MONTH_MISMATCH = of("CARD_EXPIRY_MONTH_MISMATCH") + + @JvmField val CARD_EXPIRY_YEAR_MISMATCH = of("CARD_EXPIRY_YEAR_MISMATCH") + + @JvmField val CARD_INVALID_STATE = of("CARD_INVALID_STATE") + + @JvmField val CUSTOMER_RED_PATH = of("CUSTOMER_RED_PATH") + + @JvmField val INVALID_CUSTOMER_RESPONSE = of("INVALID_CUSTOMER_RESPONSE") + + @JvmField val NETWORK_FAILURE = of("NETWORK_FAILURE") + + @JvmField val GENERIC_DECLINE = of("GENERIC_DECLINE") + + @JvmField val DIGITAL_CARD_ART_REQUIRED = of("DIGITAL_CARD_ART_REQUIRED") + + @JvmStatic fun of(value: String) = TokenizationDeclineReason(JsonField.of(value)) + } + + /** An enum containing [TokenizationDeclineReason]'s known values. */ + enum class Known { + ACCOUNT_SCORE_1, + DEVICE_SCORE_1, + ALL_WALLET_DECLINE_REASONS_PRESENT, + WALLET_RECOMMENDED_DECISION_RED, + CVC_MISMATCH, + CARD_EXPIRY_MONTH_MISMATCH, + CARD_EXPIRY_YEAR_MISMATCH, + CARD_INVALID_STATE, + CUSTOMER_RED_PATH, + INVALID_CUSTOMER_RESPONSE, + NETWORK_FAILURE, + GENERIC_DECLINE, + DIGITAL_CARD_ART_REQUIRED, + } + + /** + * An enum containing [TokenizationDeclineReason]'s known values, as well as an + * [_UNKNOWN] member. + * + * An instance of [TokenizationDeclineReason] can contain an unknown value in a couple + * of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + ACCOUNT_SCORE_1, + DEVICE_SCORE_1, + ALL_WALLET_DECLINE_REASONS_PRESENT, + WALLET_RECOMMENDED_DECISION_RED, + CVC_MISMATCH, + CARD_EXPIRY_MONTH_MISMATCH, + CARD_EXPIRY_YEAR_MISMATCH, + CARD_INVALID_STATE, + CUSTOMER_RED_PATH, + INVALID_CUSTOMER_RESPONSE, + NETWORK_FAILURE, + GENERIC_DECLINE, + DIGITAL_CARD_ART_REQUIRED, + /** + * An enum member indicating that [TokenizationDeclineReason] was instantiated with + * an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + ACCOUNT_SCORE_1 -> Value.ACCOUNT_SCORE_1 + DEVICE_SCORE_1 -> Value.DEVICE_SCORE_1 + ALL_WALLET_DECLINE_REASONS_PRESENT -> Value.ALL_WALLET_DECLINE_REASONS_PRESENT + WALLET_RECOMMENDED_DECISION_RED -> Value.WALLET_RECOMMENDED_DECISION_RED + CVC_MISMATCH -> Value.CVC_MISMATCH + CARD_EXPIRY_MONTH_MISMATCH -> Value.CARD_EXPIRY_MONTH_MISMATCH + CARD_EXPIRY_YEAR_MISMATCH -> Value.CARD_EXPIRY_YEAR_MISMATCH + CARD_INVALID_STATE -> Value.CARD_INVALID_STATE + CUSTOMER_RED_PATH -> Value.CUSTOMER_RED_PATH + INVALID_CUSTOMER_RESPONSE -> Value.INVALID_CUSTOMER_RESPONSE + NETWORK_FAILURE -> Value.NETWORK_FAILURE + GENERIC_DECLINE -> Value.GENERIC_DECLINE + DIGITAL_CARD_ART_REQUIRED -> Value.DIGITAL_CARD_ART_REQUIRED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ACCOUNT_SCORE_1 -> Known.ACCOUNT_SCORE_1 + DEVICE_SCORE_1 -> Known.DEVICE_SCORE_1 + ALL_WALLET_DECLINE_REASONS_PRESENT -> Known.ALL_WALLET_DECLINE_REASONS_PRESENT + WALLET_RECOMMENDED_DECISION_RED -> Known.WALLET_RECOMMENDED_DECISION_RED + CVC_MISMATCH -> Known.CVC_MISMATCH + CARD_EXPIRY_MONTH_MISMATCH -> Known.CARD_EXPIRY_MONTH_MISMATCH + CARD_EXPIRY_YEAR_MISMATCH -> Known.CARD_EXPIRY_YEAR_MISMATCH + CARD_INVALID_STATE -> Known.CARD_INVALID_STATE + CUSTOMER_RED_PATH -> Known.CUSTOMER_RED_PATH + INVALID_CUSTOMER_RESPONSE -> Known.INVALID_CUSTOMER_RESPONSE + NETWORK_FAILURE -> Known.NETWORK_FAILURE + GENERIC_DECLINE -> Known.GENERIC_DECLINE + DIGITAL_CARD_ART_REQUIRED -> Known.DIGITAL_CARD_ART_REQUIRED + else -> + throw LithicInvalidDataException( + "Unknown TokenizationDeclineReason: $value" + ) + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): TokenizationDeclineReason = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TokenizationDeclineReason && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Reason code for why a tokenization required two-factor authentication */ + class TokenizationTfaReason + @JsonCreator + private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val WALLET_RECOMMENDED_TFA = of("WALLET_RECOMMENDED_TFA") + + @JvmField val SUSPICIOUS_ACTIVITY = of("SUSPICIOUS_ACTIVITY") + + @JvmField val DEVICE_RECENTLY_LOST = of("DEVICE_RECENTLY_LOST") + + @JvmField val TOO_MANY_RECENT_ATTEMPTS = of("TOO_MANY_RECENT_ATTEMPTS") + + @JvmField val TOO_MANY_RECENT_TOKENS = of("TOO_MANY_RECENT_TOKENS") + + @JvmField val TOO_MANY_DIFFERENT_CARDHOLDERS = of("TOO_MANY_DIFFERENT_CARDHOLDERS") + + @JvmField val OUTSIDE_HOME_TERRITORY = of("OUTSIDE_HOME_TERRITORY") + + @JvmField val HAS_SUSPENDED_TOKENS = of("HAS_SUSPENDED_TOKENS") + + @JvmField val HIGH_RISK = of("HIGH_RISK") + + @JvmField val ACCOUNT_SCORE_LOW = of("ACCOUNT_SCORE_LOW") + + @JvmField val DEVICE_SCORE_LOW = of("DEVICE_SCORE_LOW") + + @JvmField val CARD_STATE_TFA = of("CARD_STATE_TFA") + + @JvmField val HARDCODED_TFA = of("HARDCODED_TFA") + + @JvmField val CUSTOMER_RULE_TFA = of("CUSTOMER_RULE_TFA") + + @JvmField val DEVICE_HOST_CARD_EMULATION = of("DEVICE_HOST_CARD_EMULATION") + + @JvmStatic fun of(value: String) = TokenizationTfaReason(JsonField.of(value)) + } + + /** An enum containing [TokenizationTfaReason]'s known values. */ + enum class Known { + WALLET_RECOMMENDED_TFA, + SUSPICIOUS_ACTIVITY, + DEVICE_RECENTLY_LOST, + TOO_MANY_RECENT_ATTEMPTS, + TOO_MANY_RECENT_TOKENS, + TOO_MANY_DIFFERENT_CARDHOLDERS, + OUTSIDE_HOME_TERRITORY, + HAS_SUSPENDED_TOKENS, + HIGH_RISK, + ACCOUNT_SCORE_LOW, + DEVICE_SCORE_LOW, + CARD_STATE_TFA, + HARDCODED_TFA, + CUSTOMER_RULE_TFA, + DEVICE_HOST_CARD_EMULATION, + } + + /** + * An enum containing [TokenizationTfaReason]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [TokenizationTfaReason] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + WALLET_RECOMMENDED_TFA, + SUSPICIOUS_ACTIVITY, + DEVICE_RECENTLY_LOST, + TOO_MANY_RECENT_ATTEMPTS, + TOO_MANY_RECENT_TOKENS, + TOO_MANY_DIFFERENT_CARDHOLDERS, + OUTSIDE_HOME_TERRITORY, + HAS_SUSPENDED_TOKENS, + HIGH_RISK, + ACCOUNT_SCORE_LOW, + DEVICE_SCORE_LOW, + CARD_STATE_TFA, + HARDCODED_TFA, + CUSTOMER_RULE_TFA, + DEVICE_HOST_CARD_EMULATION, + /** + * An enum member indicating that [TokenizationTfaReason] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + WALLET_RECOMMENDED_TFA -> Value.WALLET_RECOMMENDED_TFA + SUSPICIOUS_ACTIVITY -> Value.SUSPICIOUS_ACTIVITY + DEVICE_RECENTLY_LOST -> Value.DEVICE_RECENTLY_LOST + TOO_MANY_RECENT_ATTEMPTS -> Value.TOO_MANY_RECENT_ATTEMPTS + TOO_MANY_RECENT_TOKENS -> Value.TOO_MANY_RECENT_TOKENS + TOO_MANY_DIFFERENT_CARDHOLDERS -> Value.TOO_MANY_DIFFERENT_CARDHOLDERS + OUTSIDE_HOME_TERRITORY -> Value.OUTSIDE_HOME_TERRITORY + HAS_SUSPENDED_TOKENS -> Value.HAS_SUSPENDED_TOKENS + HIGH_RISK -> Value.HIGH_RISK + ACCOUNT_SCORE_LOW -> Value.ACCOUNT_SCORE_LOW + DEVICE_SCORE_LOW -> Value.DEVICE_SCORE_LOW + CARD_STATE_TFA -> Value.CARD_STATE_TFA + HARDCODED_TFA -> Value.HARDCODED_TFA + CUSTOMER_RULE_TFA -> Value.CUSTOMER_RULE_TFA + DEVICE_HOST_CARD_EMULATION -> Value.DEVICE_HOST_CARD_EMULATION + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws LithicInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + WALLET_RECOMMENDED_TFA -> Known.WALLET_RECOMMENDED_TFA + SUSPICIOUS_ACTIVITY -> Known.SUSPICIOUS_ACTIVITY + DEVICE_RECENTLY_LOST -> Known.DEVICE_RECENTLY_LOST + TOO_MANY_RECENT_ATTEMPTS -> Known.TOO_MANY_RECENT_ATTEMPTS + TOO_MANY_RECENT_TOKENS -> Known.TOO_MANY_RECENT_TOKENS + TOO_MANY_DIFFERENT_CARDHOLDERS -> Known.TOO_MANY_DIFFERENT_CARDHOLDERS + OUTSIDE_HOME_TERRITORY -> Known.OUTSIDE_HOME_TERRITORY + HAS_SUSPENDED_TOKENS -> Known.HAS_SUSPENDED_TOKENS + HIGH_RISK -> Known.HIGH_RISK + ACCOUNT_SCORE_LOW -> Known.ACCOUNT_SCORE_LOW + DEVICE_SCORE_LOW -> Known.DEVICE_SCORE_LOW + CARD_STATE_TFA -> Known.CARD_STATE_TFA + HARDCODED_TFA -> Known.HARDCODED_TFA + CUSTOMER_RULE_TFA -> Known.CUSTOMER_RULE_TFA + DEVICE_HOST_CARD_EMULATION -> Known.DEVICE_HOST_CARD_EMULATION + else -> + throw LithicInvalidDataException("Unknown TokenizationTfaReason: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws LithicInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + LithicInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): TokenizationTfaReason = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is TokenizationTfaReason && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + /** Enum representing the type of tokenization event that occurred */ class Type @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -1824,18 +2894,30 @@ private constructor( token == other.token && createdAt == other.createdAt && result == other.result && + ruleResults == other.ruleResults && + tokenizationDeclineReasons == other.tokenizationDeclineReasons && + tokenizationTfaReasons == other.tokenizationTfaReasons && type == other.type && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(token, createdAt, result, type, additionalProperties) + Objects.hash( + token, + createdAt, + result, + ruleResults, + tokenizationDeclineReasons, + tokenizationTfaReasons, + type, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "TokenizationEvent{token=$token, createdAt=$createdAt, result=$result, type=$type, additionalProperties=$additionalProperties}" + "TokenizationEvent{token=$token, createdAt=$createdAt, result=$result, ruleResults=$ruleResults, tokenizationDeclineReasons=$tokenizationDeclineReasons, tokenizationTfaReasons=$tokenizationTfaReasons, type=$type, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Transaction.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Transaction.kt index c6eab6b1..037f354e 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Transaction.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Transaction.kt @@ -2698,26 +2698,19 @@ private constructor( class CardholderAuthentication @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val threeDSVersion: JsonField, - private val acquirerExemption: JsonField, + private val authenticationMethod: JsonField, private val authenticationResult: JsonField, private val decisionMadeBy: JsonField, private val liabilityShift: JsonField, private val threeDSAuthenticationToken: JsonField, - private val verificationAttempted: JsonField, - private val verificationResult: JsonField, - private val authenticationMethod: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("3ds_version") - @ExcludeMissing - threeDSVersion: JsonField = JsonMissing.of(), - @JsonProperty("acquirer_exemption") + @JsonProperty("authentication_method") @ExcludeMissing - acquirerExemption: JsonField = JsonMissing.of(), + authenticationMethod: JsonField = JsonMissing.of(), @JsonProperty("authentication_result") @ExcludeMissing authenticationResult: JsonField = JsonMissing.of(), @@ -2730,47 +2723,23 @@ private constructor( @JsonProperty("three_ds_authentication_token") @ExcludeMissing threeDSAuthenticationToken: JsonField = JsonMissing.of(), - @JsonProperty("verification_attempted") - @ExcludeMissing - verificationAttempted: JsonField = JsonMissing.of(), - @JsonProperty("verification_result") - @ExcludeMissing - verificationResult: JsonField = JsonMissing.of(), - @JsonProperty("authentication_method") - @ExcludeMissing - authenticationMethod: JsonField = JsonMissing.of(), ) : this( - threeDSVersion, - acquirerExemption, + authenticationMethod, authenticationResult, decisionMadeBy, liabilityShift, threeDSAuthenticationToken, - verificationAttempted, - verificationResult, - authenticationMethod, mutableMapOf(), ) /** - * The 3DS version used for the authentication - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun threeDSVersion(): Optional = threeDSVersion.getOptional("3ds_version") - - /** - * Whether an acquirer exemption applied to the transaction. Not currently populated and - * will be removed in the future. + * Indicates the method used to authenticate the cardholder. * * @throws LithicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - @Deprecated("deprecated") - fun acquirerExemption(): AcquirerExemption = - acquirerExemption.getRequired("acquirer_exemption") + fun authenticationMethod(): AuthenticationMethod = + authenticationMethod.getRequired("authentication_method") /** * Indicates the outcome of the 3DS authentication process. @@ -2817,57 +2786,14 @@ private constructor( threeDSAuthenticationToken.getOptional("three_ds_authentication_token") /** - * Indicates whether a 3DS challenge flow was used, and if so, what the verification method - * was. (deprecated, use `authentication_result`) - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun verificationAttempted(): VerificationAttempted = - verificationAttempted.getRequired("verification_attempted") - - /** - * Indicates whether a transaction is considered 3DS authenticated. (deprecated, use - * `authentication_result`) - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). - */ - @Deprecated("deprecated") - fun verificationResult(): VerificationResult = - verificationResult.getRequired("verification_result") - - /** - * Indicates the method used to authenticate the cardholder. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun authenticationMethod(): Optional = - authenticationMethod.getOptional("authentication_method") - - /** - * Returns the raw JSON value of [threeDSVersion]. - * - * Unlike [threeDSVersion], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @Deprecated("deprecated") - @JsonProperty("3ds_version") - @ExcludeMissing - fun _threeDSVersion(): JsonField = threeDSVersion - - /** - * Returns the raw JSON value of [acquirerExemption]. + * Returns the raw JSON value of [authenticationMethod]. * - * Unlike [acquirerExemption], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [authenticationMethod], this method doesn't throw if the JSON field has an + * unexpected type. */ - @Deprecated("deprecated") - @JsonProperty("acquirer_exemption") + @JsonProperty("authentication_method") @ExcludeMissing - fun _acquirerExemption(): JsonField = acquirerExemption + fun _authenticationMethod(): JsonField = authenticationMethod /** * Returns the raw JSON value of [authenticationResult]. @@ -2909,38 +2835,6 @@ private constructor( @ExcludeMissing fun _threeDSAuthenticationToken(): JsonField = threeDSAuthenticationToken - /** - * Returns the raw JSON value of [verificationAttempted]. - * - * Unlike [verificationAttempted], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("verification_attempted") - @ExcludeMissing - fun _verificationAttempted(): JsonField = verificationAttempted - - /** - * Returns the raw JSON value of [verificationResult]. - * - * Unlike [verificationResult], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("verification_result") - @ExcludeMissing - fun _verificationResult(): JsonField = verificationResult - - /** - * Returns the raw JSON value of [authenticationMethod]. - * - * Unlike [authenticationMethod], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("authentication_method") - @ExcludeMissing - fun _authenticationMethod(): JsonField = authenticationMethod - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2960,14 +2854,11 @@ private constructor( * * The following fields are required: * ```java - * .threeDSVersion() - * .acquirerExemption() + * .authenticationMethod() * .authenticationResult() * .decisionMadeBy() * .liabilityShift() * .threeDSAuthenticationToken() - * .verificationAttempted() - * .verificationResult() * ``` */ @JvmStatic fun builder() = Builder() @@ -2976,72 +2867,38 @@ private constructor( /** A builder for [CardholderAuthentication]. */ class Builder internal constructor() { - private var threeDSVersion: JsonField? = null - private var acquirerExemption: JsonField? = null + private var authenticationMethod: JsonField? = null private var authenticationResult: JsonField? = null private var decisionMadeBy: JsonField? = null private var liabilityShift: JsonField? = null private var threeDSAuthenticationToken: JsonField? = null - private var verificationAttempted: JsonField? = null - private var verificationResult: JsonField? = null - private var authenticationMethod: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(cardholderAuthentication: CardholderAuthentication) = apply { - threeDSVersion = cardholderAuthentication.threeDSVersion - acquirerExemption = cardholderAuthentication.acquirerExemption + authenticationMethod = cardholderAuthentication.authenticationMethod authenticationResult = cardholderAuthentication.authenticationResult decisionMadeBy = cardholderAuthentication.decisionMadeBy liabilityShift = cardholderAuthentication.liabilityShift threeDSAuthenticationToken = cardholderAuthentication.threeDSAuthenticationToken - verificationAttempted = cardholderAuthentication.verificationAttempted - verificationResult = cardholderAuthentication.verificationResult - authenticationMethod = cardholderAuthentication.authenticationMethod additionalProperties = cardholderAuthentication.additionalProperties.toMutableMap() } - /** The 3DS version used for the authentication */ - @Deprecated("deprecated") - fun threeDSVersion(threeDSVersion: String?) = - threeDSVersion(JsonField.ofNullable(threeDSVersion)) - - /** Alias for calling [Builder.threeDSVersion] with `threeDSVersion.orElse(null)`. */ - @Deprecated("deprecated") - fun threeDSVersion(threeDSVersion: Optional) = - threeDSVersion(threeDSVersion.getOrNull()) - - /** - * Sets [Builder.threeDSVersion] to an arbitrary JSON value. - * - * You should usually call [Builder.threeDSVersion] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - @Deprecated("deprecated") - fun threeDSVersion(threeDSVersion: JsonField) = apply { - this.threeDSVersion = threeDSVersion - } - - /** - * Whether an acquirer exemption applied to the transaction. Not currently populated and - * will be removed in the future. - */ - @Deprecated("deprecated") - fun acquirerExemption(acquirerExemption: AcquirerExemption) = - acquirerExemption(JsonField.of(acquirerExemption)) + /** Indicates the method used to authenticate the cardholder. */ + fun authenticationMethod(authenticationMethod: AuthenticationMethod) = + authenticationMethod(JsonField.of(authenticationMethod)) /** - * Sets [Builder.acquirerExemption] to an arbitrary JSON value. + * Sets [Builder.authenticationMethod] to an arbitrary JSON value. * - * You should usually call [Builder.acquirerExemption] with a well-typed - * [AcquirerExemption] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. + * You should usually call [Builder.authenticationMethod] with a well-typed + * [AuthenticationMethod] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. */ - @Deprecated("deprecated") - fun acquirerExemption(acquirerExemption: JsonField) = apply { - this.acquirerExemption = acquirerExemption - } + fun authenticationMethod(authenticationMethod: JsonField) = + apply { + this.authenticationMethod = authenticationMethod + } /** Indicates the outcome of the 3DS authentication process. */ fun authenticationResult(authenticationResult: AuthenticationResult) = @@ -3125,63 +2982,6 @@ private constructor( this.threeDSAuthenticationToken = threeDSAuthenticationToken } - /** - * Indicates whether a 3DS challenge flow was used, and if so, what the verification - * method was. (deprecated, use `authentication_result`) - */ - @Deprecated("deprecated") - fun verificationAttempted(verificationAttempted: VerificationAttempted) = - verificationAttempted(JsonField.of(verificationAttempted)) - - /** - * Sets [Builder.verificationAttempted] to an arbitrary JSON value. - * - * You should usually call [Builder.verificationAttempted] with a well-typed - * [VerificationAttempted] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun verificationAttempted(verificationAttempted: JsonField) = - apply { - this.verificationAttempted = verificationAttempted - } - - /** - * Indicates whether a transaction is considered 3DS authenticated. (deprecated, use - * `authentication_result`) - */ - @Deprecated("deprecated") - fun verificationResult(verificationResult: VerificationResult) = - verificationResult(JsonField.of(verificationResult)) - - /** - * Sets [Builder.verificationResult] to an arbitrary JSON value. - * - * You should usually call [Builder.verificationResult] with a well-typed - * [VerificationResult] value instead. This method is primarily for setting the field to - * an undocumented or not yet supported value. - */ - @Deprecated("deprecated") - fun verificationResult(verificationResult: JsonField) = apply { - this.verificationResult = verificationResult - } - - /** Indicates the method used to authenticate the cardholder. */ - fun authenticationMethod(authenticationMethod: AuthenticationMethod) = - authenticationMethod(JsonField.of(authenticationMethod)) - - /** - * Sets [Builder.authenticationMethod] to an arbitrary JSON value. - * - * You should usually call [Builder.authenticationMethod] with a well-typed - * [AuthenticationMethod] value instead. This method is primarily for setting the field - * to an undocumented or not yet supported value. - */ - fun authenticationMethod(authenticationMethod: JsonField) = - apply { - this.authenticationMethod = authenticationMethod - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3208,29 +3008,22 @@ private constructor( * * The following fields are required: * ```java - * .threeDSVersion() - * .acquirerExemption() + * .authenticationMethod() * .authenticationResult() * .decisionMadeBy() * .liabilityShift() * .threeDSAuthenticationToken() - * .verificationAttempted() - * .verificationResult() * ``` * * @throws IllegalStateException if any required field is unset. */ fun build(): CardholderAuthentication = CardholderAuthentication( - checkRequired("threeDSVersion", threeDSVersion), - checkRequired("acquirerExemption", acquirerExemption), + checkRequired("authenticationMethod", authenticationMethod), checkRequired("authenticationResult", authenticationResult), checkRequired("decisionMadeBy", decisionMadeBy), checkRequired("liabilityShift", liabilityShift), checkRequired("threeDSAuthenticationToken", threeDSAuthenticationToken), - checkRequired("verificationAttempted", verificationAttempted), - checkRequired("verificationResult", verificationResult), - authenticationMethod, additionalProperties.toMutableMap(), ) } @@ -3242,15 +3035,11 @@ private constructor( return@apply } - threeDSVersion() - acquirerExemption().validate() + authenticationMethod().validate() authenticationResult().validate() decisionMadeBy().validate() liabilityShift().validate() threeDSAuthenticationToken() - verificationAttempted().validate() - verificationResult().validate() - authenticationMethod().ifPresent { it.validate() } validated = true } @@ -3270,22 +3059,14 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (threeDSVersion.asKnown().isPresent) 1 else 0) + - (acquirerExemption.asKnown().getOrNull()?.validity() ?: 0) + + (authenticationMethod.asKnown().getOrNull()?.validity() ?: 0) + (authenticationResult.asKnown().getOrNull()?.validity() ?: 0) + (decisionMadeBy.asKnown().getOrNull()?.validity() ?: 0) + (liabilityShift.asKnown().getOrNull()?.validity() ?: 0) + - (if (threeDSAuthenticationToken.asKnown().isPresent) 1 else 0) + - (verificationAttempted.asKnown().getOrNull()?.validity() ?: 0) + - (verificationResult.asKnown().getOrNull()?.validity() ?: 0) + - (authenticationMethod.asKnown().getOrNull()?.validity() ?: 0) + (if (threeDSAuthenticationToken.asKnown().isPresent) 1 else 0) - /** - * Whether an acquirer exemption applied to the transaction. Not currently populated and - * will be removed in the future. - */ - @Deprecated("deprecated") - class AcquirerExemption + /** Indicates the method used to authenticate the cardholder. */ + class AuthenticationMethod @JsonCreator private constructor(private val value: JsonField) : Enum { @@ -3301,61 +3082,39 @@ private constructor( companion object { - @JvmField - val AUTHENTICATION_OUTAGE_EXCEPTION = of("AUTHENTICATION_OUTAGE_EXCEPTION") - - @JvmField val LOW_VALUE = of("LOW_VALUE") + @JvmField val FRICTIONLESS = of("FRICTIONLESS") - @JvmField val MERCHANT_INITIATED_TRANSACTION = of("MERCHANT_INITIATED_TRANSACTION") + @JvmField val CHALLENGE = of("CHALLENGE") @JvmField val NONE = of("NONE") - @JvmField val RECURRING_PAYMENT = of("RECURRING_PAYMENT") - - @JvmField val SECURE_CORPORATE_PAYMENT = of("SECURE_CORPORATE_PAYMENT") - - @JvmField - val STRONG_CUSTOMER_AUTHENTICATION_DELEGATION = - of("STRONG_CUSTOMER_AUTHENTICATION_DELEGATION") - - @JvmField val TRANSACTION_RISK_ANALYSIS = of("TRANSACTION_RISK_ANALYSIS") - - @JvmStatic fun of(value: String) = AcquirerExemption(JsonField.of(value)) + @JvmStatic fun of(value: String) = AuthenticationMethod(JsonField.of(value)) } - /** An enum containing [AcquirerExemption]'s known values. */ + /** An enum containing [AuthenticationMethod]'s known values. */ enum class Known { - AUTHENTICATION_OUTAGE_EXCEPTION, - LOW_VALUE, - MERCHANT_INITIATED_TRANSACTION, + FRICTIONLESS, + CHALLENGE, NONE, - RECURRING_PAYMENT, - SECURE_CORPORATE_PAYMENT, - STRONG_CUSTOMER_AUTHENTICATION_DELEGATION, - TRANSACTION_RISK_ANALYSIS, } /** - * An enum containing [AcquirerExemption]'s known values, as well as an [_UNKNOWN] + * An enum containing [AuthenticationMethod]'s known values, as well as an [_UNKNOWN] * member. * - * An instance of [AcquirerExemption] can contain an unknown value in a couple of cases: + * An instance of [AuthenticationMethod] can contain an unknown value in a couple of + * cases: * - It was deserialized from data that doesn't match any known member. For example, if * the SDK is on an older version than the API, then the API may respond with new * members that the SDK is unaware of. * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - AUTHENTICATION_OUTAGE_EXCEPTION, - LOW_VALUE, - MERCHANT_INITIATED_TRANSACTION, + FRICTIONLESS, + CHALLENGE, NONE, - RECURRING_PAYMENT, - SECURE_CORPORATE_PAYMENT, - STRONG_CUSTOMER_AUTHENTICATION_DELEGATION, - TRANSACTION_RISK_ANALYSIS, /** - * An enum member indicating that [AcquirerExemption] was instantiated with an + * An enum member indicating that [AuthenticationMethod] was instantiated with an * unknown value. */ _UNKNOWN, @@ -3370,15 +3129,9 @@ private constructor( */ fun value(): Value = when (this) { - AUTHENTICATION_OUTAGE_EXCEPTION -> Value.AUTHENTICATION_OUTAGE_EXCEPTION - LOW_VALUE -> Value.LOW_VALUE - MERCHANT_INITIATED_TRANSACTION -> Value.MERCHANT_INITIATED_TRANSACTION + FRICTIONLESS -> Value.FRICTIONLESS + CHALLENGE -> Value.CHALLENGE NONE -> Value.NONE - RECURRING_PAYMENT -> Value.RECURRING_PAYMENT - SECURE_CORPORATE_PAYMENT -> Value.SECURE_CORPORATE_PAYMENT - STRONG_CUSTOMER_AUTHENTICATION_DELEGATION -> - Value.STRONG_CUSTOMER_AUTHENTICATION_DELEGATION - TRANSACTION_RISK_ANALYSIS -> Value.TRANSACTION_RISK_ANALYSIS else -> Value._UNKNOWN } @@ -3393,16 +3146,10 @@ private constructor( */ fun known(): Known = when (this) { - AUTHENTICATION_OUTAGE_EXCEPTION -> Known.AUTHENTICATION_OUTAGE_EXCEPTION - LOW_VALUE -> Known.LOW_VALUE - MERCHANT_INITIATED_TRANSACTION -> Known.MERCHANT_INITIATED_TRANSACTION + FRICTIONLESS -> Known.FRICTIONLESS + CHALLENGE -> Known.CHALLENGE NONE -> Known.NONE - RECURRING_PAYMENT -> Known.RECURRING_PAYMENT - SECURE_CORPORATE_PAYMENT -> Known.SECURE_CORPORATE_PAYMENT - STRONG_CUSTOMER_AUTHENTICATION_DELEGATION -> - Known.STRONG_CUSTOMER_AUTHENTICATION_DELEGATION - TRANSACTION_RISK_ANALYSIS -> Known.TRANSACTION_RISK_ANALYSIS - else -> throw LithicInvalidDataException("Unknown AcquirerExemption: $value") + else -> throw LithicInvalidDataException("Unknown AuthenticationMethod: $value") } /** @@ -3421,7 +3168,7 @@ private constructor( private var validated: Boolean = false - fun validate(): AcquirerExemption = apply { + fun validate(): AuthenticationMethod = apply { if (validated) { return@apply } @@ -3451,7 +3198,7 @@ private constructor( return true } - return other is AcquirerExemption && value == other.value + return other is AuthenticationMethod && value == other.value } override fun hashCode() = value.hashCode() @@ -3911,479 +3658,27 @@ private constructor( override fun toString() = value.toString() } - /** - * Indicates whether a 3DS challenge flow was used, and if so, what the verification method - * was. (deprecated, use `authentication_result`) - */ - @Deprecated("deprecated") - class VerificationAttempted - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val NONE = of("NONE") - - @JvmField val OTHER = of("OTHER") - - @JvmStatic fun of(value: String) = VerificationAttempted(JsonField.of(value)) - } - - /** An enum containing [VerificationAttempted]'s known values. */ - enum class Known { - NONE, - OTHER, - } - - /** - * An enum containing [VerificationAttempted]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [VerificationAttempted] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - NONE, - OTHER, - /** - * An enum member indicating that [VerificationAttempted] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - NONE -> Value.NONE - OTHER -> Value.OTHER - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - NONE -> Known.NONE - OTHER -> Known.OTHER - else -> - throw LithicInvalidDataException("Unknown VerificationAttempted: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): VerificationAttempted = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is VerificationAttempted && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** - * Indicates whether a transaction is considered 3DS authenticated. (deprecated, use - * `authentication_result`) - */ - @Deprecated("deprecated") - class VerificationResult - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val CANCELLED = of("CANCELLED") - - @JvmField val FAILED = of("FAILED") - - @JvmField val FRICTIONLESS = of("FRICTIONLESS") - - @JvmField val NOT_ATTEMPTED = of("NOT_ATTEMPTED") - - @JvmField val REJECTED = of("REJECTED") - - @JvmField val SUCCESS = of("SUCCESS") - - @JvmStatic fun of(value: String) = VerificationResult(JsonField.of(value)) - } - - /** An enum containing [VerificationResult]'s known values. */ - enum class Known { - CANCELLED, - FAILED, - FRICTIONLESS, - NOT_ATTEMPTED, - REJECTED, - SUCCESS, - } - - /** - * An enum containing [VerificationResult]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [VerificationResult] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - CANCELLED, - FAILED, - FRICTIONLESS, - NOT_ATTEMPTED, - REJECTED, - SUCCESS, - /** - * An enum member indicating that [VerificationResult] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - CANCELLED -> Value.CANCELLED - FAILED -> Value.FAILED - FRICTIONLESS -> Value.FRICTIONLESS - NOT_ATTEMPTED -> Value.NOT_ATTEMPTED - REJECTED -> Value.REJECTED - SUCCESS -> Value.SUCCESS - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - CANCELLED -> Known.CANCELLED - FAILED -> Known.FAILED - FRICTIONLESS -> Known.FRICTIONLESS - NOT_ATTEMPTED -> Known.NOT_ATTEMPTED - REJECTED -> Known.REJECTED - SUCCESS -> Known.SUCCESS - else -> throw LithicInvalidDataException("Unknown VerificationResult: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): VerificationResult = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is VerificationResult && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** Indicates the method used to authenticate the cardholder. */ - class AuthenticationMethod - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val FRICTIONLESS = of("FRICTIONLESS") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmField val NONE = of("NONE") - - @JvmStatic fun of(value: String) = AuthenticationMethod(JsonField.of(value)) - } - - /** An enum containing [AuthenticationMethod]'s known values. */ - enum class Known { - FRICTIONLESS, - CHALLENGE, - NONE, - } - - /** - * An enum containing [AuthenticationMethod]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [AuthenticationMethod] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - FRICTIONLESS, - CHALLENGE, - NONE, - /** - * An enum member indicating that [AuthenticationMethod] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - FRICTIONLESS -> Value.FRICTIONLESS - CHALLENGE -> Value.CHALLENGE - NONE -> Value.NONE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - FRICTIONLESS -> Known.FRICTIONLESS - CHALLENGE -> Known.CHALLENGE - NONE -> Known.NONE - else -> throw LithicInvalidDataException("Unknown AuthenticationMethod: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): AuthenticationMethod = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is AuthenticationMethod && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is CardholderAuthentication && - threeDSVersion == other.threeDSVersion && - acquirerExemption == other.acquirerExemption && - authenticationResult == other.authenticationResult && - decisionMadeBy == other.decisionMadeBy && - liabilityShift == other.liabilityShift && - threeDSAuthenticationToken == other.threeDSAuthenticationToken && - verificationAttempted == other.verificationAttempted && - verificationResult == other.verificationResult && - authenticationMethod == other.authenticationMethod && - additionalProperties == other.additionalProperties - } + return other is CardholderAuthentication && + authenticationMethod == other.authenticationMethod && + authenticationResult == other.authenticationResult && + decisionMadeBy == other.decisionMadeBy && + liabilityShift == other.liabilityShift && + threeDSAuthenticationToken == other.threeDSAuthenticationToken && + additionalProperties == other.additionalProperties + } private val hashCode: Int by lazy { Objects.hash( - threeDSVersion, - acquirerExemption, + authenticationMethod, authenticationResult, decisionMadeBy, liabilityShift, threeDSAuthenticationToken, - verificationAttempted, - verificationResult, - authenticationMethod, additionalProperties, ) } @@ -4391,7 +3686,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "CardholderAuthentication{threeDSVersion=$threeDSVersion, acquirerExemption=$acquirerExemption, authenticationResult=$authenticationResult, decisionMadeBy=$decisionMadeBy, liabilityShift=$liabilityShift, threeDSAuthenticationToken=$threeDSAuthenticationToken, verificationAttempted=$verificationAttempted, verificationResult=$verificationResult, authenticationMethod=$authenticationMethod, additionalProperties=$additionalProperties}" + "CardholderAuthentication{authenticationMethod=$authenticationMethod, authenticationResult=$authenticationResult, decisionMadeBy=$decisionMadeBy, liabilityShift=$liabilityShift, threeDSAuthenticationToken=$threeDSAuthenticationToken, additionalProperties=$additionalProperties}" } class Merchant diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2CreateResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2CreateResponse.kt index 32823721..51e02d12 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2CreateResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2CreateResponse.kt @@ -884,7 +884,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1288,1460 +1288,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2897,7 +1443,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3301,1460 +1847,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2DraftResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2DraftResponse.kt index 33af66f4..5553d2af 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2DraftResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2DraftResponse.kt @@ -883,7 +883,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1287,1460 +1287,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2896,7 +1442,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3300,1460 +1846,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ListResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ListResponse.kt index 714f142a..297af5ff 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ListResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ListResponse.kt @@ -883,7 +883,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1287,1460 +1287,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2896,7 +1442,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3300,1460 +1846,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2PromoteResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2PromoteResponse.kt index 2463f121..4fa34461 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2PromoteResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2PromoteResponse.kt @@ -884,7 +884,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1288,1460 +1288,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2897,7 +1443,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3301,1460 +1847,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponse.kt index 9be25d3a..9eb3f21f 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponse.kt @@ -225,7 +225,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val filters: JsonField, - private val period: JsonField, + private val period: JsonField, private val scope: JsonField, private val value: JsonField, private val additionalProperties: MutableMap, @@ -238,7 +238,7 @@ private constructor( filters: JsonField = JsonMissing.of(), @JsonProperty("period") @ExcludeMissing - period: JsonField = JsonMissing.of(), + period: JsonField = JsonMissing.of(), @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), @@ -257,7 +257,7 @@ private constructor( * @throws LithicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun period(): VelocityLimitParamsPeriodWindow = period.getRequired("period") + fun period(): VelocityLimitPeriod = period.getRequired("period") /** * The scope the velocity is calculated for @@ -289,7 +289,7 @@ private constructor( */ @JsonProperty("period") @ExcludeMissing - fun _period(): JsonField = period + fun _period(): JsonField = period /** * Returns the raw JSON value of [scope]. @@ -337,7 +337,7 @@ private constructor( class Builder internal constructor() { private var filters: JsonField? = null - private var period: JsonField? = null + private var period: JsonField? = null private var scope: JsonField? = null private var value: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -363,53 +363,51 @@ private constructor( fun filters(filters: JsonField) = apply { this.filters = filters } /** Velocity over the current day since 00:00 / 12 AM in Eastern Time */ - fun period(period: VelocityLimitParamsPeriodWindow) = period(JsonField.of(period)) + fun period(period: VelocityLimitPeriod) = period(JsonField.of(period)) /** * Sets [Builder.period] to an arbitrary JSON value. * - * You should usually call [Builder.period] with a well-typed - * [VelocityLimitParamsPeriodWindow] value instead. This method is primarily for setting - * the field to an undocumented or not yet supported value. + * You should usually call [Builder.period] with a well-typed [VelocityLimitPeriod] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. */ - fun period(period: JsonField) = apply { - this.period = period - } + fun period(period: JsonField) = apply { this.period = period } /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofTrailingWindowObject(trailingWindowObject)`. + * `VelocityLimitPeriod.ofTrailingWindowObject(trailingWindowObject)`. */ - fun period(trailingWindowObject: VelocityLimitParamsPeriodWindow.TrailingWindowObject) = - period(VelocityLimitParamsPeriodWindow.ofTrailingWindowObject(trailingWindowObject)) + fun period(trailingWindowObject: VelocityLimitPeriod.TrailingWindowObject) = + period(VelocityLimitPeriod.ofTrailingWindowObject(trailingWindowObject)) /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowDay(fixedWindowDay)`. + * `VelocityLimitPeriod.ofFixedWindowDay(fixedWindowDay)`. */ - fun period(fixedWindowDay: VelocityLimitParamsPeriodWindow.FixedWindowDay) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowDay(fixedWindowDay)) + fun period(fixedWindowDay: VelocityLimitPeriod.FixedWindowDay) = + period(VelocityLimitPeriod.ofFixedWindowDay(fixedWindowDay)) /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowWeek(fixedWindowWeek)`. + * `VelocityLimitPeriod.ofFixedWindowWeek(fixedWindowWeek)`. */ - fun period(fixedWindowWeek: VelocityLimitParamsPeriodWindow.FixedWindowWeek) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowWeek(fixedWindowWeek)) + fun period(fixedWindowWeek: VelocityLimitPeriod.FixedWindowWeek) = + period(VelocityLimitPeriod.ofFixedWindowWeek(fixedWindowWeek)) /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowMonth(fixedWindowMonth)`. + * `VelocityLimitPeriod.ofFixedWindowMonth(fixedWindowMonth)`. */ - fun period(fixedWindowMonth: VelocityLimitParamsPeriodWindow.FixedWindowMonth) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowMonth(fixedWindowMonth)) + fun period(fixedWindowMonth: VelocityLimitPeriod.FixedWindowMonth) = + period(VelocityLimitPeriod.ofFixedWindowMonth(fixedWindowMonth)) /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowYear(fixedWindowYear)`. + * `VelocityLimitPeriod.ofFixedWindowYear(fixedWindowYear)`. */ - fun period(fixedWindowYear: VelocityLimitParamsPeriodWindow.FixedWindowYear) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowYear(fixedWindowYear)) + fun period(fixedWindowYear: VelocityLimitPeriod.FixedWindowYear) = + period(VelocityLimitPeriod.ofFixedWindowYear(fixedWindowYear)) /** The scope the velocity is calculated for */ fun scope(scope: VelocityScope) = scope(JsonField.of(scope)) diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveResponse.kt index a373ac29..65bb1aa6 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2RetrieveResponse.kt @@ -884,7 +884,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1288,1460 +1288,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2897,7 +1443,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3301,1460 +1847,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2UpdateResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2UpdateResponse.kt index 1bca1654..971bdb5f 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2UpdateResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2UpdateResponse.kt @@ -884,7 +884,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -1288,1460 +1288,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { @@ -2897,7 +1443,7 @@ private constructor( * `Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction)`. */ fun parameters( - conditionalAuthorizationAction: Parameters.ConditionalAuthorizationActionParameters + conditionalAuthorizationAction: ConditionalAuthorizationActionParameters ) = parameters( Parameters.ofConditionalAuthorizationAction(conditionalAuthorizationAction) @@ -3301,1460 +1847,6 @@ private constructor( } } } - - class ConditionalAuthorizationActionParameters - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val action: JsonField, - private val conditions: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("action") - @ExcludeMissing - action: JsonField = JsonMissing.of(), - @JsonProperty("conditions") - @ExcludeMissing - conditions: JsonField> = JsonMissing.of(), - ) : this(action, conditions, mutableMapOf()) - - /** - * The action to take if the conditions are met. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun action(): Action = action.getRequired("action") - - /** - * @throws LithicInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). - */ - fun conditions(): List = conditions.getRequired("conditions") - - /** - * Returns the raw JSON value of [action]. - * - * Unlike [action], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action - - /** - * Returns the raw JSON value of [conditions]. - * - * Unlike [conditions], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("conditions") - @ExcludeMissing - fun _conditions(): JsonField> = conditions - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [ConditionalAuthorizationActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ConditionalAuthorizationActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditionalAuthorizationActionParameters: - ConditionalAuthorizationActionParameters - ) = apply { - action = conditionalAuthorizationActionParameters.action - conditions = - conditionalAuthorizationActionParameters.conditions.map { - it.toMutableList() - } - additionalProperties = - conditionalAuthorizationActionParameters.additionalProperties - .toMutableMap() - } - - /** The action to take if the conditions are met. */ - fun action(action: Action) = action(JsonField.of(action)) - - /** - * Sets [Builder.action] to an arbitrary JSON value. - * - * You should usually call [Builder.action] with a well-typed [Action] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun action(action: JsonField) = apply { this.action = action } - - fun conditions(conditions: List) = - conditions(JsonField.of(conditions)) - - /** - * Sets [Builder.conditions] to an arbitrary JSON value. - * - * You should usually call [Builder.conditions] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun conditions(conditions: JsonField>) = apply { - this.conditions = conditions.map { it.toMutableList() } - } - - /** - * Adds a single [Condition] to [conditions]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCondition(condition: Condition) = apply { - conditions = - (conditions ?: JsonField.of(mutableListOf())).also { - checkKnown("conditions", it).add(condition) - } - } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [ConditionalAuthorizationActionParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ConditionalAuthorizationActionParameters = - ConditionalAuthorizationActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ConditionalAuthorizationActionParameters = apply { - if (validated) { - return@apply - } - - action().validate() - conditions().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (action.asKnown().getOrNull()?.validity() ?: 0) + - (conditions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** The action to take if the conditions are met. */ - class Action - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val DECLINE = of("DECLINE") - - @JvmField val CHALLENGE = of("CHALLENGE") - - @JvmStatic fun of(value: String) = Action(JsonField.of(value)) - } - - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } - - /** - * An enum containing [Action]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Action] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DECLINE, - CHALLENGE, - /** - * An enum member indicating that [Action] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or - * if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DECLINE -> Value.DECLINE - CHALLENGE -> Value.CHALLENGE - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known - * and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a not a - * known member. - */ - fun known(): Known = - when (this) { - DECLINE -> Known.DECLINE - CHALLENGE -> Known.CHALLENGE - else -> throw LithicInvalidDataException("Unknown Action: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does not - * have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Action = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Action && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - @JsonCreator(mode = JsonCreator.Mode.DISABLED) - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("attribute") - @ExcludeMissing - attribute: JsonField = JsonMissing.of(), - @JsonProperty("operation") - @ExcludeMissing - operation: JsonField = JsonMissing.of(), - @JsonProperty("value") - @ExcludeMissing - value: JsonField = JsonMissing.of(), - ) : this(attribute, operation, value, mutableMapOf()) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun attribute(): Optional = attribute.getOptional("attribute") - - /** - * The operation to apply to the attribute - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun operation(): Optional = operation.getOptional("operation") - - /** - * A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun value(): Optional = value.getOptional("value") - - /** - * Returns the raw JSON value of [attribute]. - * - * Unlike [attribute], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("attribute") - @ExcludeMissing - fun _attribute(): JsonField = attribute - - /** - * Returns the raw JSON value of [operation]. - * - * Unlike [operation], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("operation") - @ExcludeMissing - fun _operation(): JsonField = operation - - /** - * Returns the raw JSON value of [value]. - * - * Unlike [value], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Condition]. */ - class Builder internal constructor() { - - private var attribute: JsonField = JsonMissing.of() - private var operation: JsonField = JsonMissing.of() - private var value: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(condition: Condition) = apply { - attribute = condition.attribute - operation = condition.operation - value = condition.value - additionalProperties = condition.additionalProperties.toMutableMap() - } - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to - * classify a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) - * all ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT - * for Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant - * currency of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card - * acceptor (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, - * `ICC`, `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, - * `SECURE_CARDLESS`, `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or - * `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This - * is the amount the issuer should authorize against unless the issuer is - * paying the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units - * (cents). This represents the amount of cash being withdrawn or - * advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authorization. Scores are on a range of 0-999, with 0 - * representing the lowest risk and 999 representing the highest risk. For - * Visa transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in - * the trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in - * the trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in - * the trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the - * transaction. Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are - * `NOT_SET`, `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates - * the source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's - * address data with the cardholder KYC data if it exists. Valid values - * are `MATCH`, `MATCH_ADDRESS_ONLY`, - * `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - fun attribute(attribute: Attribute) = attribute(JsonField.of(attribute)) - - /** - * Sets [Builder.attribute] to an arbitrary JSON value. - * - * You should usually call [Builder.attribute] with a well-typed [Attribute] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun attribute(attribute: JsonField) = apply { - this.attribute = attribute - } - - /** The operation to apply to the attribute */ - fun operation(operation: Operation) = operation(JsonField.of(operation)) - - /** - * Sets [Builder.operation] to an arbitrary JSON value. - * - * You should usually call [Builder.operation] with a well-typed [Operation] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun operation(operation: JsonField) = apply { - this.operation = operation - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun value(value: Value) = value(JsonField.of(value)) - - /** - * Sets [Builder.value] to an arbitrary JSON value. - * - * You should usually call [Builder.value] with a well-typed [Value] value - * instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun value(value: JsonField) = apply { this.value = value } - - /** Alias for calling [value] with `Value.ofRegex(regex)`. */ - fun value(regex: String) = value(Value.ofRegex(regex)) - - /** Alias for calling [value] with `Value.ofNumber(number)`. */ - fun value(number: Long) = value(Value.ofNumber(number)) - - /** - * Alias for calling [value] with `Value.ofListOfStrings(listOfStrings)`. - */ - fun valueOfListOfStrings(listOfStrings: List) = - value(Value.ofListOfStrings(listOfStrings)) - - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } - - /** - * Returns an immutable instance of [Condition]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Condition = - Condition( - attribute, - operation, - value, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Condition = apply { - if (validated) { - return@apply - } - - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (attribute.asKnown().getOrNull()?.validity() ?: 0) + - (operation.asKnown().getOrNull()?.validity() ?: 0) + - (value.asKnown().getOrNull()?.validity() ?: 0) - - /** - * The attribute to target. - * - * The following attributes may be targeted: - * * `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify - * a business by the types of goods or services it provides. - * * `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all - * ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for - * Netherlands Antilles. - * * `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency - * of the transaction. - * * `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor - * (merchant). - * * `DESCRIPTOR`: Short description of card acceptor. - * * `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the - * issuer applies to the transaction. Valid values are `NONE`, - * `3DS_AUTHENTICATED`, or `TOKEN_AUTHENTICATED`. - * * `PAN_ENTRY_MODE`: The method by which the cardholder's primary account - * number (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, - * `CONTACTLESS`, `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, - * `KEY_ENTERED`, `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, - * `UNSPECIFIED`, `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`. - * * `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the - * acquirer fee field in the settlement/cardholder billing currency. This is - * the amount the issuer should authorize against unless the issuer is paying - * the acquirer fee on behalf of the cardholder. - * * `CASH_AMOUNT`: The cash amount of the transaction in minor units (cents). - * This represents the amount of cash being withdrawn or advanced. - * * `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authorization. Scores are on a range of 0-999, with 0 representing - * the lowest risk and 999 representing the highest risk. For Visa - * transactions, where the raw score has a range of 0-99, Lithic will - * normalize the score by multiplying the raw score by 10x. - * * `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the - * trailing 15 minutes before the authorization. - * * `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the - * trailing hour up and until the authorization. - * * `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the - * trailing 24 hours up and until the authorization. - * * `CARD_STATE`: The current state of the card associated with the - * transaction. Valid values are `CLOSED`, `OPEN`, `PAUSED`, - * `PENDING_ACTIVATION`, `PENDING_FULFILLMENT`. - * * `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction. - * Valid values are `TRUE`, `FALSE`. - * * `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`, - * `OK`, `BLOCKED`. - * * `WALLET_TYPE`: For transactions using a digital wallet token, indicates the - * source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`, - * `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`. - * * `TRANSACTION_INITIATOR`: The entity that initiated the transaction - * indicates the source of the token. Valid values are `CARDHOLDER`, - * `MERCHANT`, `UNKNOWN`. - * * `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address - * data with the cardholder KYC data if it exists. Valid values are `MATCH`, - * `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`. - */ - class Attribute - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val MCC = of("MCC") - - @JvmField val COUNTRY = of("COUNTRY") - - @JvmField val CURRENCY = of("CURRENCY") - - @JvmField val MERCHANT_ID = of("MERCHANT_ID") - - @JvmField val DESCRIPTOR = of("DESCRIPTOR") - - @JvmField val LIABILITY_SHIFT = of("LIABILITY_SHIFT") - - @JvmField val PAN_ENTRY_MODE = of("PAN_ENTRY_MODE") - - @JvmField val TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val CASH_AMOUNT = of("CASH_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField - val CARD_TRANSACTION_COUNT_15_M = of("CARD_TRANSACTION_COUNT_15M") - - @JvmField - val CARD_TRANSACTION_COUNT_1_H = of("CARD_TRANSACTION_COUNT_1H") - - @JvmField - val CARD_TRANSACTION_COUNT_24_H = of("CARD_TRANSACTION_COUNT_24H") - - @JvmField val CARD_STATE = of("CARD_STATE") - - @JvmField val PIN_ENTERED = of("PIN_ENTERED") - - @JvmField val PIN_STATUS = of("PIN_STATUS") - - @JvmField val WALLET_TYPE = of("WALLET_TYPE") - - @JvmField val TRANSACTION_INITIATOR = of("TRANSACTION_INITIATOR") - - @JvmField val ADDRESS_MATCH = of("ADDRESS_MATCH") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } - - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - } - - /** - * An enum containing [Attribute]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Attribute] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - LIABILITY_SHIFT, - PAN_ENTRY_MODE, - TRANSACTION_AMOUNT, - CASH_AMOUNT, - RISK_SCORE, - CARD_TRANSACTION_COUNT_15_M, - CARD_TRANSACTION_COUNT_1_H, - CARD_TRANSACTION_COUNT_24_H, - CARD_STATE, - PIN_ENTERED, - PIN_STATUS, - WALLET_TYPE, - TRANSACTION_INITIATOR, - ADDRESS_MATCH, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - LIABILITY_SHIFT -> Value.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Value.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - CASH_AMOUNT -> Value.CASH_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Value.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Value.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Value.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Value.CARD_STATE - PIN_ENTERED -> Value.PIN_ENTERED - PIN_STATUS -> Value.PIN_STATUS - WALLET_TYPE -> Value.WALLET_TYPE - TRANSACTION_INITIATOR -> Value.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Value.ADDRESS_MATCH - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - MCC -> Known.MCC - COUNTRY -> Known.COUNTRY - CURRENCY -> Known.CURRENCY - MERCHANT_ID -> Known.MERCHANT_ID - DESCRIPTOR -> Known.DESCRIPTOR - LIABILITY_SHIFT -> Known.LIABILITY_SHIFT - PAN_ENTRY_MODE -> Known.PAN_ENTRY_MODE - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - CASH_AMOUNT -> Known.CASH_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - CARD_TRANSACTION_COUNT_15_M -> Known.CARD_TRANSACTION_COUNT_15_M - CARD_TRANSACTION_COUNT_1_H -> Known.CARD_TRANSACTION_COUNT_1_H - CARD_TRANSACTION_COUNT_24_H -> Known.CARD_TRANSACTION_COUNT_24_H - CARD_STATE -> Known.CARD_STATE - PIN_ENTERED -> Known.PIN_ENTERED - PIN_STATUS -> Known.PIN_STATUS - WALLET_TYPE -> Known.WALLET_TYPE - TRANSACTION_INITIATOR -> Known.TRANSACTION_INITIATOR - ADDRESS_MATCH -> Known.ADDRESS_MATCH - else -> - throw LithicInvalidDataException("Unknown Attribute: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Attribute = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Attribute && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data - * that doesn't match any known member, and you want to know that value. For - * example, if the SDK is on an older version than the API, then the API may - * respond with new members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue - fun _value(): JsonField = value - - companion object { - - @JvmField val IS_ONE_OF = of("IS_ONE_OF") - - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") - - @JvmField val MATCHES = of("MATCHES") - - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") - - @JvmField val IS_EQUAL_TO = of("IS_EQUAL_TO") - - @JvmField val IS_NOT_EQUAL_TO = of("IS_NOT_EQUAL_TO") - - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField - val IS_GREATER_THAN_OR_EQUAL_TO = of("IS_GREATER_THAN_OR_EQUAL_TO") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @JvmField val IS_LESS_THAN_OR_EQUAL_TO = of("IS_LESS_THAN_OR_EQUAL_TO") - - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } - - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - } - - /** - * An enum containing [Operation]'s known values, as well as an [_UNKNOWN] - * member. - * - * An instance of [Operation] can contain an unknown value in a couple of - * cases: - * - It was deserialized from data that doesn't match any known member. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_EQUAL_TO, - IS_NOT_EQUAL_TO, - IS_GREATER_THAN, - IS_GREATER_THAN_OR_EQUAL_TO, - IS_LESS_THAN, - IS_LESS_THAN_OR_EQUAL_TO, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always - * known or if you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - IS_ONE_OF -> Value.IS_ONE_OF - IS_NOT_ONE_OF -> Value.IS_NOT_ONE_OF - MATCHES -> Value.MATCHES - DOES_NOT_MATCH -> Value.DOES_NOT_MATCH - IS_EQUAL_TO -> Value.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Value.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Value.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Value.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Value.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Value.IS_LESS_THAN_OR_EQUAL_TO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always - * known and don't want to throw for the unknown case. - * - * @throws LithicInvalidDataException if this class instance's value is a - * not a known member. - */ - fun known(): Known = - when (this) { - IS_ONE_OF -> Known.IS_ONE_OF - IS_NOT_ONE_OF -> Known.IS_NOT_ONE_OF - MATCHES -> Known.MATCHES - DOES_NOT_MATCH -> Known.DOES_NOT_MATCH - IS_EQUAL_TO -> Known.IS_EQUAL_TO - IS_NOT_EQUAL_TO -> Known.IS_NOT_EQUAL_TO - IS_GREATER_THAN -> Known.IS_GREATER_THAN - IS_GREATER_THAN_OR_EQUAL_TO -> Known.IS_GREATER_THAN_OR_EQUAL_TO - IS_LESS_THAN -> Known.IS_LESS_THAN - IS_LESS_THAN_OR_EQUAL_TO -> Known.IS_LESS_THAN_OR_EQUAL_TO - else -> - throw LithicInvalidDataException("Unknown Operation: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily - * for debugging and generally doesn't throw. - * - * @throws LithicInvalidDataException if this class instance's value does - * not have the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - LithicInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Operation = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Operation && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JsonDeserialize(using = Value.Deserializer::class) - @JsonSerialize(using = Value.Serializer::class) - class Value - private constructor( - private val regex: String? = null, - private val number: Long? = null, - private val listOfStrings: List? = null, - private val _json: JsonValue? = null, - ) { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun number(): Optional = Optional.ofNullable(number) - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) - - fun isRegex(): Boolean = regex != null - - fun isNumber(): Boolean = number != null - - fun isListOfStrings(): Boolean = listOfStrings != null - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun asRegex(): String = regex.getOrThrow("regex") - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun asNumber(): Long = number.getOrThrow("number") - - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - regex != null -> visitor.visitRegex(regex) - number != null -> visitor.visitNumber(number) - listOfStrings != null -> visitor.visitListOfStrings(listOfStrings) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Value = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitRegex(regex: String) {} - - override fun visitNumber(number: Long) {} - - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this - * object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - accept( - object : Visitor { - override fun visitRegex(regex: String) = 1 - - override fun visitNumber(number: Long) = 1 - - override fun visitListOfStrings(listOfStrings: List) = - listOfStrings.size - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Value && - regex == other.regex && - number == other.number && - listOfStrings == other.listOfStrings - } - - override fun hashCode(): Int = Objects.hash(regex, number, listOfStrings) - - override fun toString(): String = - when { - regex != null -> "Value{regex=$regex}" - number != null -> "Value{number=$number}" - listOfStrings != null -> "Value{listOfStrings=$listOfStrings}" - _json != null -> "Value{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Value") - } - - companion object { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings.toImmutable()) - } - - /** - * An interface that defines how to map each variant of [Value] to a value - * of type [T]. - */ - interface Visitor { - - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun visitRegex(regex: String): T - - /** - * A number, to be used with `IS_GREATER_THAN`, - * `IS_GREATER_THAN_OR_EQUAL_TO`, `IS_LESS_THAN`, - * `IS_LESS_THAN_OR_EQUAL_TO`, `IS_EQUAL_TO`, or `IS_NOT_EQUAL_TO` - */ - fun visitNumber(number: Long): T - - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun visitListOfStrings(listOfStrings: List): T - - /** - * Maps an unknown variant of [Value] to a value of type [T]. - * - * An instance of [Value] can contain an unknown variant if it was - * deserialized from data that doesn't match any known variant. For - * example, if the SDK is on an older version than the API, then the API - * may respond with new variants that the SDK is unaware of. - * - * @throws LithicInvalidDataException in the default implementation. - */ - fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown Value: $json") - } - } - - internal class Deserializer : BaseDeserializer(Value::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Value { - val json = JsonValue.fromJsonNode(node) - - val bestMatches = - sequenceOf( - tryDeserialize(node, jacksonTypeRef())?.let { - Value(regex = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef())?.let { - Value(number = it, _json = json) - }, - tryDeserialize(node, jacksonTypeRef>()) - ?.let { Value(listOfStrings = it, _json = json) }, - ) - .filterNotNull() - .allMaxBy { it.validity() } - .toList() - return when (bestMatches.size) { - // This can happen if what we're deserializing is completely - // incompatible with all the possible variants (e.g. - // deserializing from object). - 0 -> Value(_json = json) - 1 -> bestMatches.single() - // If there's more than one match with the highest validity, - // then use the first completely valid match, or simply the - // first match if none are completely valid. - else -> - bestMatches.firstOrNull { it.isValid() } - ?: bestMatches.first() - } - } - } - - internal class Serializer : BaseSerializer(Value::class) { - - override fun serialize( - value: Value, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.regex != null -> generator.writeObject(value.regex) - value.number != null -> generator.writeObject(value.number) - value.listOfStrings != null -> - generator.writeObject(value.listOfStrings) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Value") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Condition && - attribute == other.attribute && - operation == other.operation && - value == other.value && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(attribute, operation, value, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Condition{attribute=$attribute, operation=$operation, value=$value, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ConditionalAuthorizationActionParameters && - action == other.action && - conditions == other.conditions && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(action, conditions, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ConditionalAuthorizationActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParams.kt index f43b3d5d..4ec1ed19 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParams.kt @@ -24,7 +24,7 @@ class VelocityLimitParams @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val filters: JsonField, - private val period: JsonField, + private val period: JsonField, private val scope: JsonField, private val limitAmount: JsonField, private val limitCount: JsonField, @@ -38,7 +38,7 @@ private constructor( filters: JsonField = JsonMissing.of(), @JsonProperty("period") @ExcludeMissing - period: JsonField = JsonMissing.of(), + period: JsonField = JsonMissing.of(), @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), @JsonProperty("limit_amount") @ExcludeMissing @@ -58,7 +58,7 @@ private constructor( * @throws LithicInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun period(): VelocityLimitParamsPeriodWindow = period.getRequired("period") + fun period(): VelocityLimitPeriod = period.getRequired("period") /** * The scope the velocity is calculated for @@ -102,9 +102,7 @@ private constructor( * * Unlike [period], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("period") - @ExcludeMissing - fun _period(): JsonField = period + @JsonProperty("period") @ExcludeMissing fun _period(): JsonField = period /** * Returns the raw JSON value of [scope]. @@ -158,7 +156,7 @@ private constructor( class Builder internal constructor() { private var filters: JsonField? = null - private var period: JsonField? = null + private var period: JsonField? = null private var scope: JsonField? = null private var limitAmount: JsonField = JsonMissing.of() private var limitCount: JsonField = JsonMissing.of() @@ -186,53 +184,48 @@ private constructor( fun filters(filters: JsonField) = apply { this.filters = filters } /** Velocity over the current day since 00:00 / 12 AM in Eastern Time */ - fun period(period: VelocityLimitParamsPeriodWindow) = period(JsonField.of(period)) + fun period(period: VelocityLimitPeriod) = period(JsonField.of(period)) /** * Sets [Builder.period] to an arbitrary JSON value. * - * You should usually call [Builder.period] with a well-typed - * [VelocityLimitParamsPeriodWindow] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. + * You should usually call [Builder.period] with a well-typed [VelocityLimitPeriod] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun period(period: JsonField) = apply { - this.period = period - } + fun period(period: JsonField) = apply { this.period = period } /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofTrailingWindowObject(trailingWindowObject)`. + * `VelocityLimitPeriod.ofTrailingWindowObject(trailingWindowObject)`. */ - fun period(trailingWindowObject: VelocityLimitParamsPeriodWindow.TrailingWindowObject) = - period(VelocityLimitParamsPeriodWindow.ofTrailingWindowObject(trailingWindowObject)) + fun period(trailingWindowObject: VelocityLimitPeriod.TrailingWindowObject) = + period(VelocityLimitPeriod.ofTrailingWindowObject(trailingWindowObject)) /** - * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowDay(fixedWindowDay)`. + * Alias for calling [period] with `VelocityLimitPeriod.ofFixedWindowDay(fixedWindowDay)`. */ - fun period(fixedWindowDay: VelocityLimitParamsPeriodWindow.FixedWindowDay) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowDay(fixedWindowDay)) + fun period(fixedWindowDay: VelocityLimitPeriod.FixedWindowDay) = + period(VelocityLimitPeriod.ofFixedWindowDay(fixedWindowDay)) /** - * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowWeek(fixedWindowWeek)`. + * Alias for calling [period] with `VelocityLimitPeriod.ofFixedWindowWeek(fixedWindowWeek)`. */ - fun period(fixedWindowWeek: VelocityLimitParamsPeriodWindow.FixedWindowWeek) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowWeek(fixedWindowWeek)) + fun period(fixedWindowWeek: VelocityLimitPeriod.FixedWindowWeek) = + period(VelocityLimitPeriod.ofFixedWindowWeek(fixedWindowWeek)) /** * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowMonth(fixedWindowMonth)`. + * `VelocityLimitPeriod.ofFixedWindowMonth(fixedWindowMonth)`. */ - fun period(fixedWindowMonth: VelocityLimitParamsPeriodWindow.FixedWindowMonth) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowMonth(fixedWindowMonth)) + fun period(fixedWindowMonth: VelocityLimitPeriod.FixedWindowMonth) = + period(VelocityLimitPeriod.ofFixedWindowMonth(fixedWindowMonth)) /** - * Alias for calling [period] with - * `VelocityLimitParamsPeriodWindow.ofFixedWindowYear(fixedWindowYear)`. + * Alias for calling [period] with `VelocityLimitPeriod.ofFixedWindowYear(fixedWindowYear)`. */ - fun period(fixedWindowYear: VelocityLimitParamsPeriodWindow.FixedWindowYear) = - period(VelocityLimitParamsPeriodWindow.ofFixedWindowYear(fixedWindowYear)) + fun period(fixedWindowYear: VelocityLimitPeriod.FixedWindowYear) = + period(VelocityLimitPeriod.ofFixedWindowYear(fixedWindowYear)) /** The scope the velocity is calculated for */ fun scope(scope: VelocityScope) = scope(JsonField.of(scope)) diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindow.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitPeriod.kt similarity index 96% rename from lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindow.kt rename to lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitPeriod.kt index 7fa0cfab..dd37a279 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindow.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/VelocityLimitPeriod.kt @@ -30,9 +30,9 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Velocity over the current day since 00:00 / 12 AM in Eastern Time */ -@JsonDeserialize(using = VelocityLimitParamsPeriodWindow.Deserializer::class) -@JsonSerialize(using = VelocityLimitParamsPeriodWindow.Serializer::class) -class VelocityLimitParamsPeriodWindow +@JsonDeserialize(using = VelocityLimitPeriod.Deserializer::class) +@JsonSerialize(using = VelocityLimitPeriod.Serializer::class) +class VelocityLimitPeriod private constructor( private val trailingWindowObject: TrailingWindowObject? = null, private val fixedWindowDay: FixedWindowDay? = null, @@ -116,7 +116,7 @@ private constructor( private var validated: Boolean = false - fun validate(): VelocityLimitParamsPeriodWindow = apply { + fun validate(): VelocityLimitPeriod = apply { if (validated) { return@apply } @@ -188,7 +188,7 @@ private constructor( return true } - return other is VelocityLimitParamsPeriodWindow && + return other is VelocityLimitPeriod && trailingWindowObject == other.trailingWindowObject && fixedWindowDay == other.fixedWindowDay && fixedWindowWeek == other.fixedWindowWeek && @@ -208,29 +208,25 @@ private constructor( override fun toString(): String = when { trailingWindowObject != null -> - "VelocityLimitParamsPeriodWindow{trailingWindowObject=$trailingWindowObject}" - fixedWindowDay != null -> - "VelocityLimitParamsPeriodWindow{fixedWindowDay=$fixedWindowDay}" - fixedWindowWeek != null -> - "VelocityLimitParamsPeriodWindow{fixedWindowWeek=$fixedWindowWeek}" - fixedWindowMonth != null -> - "VelocityLimitParamsPeriodWindow{fixedWindowMonth=$fixedWindowMonth}" - fixedWindowYear != null -> - "VelocityLimitParamsPeriodWindow{fixedWindowYear=$fixedWindowYear}" - _json != null -> "VelocityLimitParamsPeriodWindow{_unknown=$_json}" - else -> throw IllegalStateException("Invalid VelocityLimitParamsPeriodWindow") + "VelocityLimitPeriod{trailingWindowObject=$trailingWindowObject}" + fixedWindowDay != null -> "VelocityLimitPeriod{fixedWindowDay=$fixedWindowDay}" + fixedWindowWeek != null -> "VelocityLimitPeriod{fixedWindowWeek=$fixedWindowWeek}" + fixedWindowMonth != null -> "VelocityLimitPeriod{fixedWindowMonth=$fixedWindowMonth}" + fixedWindowYear != null -> "VelocityLimitPeriod{fixedWindowYear=$fixedWindowYear}" + _json != null -> "VelocityLimitPeriod{_unknown=$_json}" + else -> throw IllegalStateException("Invalid VelocityLimitPeriod") } companion object { @JvmStatic fun ofTrailingWindowObject(trailingWindowObject: TrailingWindowObject) = - VelocityLimitParamsPeriodWindow(trailingWindowObject = trailingWindowObject) + VelocityLimitPeriod(trailingWindowObject = trailingWindowObject) /** Velocity over the current day since 00:00 / 12 AM in Eastern Time */ @JvmStatic fun ofFixedWindowDay(fixedWindowDay: FixedWindowDay) = - VelocityLimitParamsPeriodWindow(fixedWindowDay = fixedWindowDay) + VelocityLimitPeriod(fixedWindowDay = fixedWindowDay) /** * Velocity over the current week since 00:00 / 12 AM in Eastern Time on specified @@ -238,7 +234,7 @@ private constructor( */ @JvmStatic fun ofFixedWindowWeek(fixedWindowWeek: FixedWindowWeek) = - VelocityLimitParamsPeriodWindow(fixedWindowWeek = fixedWindowWeek) + VelocityLimitPeriod(fixedWindowWeek = fixedWindowWeek) /** * Velocity over the current month since 00:00 / 12 AM in Eastern Time on specified @@ -246,7 +242,7 @@ private constructor( */ @JvmStatic fun ofFixedWindowMonth(fixedWindowMonth: FixedWindowMonth) = - VelocityLimitParamsPeriodWindow(fixedWindowMonth = fixedWindowMonth) + VelocityLimitPeriod(fixedWindowMonth = fixedWindowMonth) /** * Velocity over the current year since 00:00 / 12 AM in Eastern Time on specified `month` @@ -256,12 +252,12 @@ private constructor( */ @JvmStatic fun ofFixedWindowYear(fixedWindowYear: FixedWindowYear) = - VelocityLimitParamsPeriodWindow(fixedWindowYear = fixedWindowYear) + VelocityLimitPeriod(fixedWindowYear = fixedWindowYear) } /** - * An interface that defines how to map each variant of [VelocityLimitParamsPeriodWindow] to a - * value of type [T]. + * An interface that defines how to map each variant of [VelocityLimitPeriod] to a value of type + * [T]. */ interface Visitor { @@ -291,9 +287,9 @@ private constructor( fun visitFixedWindowYear(fixedWindowYear: FixedWindowYear): T /** - * Maps an unknown variant of [VelocityLimitParamsPeriodWindow] to a value of type [T]. + * Maps an unknown variant of [VelocityLimitPeriod] to a value of type [T]. * - * An instance of [VelocityLimitParamsPeriodWindow] can contain an unknown variant if it was + * An instance of [VelocityLimitPeriod] can contain an unknown variant if it was * deserialized from data that doesn't match any known variant. For example, if the SDK is * on an older version than the API, then the API may respond with new variants that the SDK * is unaware of. @@ -301,32 +297,32 @@ private constructor( * @throws LithicInvalidDataException in the default implementation. */ fun unknown(json: JsonValue?): T { - throw LithicInvalidDataException("Unknown VelocityLimitParamsPeriodWindow: $json") + throw LithicInvalidDataException("Unknown VelocityLimitPeriod: $json") } } internal class Deserializer : - BaseDeserializer(VelocityLimitParamsPeriodWindow::class) { + BaseDeserializer(VelocityLimitPeriod::class) { - override fun ObjectCodec.deserialize(node: JsonNode): VelocityLimitParamsPeriodWindow { + override fun ObjectCodec.deserialize(node: JsonNode): VelocityLimitPeriod { val json = JsonValue.fromJsonNode(node) val bestMatches = sequenceOf( tryDeserialize(node, jacksonTypeRef())?.let { - VelocityLimitParamsPeriodWindow(trailingWindowObject = it, _json = json) + VelocityLimitPeriod(trailingWindowObject = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { - VelocityLimitParamsPeriodWindow(fixedWindowDay = it, _json = json) + VelocityLimitPeriod(fixedWindowDay = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { - VelocityLimitParamsPeriodWindow(fixedWindowWeek = it, _json = json) + VelocityLimitPeriod(fixedWindowWeek = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { - VelocityLimitParamsPeriodWindow(fixedWindowMonth = it, _json = json) + VelocityLimitPeriod(fixedWindowMonth = it, _json = json) }, tryDeserialize(node, jacksonTypeRef())?.let { - VelocityLimitParamsPeriodWindow(fixedWindowYear = it, _json = json) + VelocityLimitPeriod(fixedWindowYear = it, _json = json) }, ) .filterNotNull() @@ -335,7 +331,7 @@ private constructor( return when (bestMatches.size) { // This can happen if what we're deserializing is completely incompatible with all // the possible variants (e.g. deserializing from boolean). - 0 -> VelocityLimitParamsPeriodWindow(_json = json) + 0 -> VelocityLimitPeriod(_json = json) 1 -> bestMatches.single() // If there's more than one match with the highest validity, then use the first // completely valid match, or simply the first match if none are completely valid. @@ -344,11 +340,10 @@ private constructor( } } - internal class Serializer : - BaseSerializer(VelocityLimitParamsPeriodWindow::class) { + internal class Serializer : BaseSerializer(VelocityLimitPeriod::class) { override fun serialize( - value: VelocityLimitParamsPeriodWindow, + value: VelocityLimitPeriod, generator: JsonGenerator, provider: SerializerProvider, ) { @@ -360,7 +355,7 @@ private constructor( value.fixedWindowMonth != null -> generator.writeObject(value.fixedWindowMonth) value.fixedWindowYear != null -> generator.writeObject(value.fixedWindowYear) value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid VelocityLimitParamsPeriodWindow") + else -> throw IllegalStateException("Invalid VelocityLimitPeriod") } } } diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityListResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityListResponseTest.kt index 97237392..edeb0376 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityListResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityListResponseTest.kt @@ -281,9 +281,8 @@ internal class AccountActivityListResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -295,15 +294,6 @@ internal class AccountActivityListResponseTest { Transaction.CardholderAuthentication.LiabilityShift._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -528,9 +518,9 @@ internal class AccountActivityListResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod + .FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -543,16 +533,6 @@ internal class AccountActivityListResponseTest { ._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod - .FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityRetrieveTransactionResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityRetrieveTransactionResponseTest.kt index bb9c51e6..48a8736b 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityRetrieveTransactionResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AccountActivityRetrieveTransactionResponseTest.kt @@ -316,9 +316,8 @@ internal class AccountActivityRetrieveTransactionResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -330,15 +329,6 @@ internal class AccountActivityRetrieveTransactionResponseTest { Transaction.CardholderAuthentication.LiabilityShift._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) @@ -564,9 +554,9 @@ internal class AccountActivityRetrieveTransactionResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod + .FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -579,16 +569,6 @@ internal class AccountActivityRetrieveTransactionResponseTest { ._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod - .FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AuthRuleV2CreateParamsTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AuthRuleV2CreateParamsTest.kt index 2405a7bb..78cbbf23 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/AuthRuleV2CreateParamsTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/AuthRuleV2CreateParamsTest.kt @@ -11,14 +11,7 @@ internal class AuthRuleV2CreateParamsTest { fun create() { AuthRuleV2CreateParams.builder() .body( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() - .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .eventStream( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.EventStream - .AUTHORIZATION - ) - .name("name") + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition( @@ -31,9 +24,14 @@ internal class AuthRuleV2CreateParamsTest { .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.AuthRuleType - .CONDITIONAL_BLOCK + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType.CONDITIONAL_BLOCK ) + .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .eventStream( + AuthRuleV2CreateParams.Body.AccountLevelRule.EventStream.AUTHORIZATION + ) + .name("name") .build() ) .build() @@ -44,15 +42,7 @@ internal class AuthRuleV2CreateParamsTest { val params = AuthRuleV2CreateParams.builder() .body( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() - .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .eventStream( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .EventStream - .AUTHORIZATION - ) - .name("name") + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition( @@ -65,10 +55,15 @@ internal class AuthRuleV2CreateParamsTest { .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) + .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .eventStream( + AuthRuleV2CreateParams.Body.AccountLevelRule.EventStream.AUTHORIZATION + ) + .name("name") .build() ) .build() @@ -77,16 +72,8 @@ internal class AuthRuleV2CreateParamsTest { assertThat(body) .isEqualTo( - AuthRuleV2CreateParams.Body.ofCreateAuthRuleRequestAccountTokens( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() - .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .eventStream( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .EventStream - .AUTHORIZATION - ) - .name("name") + AuthRuleV2CreateParams.Body.ofAccountLevelRule( + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition( @@ -99,10 +86,15 @@ internal class AuthRuleV2CreateParamsTest { .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) + .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .eventStream( + AuthRuleV2CreateParams.Body.AccountLevelRule.EventStream.AUTHORIZATION + ) + .name("name") .build() ) ) @@ -113,15 +105,14 @@ internal class AuthRuleV2CreateParamsTest { val params = AuthRuleV2CreateParams.builder() .body( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition(AuthRuleCondition.builder().build()) .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) .build() @@ -132,16 +123,15 @@ internal class AuthRuleV2CreateParamsTest { assertThat(body) .isEqualTo( - AuthRuleV2CreateParams.Body.ofCreateAuthRuleRequestAccountTokens( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() + AuthRuleV2CreateParams.Body.ofAccountLevelRule( + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition(AuthRuleCondition.builder().build()) .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) .build() diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParametersTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParametersTest.kt new file mode 100644 index 00000000..dc16e4d7 --- /dev/null +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ConditionalAuthorizationActionParametersTest.kt @@ -0,0 +1,68 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.lithic.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.lithic.api.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ConditionalAuthorizationActionParametersTest { + + @Test + fun create() { + val conditionalAuthorizationActionParameters = + ConditionalAuthorizationActionParameters.builder() + .action(ConditionalAuthorizationActionParameters.Action.DECLINE) + .addCondition( + ConditionalAuthorizationActionParameters.Condition.builder() + .attribute(ConditionalAuthorizationActionParameters.Condition.Attribute.MCC) + .operation( + ConditionalAuthorizationActionParameters.Condition.Operation.IS_ONE_OF + ) + .value("string") + .build() + ) + .build() + + assertThat(conditionalAuthorizationActionParameters.action()) + .isEqualTo(ConditionalAuthorizationActionParameters.Action.DECLINE) + assertThat(conditionalAuthorizationActionParameters.conditions()) + .containsExactly( + ConditionalAuthorizationActionParameters.Condition.builder() + .attribute(ConditionalAuthorizationActionParameters.Condition.Attribute.MCC) + .operation( + ConditionalAuthorizationActionParameters.Condition.Operation.IS_ONE_OF + ) + .value("string") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val conditionalAuthorizationActionParameters = + ConditionalAuthorizationActionParameters.builder() + .action(ConditionalAuthorizationActionParameters.Action.DECLINE) + .addCondition( + ConditionalAuthorizationActionParameters.Condition.builder() + .attribute(ConditionalAuthorizationActionParameters.Condition.Attribute.MCC) + .operation( + ConditionalAuthorizationActionParameters.Condition.Operation.IS_ONE_OF + ) + .value("string") + .build() + ) + .build() + + val roundtrippedConditionalAuthorizationActionParameters = + jsonMapper.readValue( + jsonMapper.writeValueAsString(conditionalAuthorizationActionParameters), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConditionalAuthorizationActionParameters) + .isEqualTo(conditionalAuthorizationActionParameters) + } +} diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationListPageResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationListPageResponseTest.kt index cca753b0..e4b98ccd 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationListPageResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationListPageResponseTest.kt @@ -36,6 +36,26 @@ internal class TokenizationListPageResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -67,6 +87,25 @@ internal class TokenizationListPageResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -102,6 +141,26 @@ internal class TokenizationListPageResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationSimulateResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationSimulateResponseTest.kt index eb7ab473..286f353a 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationSimulateResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationSimulateResponseTest.kt @@ -36,6 +36,26 @@ internal class TokenizationSimulateResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -66,6 +86,25 @@ internal class TokenizationSimulateResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -100,6 +139,26 @@ internal class TokenizationSimulateResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationTest.kt index f945de12..bac8f19b 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationTest.kt @@ -32,6 +32,24 @@ internal class TokenizationTest { .token("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .result(Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason.ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -61,6 +79,23 @@ internal class TokenizationTest { .token("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .result(Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason.ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason.WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -90,6 +125,24 @@ internal class TokenizationTest { .token("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .result(Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason.ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationUpdateDigitalCardArtResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationUpdateDigitalCardArtResponseTest.kt index b9a6b527..df815fca 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationUpdateDigitalCardArtResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TokenizationUpdateDigitalCardArtResponseTest.kt @@ -35,6 +35,26 @@ internal class TokenizationUpdateDigitalCardArtResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -65,6 +85,25 @@ internal class TokenizationUpdateDigitalCardArtResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult.Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) @@ -99,6 +138,26 @@ internal class TokenizationUpdateDigitalCardArtResponseTest { .result( Tokenization.TokenizationEvent.TokenizationEventOutcome.APPROVED ) + .addRuleResult( + Tokenization.TokenizationEvent.TokenizationRuleResult.builder() + .authRuleToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .explanation("explanation") + .name("name") + .result( + Tokenization.TokenizationEvent.TokenizationRuleResult + .Result + .APPROVED + ) + .build() + ) + .addTokenizationDeclineReason( + Tokenization.TokenizationEvent.TokenizationDeclineReason + .ACCOUNT_SCORE_1 + ) + .addTokenizationTfaReason( + Tokenization.TokenizationEvent.TokenizationTfaReason + .WALLET_RECOMMENDED_TFA + ) .type(Tokenization.TokenizationEvent.Type.TOKENIZATION_2_FA) .build() ) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionListPageResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionListPageResponseTest.kt index 4b20f6dd..79fd48f8 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionListPageResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionListPageResponseTest.kt @@ -59,9 +59,9 @@ internal class TransactionListPageResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod + .FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult @@ -75,17 +75,6 @@ internal class TransactionListPageResponseTest { ._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult - .FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod - .FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2023-09-26T21:14:28.637Z")) @@ -319,9 +308,9 @@ internal class TransactionListPageResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod + .FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -334,16 +323,6 @@ internal class TransactionListPageResponseTest { ._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod - .FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2023-09-26T21:14:28.637Z")) @@ -572,9 +551,9 @@ internal class TransactionListPageResponseTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod + .FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult @@ -588,17 +567,6 @@ internal class TransactionListPageResponseTest { ._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult - .FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod - .FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2023-09-26T21:14:28.637Z")) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionTest.kt index 4fd22fc6..6e9f9480 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/TransactionTest.kt @@ -55,9 +55,8 @@ internal class TransactionTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -69,15 +68,6 @@ internal class TransactionTest { Transaction.CardholderAuthentication.LiabilityShift._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2023-09-26T21:14:28.637Z")) @@ -288,8 +278,9 @@ internal class TransactionTest { assertThat(transaction.cardholderAuthentication()) .contains( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption(Transaction.CardholderAuthentication.AcquirerExemption.NONE) + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS + ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS ) @@ -300,15 +291,6 @@ internal class TransactionTest { Transaction.CardholderAuthentication.LiabilityShift._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS - ) .build() ) assertThat(transaction.created()) @@ -524,9 +506,8 @@ internal class TransactionTest { .cardToken("19c22c47-7a75-43ee-9891-595419830f7e") .cardholderAuthentication( Transaction.CardholderAuthentication.builder() - .threeDSVersion("2") - .acquirerExemption( - Transaction.CardholderAuthentication.AcquirerExemption.NONE + .authenticationMethod( + Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS ) .authenticationResult( Transaction.CardholderAuthentication.AuthenticationResult.SUCCESS @@ -538,15 +519,6 @@ internal class TransactionTest { Transaction.CardholderAuthentication.LiabilityShift._3DS_AUTHENTICATED ) .threeDSAuthenticationToken("a6e372d0-b40a-43eb-b0d1-4e1aebef5875") - .verificationAttempted( - Transaction.CardholderAuthentication.VerificationAttempted.NONE - ) - .verificationResult( - Transaction.CardholderAuthentication.VerificationResult.FRICTIONLESS - ) - .authenticationMethod( - Transaction.CardholderAuthentication.AuthenticationMethod.FRICTIONLESS - ) .build() ) .created(OffsetDateTime.parse("2023-09-26T21:14:28.637Z")) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponseTest.kt index 6d94ead8..2ccca623 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/V2RetrieveFeaturesResponseTest.kt @@ -33,11 +33,9 @@ internal class V2RetrieveFeaturesResponseTest { .build() ) .period( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM - ) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) .scope(V2RetrieveFeaturesResponse.SpendFeatureState.VelocityScope.CARD) @@ -70,9 +68,9 @@ internal class V2RetrieveFeaturesResponseTest { .build() ) .period( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) .scope(V2RetrieveFeaturesResponse.SpendFeatureState.VelocityScope.CARD) @@ -110,11 +108,9 @@ internal class V2RetrieveFeaturesResponseTest { .build() ) .period( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM - ) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) .scope(V2RetrieveFeaturesResponse.SpendFeatureState.VelocityScope.CARD) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindowTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindowTest.kt deleted file mode 100644 index 5918389a..00000000 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsPeriodWindowTest.kt +++ /dev/null @@ -1,232 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.lithic.api.models - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.lithic.api.core.JsonValue -import com.lithic.api.core.jsonMapper -import com.lithic.api.errors.LithicInvalidDataException -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.EnumSource - -internal class VelocityLimitParamsPeriodWindowTest { - - @Test - fun ofTrailingWindowObject() { - val trailingWindowObject = - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() - .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) - .build() - - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofTrailingWindowObject(trailingWindowObject) - - assertThat(velocityLimitParamsPeriodWindow.trailingWindowObject()) - .contains(trailingWindowObject) - assertThat(velocityLimitParamsPeriodWindow.fixedWindowDay()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowWeek()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowMonth()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowYear()).isEmpty - } - - @Test - fun ofTrailingWindowObjectRoundtrip() { - val jsonMapper = jsonMapper() - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofTrailingWindowObject( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() - .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) - .build() - ) - - val roundtrippedVelocityLimitParamsPeriodWindow = - jsonMapper.readValue( - jsonMapper.writeValueAsString(velocityLimitParamsPeriodWindow), - jacksonTypeRef(), - ) - - assertThat(roundtrippedVelocityLimitParamsPeriodWindow) - .isEqualTo(velocityLimitParamsPeriodWindow) - } - - @Test - fun ofFixedWindowDay() { - val fixedWindowDay = - VelocityLimitParamsPeriodWindow.FixedWindowDay.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowDay.Type.DAY) - .build() - - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowDay(fixedWindowDay) - - assertThat(velocityLimitParamsPeriodWindow.trailingWindowObject()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowDay()).contains(fixedWindowDay) - assertThat(velocityLimitParamsPeriodWindow.fixedWindowWeek()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowMonth()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowYear()).isEmpty - } - - @Test - fun ofFixedWindowDayRoundtrip() { - val jsonMapper = jsonMapper() - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowDay( - VelocityLimitParamsPeriodWindow.FixedWindowDay.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowDay.Type.DAY) - .build() - ) - - val roundtrippedVelocityLimitParamsPeriodWindow = - jsonMapper.readValue( - jsonMapper.writeValueAsString(velocityLimitParamsPeriodWindow), - jacksonTypeRef(), - ) - - assertThat(roundtrippedVelocityLimitParamsPeriodWindow) - .isEqualTo(velocityLimitParamsPeriodWindow) - } - - @Test - fun ofFixedWindowWeek() { - val fixedWindowWeek = - VelocityLimitParamsPeriodWindow.FixedWindowWeek.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowWeek.Type.WEEK) - .dayOfWeek(1L) - .build() - - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowWeek(fixedWindowWeek) - - assertThat(velocityLimitParamsPeriodWindow.trailingWindowObject()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowDay()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowWeek()).contains(fixedWindowWeek) - assertThat(velocityLimitParamsPeriodWindow.fixedWindowMonth()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowYear()).isEmpty - } - - @Test - fun ofFixedWindowWeekRoundtrip() { - val jsonMapper = jsonMapper() - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowWeek( - VelocityLimitParamsPeriodWindow.FixedWindowWeek.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowWeek.Type.WEEK) - .dayOfWeek(1L) - .build() - ) - - val roundtrippedVelocityLimitParamsPeriodWindow = - jsonMapper.readValue( - jsonMapper.writeValueAsString(velocityLimitParamsPeriodWindow), - jacksonTypeRef(), - ) - - assertThat(roundtrippedVelocityLimitParamsPeriodWindow) - .isEqualTo(velocityLimitParamsPeriodWindow) - } - - @Test - fun ofFixedWindowMonth() { - val fixedWindowMonth = - VelocityLimitParamsPeriodWindow.FixedWindowMonth.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowMonth.Type.MONTH) - .dayOfMonth(1L) - .build() - - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowMonth(fixedWindowMonth) - - assertThat(velocityLimitParamsPeriodWindow.trailingWindowObject()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowDay()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowWeek()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowMonth()).contains(fixedWindowMonth) - assertThat(velocityLimitParamsPeriodWindow.fixedWindowYear()).isEmpty - } - - @Test - fun ofFixedWindowMonthRoundtrip() { - val jsonMapper = jsonMapper() - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowMonth( - VelocityLimitParamsPeriodWindow.FixedWindowMonth.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowMonth.Type.MONTH) - .dayOfMonth(1L) - .build() - ) - - val roundtrippedVelocityLimitParamsPeriodWindow = - jsonMapper.readValue( - jsonMapper.writeValueAsString(velocityLimitParamsPeriodWindow), - jacksonTypeRef(), - ) - - assertThat(roundtrippedVelocityLimitParamsPeriodWindow) - .isEqualTo(velocityLimitParamsPeriodWindow) - } - - @Test - fun ofFixedWindowYear() { - val fixedWindowYear = - VelocityLimitParamsPeriodWindow.FixedWindowYear.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowYear.Type.YEAR) - .dayOfMonth(1L) - .month(1L) - .build() - - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowYear(fixedWindowYear) - - assertThat(velocityLimitParamsPeriodWindow.trailingWindowObject()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowDay()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowWeek()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowMonth()).isEmpty - assertThat(velocityLimitParamsPeriodWindow.fixedWindowYear()).contains(fixedWindowYear) - } - - @Test - fun ofFixedWindowYearRoundtrip() { - val jsonMapper = jsonMapper() - val velocityLimitParamsPeriodWindow = - VelocityLimitParamsPeriodWindow.ofFixedWindowYear( - VelocityLimitParamsPeriodWindow.FixedWindowYear.builder() - .type(VelocityLimitParamsPeriodWindow.FixedWindowYear.Type.YEAR) - .dayOfMonth(1L) - .month(1L) - .build() - ) - - val roundtrippedVelocityLimitParamsPeriodWindow = - jsonMapper.readValue( - jsonMapper.writeValueAsString(velocityLimitParamsPeriodWindow), - jacksonTypeRef(), - ) - - assertThat(roundtrippedVelocityLimitParamsPeriodWindow) - .isEqualTo(velocityLimitParamsPeriodWindow) - } - - enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { - BOOLEAN(JsonValue.from(false)), - STRING(JsonValue.from("invalid")), - INTEGER(JsonValue.from(-1)), - FLOAT(JsonValue.from(3.14)), - ARRAY(JsonValue.from(listOf("invalid", "array"))), - } - - @ParameterizedTest - @EnumSource - fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { - val velocityLimitParamsPeriodWindow = - jsonMapper() - .convertValue(testCase.value, jacksonTypeRef()) - - val e = - assertThrows { velocityLimitParamsPeriodWindow.validate() } - assertThat(e).hasMessageStartingWith("Unknown ") - } -} diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsTest.kt index 48b1f8b5..aa7693fb 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitParamsTest.kt @@ -25,9 +25,9 @@ internal class VelocityLimitParamsTest { .build() ) .period( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) .scope(VelocityLimitParams.VelocityScope.CARD) @@ -49,10 +49,10 @@ internal class VelocityLimitParamsTest { ) assertThat(velocityLimitParams.period()) .isEqualTo( - VelocityLimitParamsPeriodWindow.ofTrailingWindowObject( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.ofTrailingWindowObject( + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) ) @@ -78,9 +78,9 @@ internal class VelocityLimitParamsTest { .build() ) .period( - VelocityLimitParamsPeriodWindow.TrailingWindowObject.builder() + VelocityLimitPeriod.TrailingWindowObject.builder() .duration(10L) - .type(VelocityLimitParamsPeriodWindow.TrailingWindowObject.Type.CUSTOM) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) .build() ) .scope(VelocityLimitParams.VelocityScope.CARD) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitPeriodTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitPeriodTest.kt new file mode 100644 index 00000000..11208754 --- /dev/null +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/VelocityLimitPeriodTest.kt @@ -0,0 +1,219 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.lithic.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.lithic.api.core.JsonValue +import com.lithic.api.core.jsonMapper +import com.lithic.api.errors.LithicInvalidDataException +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class VelocityLimitPeriodTest { + + @Test + fun ofTrailingWindowObject() { + val trailingWindowObject = + VelocityLimitPeriod.TrailingWindowObject.builder() + .duration(10L) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) + .build() + + val velocityLimitPeriod = VelocityLimitPeriod.ofTrailingWindowObject(trailingWindowObject) + + assertThat(velocityLimitPeriod.trailingWindowObject()).contains(trailingWindowObject) + assertThat(velocityLimitPeriod.fixedWindowDay()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowWeek()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowMonth()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowYear()).isEmpty + } + + @Test + fun ofTrailingWindowObjectRoundtrip() { + val jsonMapper = jsonMapper() + val velocityLimitPeriod = + VelocityLimitPeriod.ofTrailingWindowObject( + VelocityLimitPeriod.TrailingWindowObject.builder() + .duration(10L) + .type(VelocityLimitPeriod.TrailingWindowObject.Type.CUSTOM) + .build() + ) + + val roundtrippedVelocityLimitPeriod = + jsonMapper.readValue( + jsonMapper.writeValueAsString(velocityLimitPeriod), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVelocityLimitPeriod).isEqualTo(velocityLimitPeriod) + } + + @Test + fun ofFixedWindowDay() { + val fixedWindowDay = + VelocityLimitPeriod.FixedWindowDay.builder() + .type(VelocityLimitPeriod.FixedWindowDay.Type.DAY) + .build() + + val velocityLimitPeriod = VelocityLimitPeriod.ofFixedWindowDay(fixedWindowDay) + + assertThat(velocityLimitPeriod.trailingWindowObject()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowDay()).contains(fixedWindowDay) + assertThat(velocityLimitPeriod.fixedWindowWeek()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowMonth()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowYear()).isEmpty + } + + @Test + fun ofFixedWindowDayRoundtrip() { + val jsonMapper = jsonMapper() + val velocityLimitPeriod = + VelocityLimitPeriod.ofFixedWindowDay( + VelocityLimitPeriod.FixedWindowDay.builder() + .type(VelocityLimitPeriod.FixedWindowDay.Type.DAY) + .build() + ) + + val roundtrippedVelocityLimitPeriod = + jsonMapper.readValue( + jsonMapper.writeValueAsString(velocityLimitPeriod), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVelocityLimitPeriod).isEqualTo(velocityLimitPeriod) + } + + @Test + fun ofFixedWindowWeek() { + val fixedWindowWeek = + VelocityLimitPeriod.FixedWindowWeek.builder() + .type(VelocityLimitPeriod.FixedWindowWeek.Type.WEEK) + .dayOfWeek(1L) + .build() + + val velocityLimitPeriod = VelocityLimitPeriod.ofFixedWindowWeek(fixedWindowWeek) + + assertThat(velocityLimitPeriod.trailingWindowObject()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowDay()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowWeek()).contains(fixedWindowWeek) + assertThat(velocityLimitPeriod.fixedWindowMonth()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowYear()).isEmpty + } + + @Test + fun ofFixedWindowWeekRoundtrip() { + val jsonMapper = jsonMapper() + val velocityLimitPeriod = + VelocityLimitPeriod.ofFixedWindowWeek( + VelocityLimitPeriod.FixedWindowWeek.builder() + .type(VelocityLimitPeriod.FixedWindowWeek.Type.WEEK) + .dayOfWeek(1L) + .build() + ) + + val roundtrippedVelocityLimitPeriod = + jsonMapper.readValue( + jsonMapper.writeValueAsString(velocityLimitPeriod), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVelocityLimitPeriod).isEqualTo(velocityLimitPeriod) + } + + @Test + fun ofFixedWindowMonth() { + val fixedWindowMonth = + VelocityLimitPeriod.FixedWindowMonth.builder() + .type(VelocityLimitPeriod.FixedWindowMonth.Type.MONTH) + .dayOfMonth(1L) + .build() + + val velocityLimitPeriod = VelocityLimitPeriod.ofFixedWindowMonth(fixedWindowMonth) + + assertThat(velocityLimitPeriod.trailingWindowObject()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowDay()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowWeek()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowMonth()).contains(fixedWindowMonth) + assertThat(velocityLimitPeriod.fixedWindowYear()).isEmpty + } + + @Test + fun ofFixedWindowMonthRoundtrip() { + val jsonMapper = jsonMapper() + val velocityLimitPeriod = + VelocityLimitPeriod.ofFixedWindowMonth( + VelocityLimitPeriod.FixedWindowMonth.builder() + .type(VelocityLimitPeriod.FixedWindowMonth.Type.MONTH) + .dayOfMonth(1L) + .build() + ) + + val roundtrippedVelocityLimitPeriod = + jsonMapper.readValue( + jsonMapper.writeValueAsString(velocityLimitPeriod), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVelocityLimitPeriod).isEqualTo(velocityLimitPeriod) + } + + @Test + fun ofFixedWindowYear() { + val fixedWindowYear = + VelocityLimitPeriod.FixedWindowYear.builder() + .type(VelocityLimitPeriod.FixedWindowYear.Type.YEAR) + .dayOfMonth(1L) + .month(1L) + .build() + + val velocityLimitPeriod = VelocityLimitPeriod.ofFixedWindowYear(fixedWindowYear) + + assertThat(velocityLimitPeriod.trailingWindowObject()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowDay()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowWeek()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowMonth()).isEmpty + assertThat(velocityLimitPeriod.fixedWindowYear()).contains(fixedWindowYear) + } + + @Test + fun ofFixedWindowYearRoundtrip() { + val jsonMapper = jsonMapper() + val velocityLimitPeriod = + VelocityLimitPeriod.ofFixedWindowYear( + VelocityLimitPeriod.FixedWindowYear.builder() + .type(VelocityLimitPeriod.FixedWindowYear.Type.YEAR) + .dayOfMonth(1L) + .month(1L) + .build() + ) + + val roundtrippedVelocityLimitPeriod = + jsonMapper.readValue( + jsonMapper.writeValueAsString(velocityLimitPeriod), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVelocityLimitPeriod).isEqualTo(velocityLimitPeriod) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val velocityLimitPeriod = + jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { velocityLimitPeriod.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } +} diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/services/async/authRules/V2ServiceAsyncTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/services/async/authRules/V2ServiceAsyncTest.kt index 78a7eef8..dd15a389 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/services/async/authRules/V2ServiceAsyncTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/services/async/authRules/V2ServiceAsyncTest.kt @@ -32,15 +32,7 @@ internal class V2ServiceAsyncTest { v2ServiceAsync.create( AuthRuleV2CreateParams.builder() .body( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() - .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .eventStream( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .EventStream - .AUTHORIZATION - ) - .name("name") + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition( @@ -53,10 +45,16 @@ internal class V2ServiceAsyncTest { .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) + .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .eventStream( + AuthRuleV2CreateParams.Body.AccountLevelRule.EventStream + .AUTHORIZATION + ) + .name("name") .build() ) .build() diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/services/blocking/authRules/V2ServiceTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/services/blocking/authRules/V2ServiceTest.kt index e39bdd15..0bb661a3 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/services/blocking/authRules/V2ServiceTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/services/blocking/authRules/V2ServiceTest.kt @@ -32,15 +32,7 @@ internal class V2ServiceTest { v2Service.create( AuthRuleV2CreateParams.builder() .body( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens.builder() - .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .eventStream( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .EventStream - .AUTHORIZATION - ) - .name("name") + AuthRuleV2CreateParams.Body.AccountLevelRule.builder() .parameters( ConditionalBlockParameters.builder() .addCondition( @@ -53,10 +45,16 @@ internal class V2ServiceTest { .build() ) .type( - AuthRuleV2CreateParams.Body.CreateAuthRuleRequestAccountTokens - .AuthRuleType + AuthRuleV2CreateParams.Body.AccountLevelRule.AuthRuleType .CONDITIONAL_BLOCK ) + .addAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .addBusinessAccountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .eventStream( + AuthRuleV2CreateParams.Body.AccountLevelRule.EventStream + .AUTHORIZATION + ) + .name("name") .build() ) .build() From 26cec993b5d2d2ed0ee382726743d5573a942426 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 06:47:59 +0000 Subject: [PATCH 2/3] fix(client): multi-value header serialization --- .../kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt b/lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt index 859611b4..d4e9564d 100644 --- a/lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt +++ b/lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt @@ -109,19 +109,19 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC val builder = Request.Builder().url(toUrl()).method(method.name, body) headers.names().forEach { name -> - headers.values(name).forEach { builder.header(name, it) } + headers.values(name).forEach { builder.addHeader(name, it) } } if ( !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 ) { - builder.header( + builder.addHeader( "X-Stainless-Read-Timeout", Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), ) } if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { - builder.header( + builder.addHeader( "X-Stainless-Timeout", Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), ) From d379018b7c6c7e05cb36e35b81743e11d9f650bc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 06:48:24 +0000 Subject: [PATCH 3/3] release: 0.111.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 15 +++++++++++++++ README.md | 10 +++++----- build.gradle.kts | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c37434e9..2969a756 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.110.0" + ".": "0.111.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c53b935..bb9a9745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.111.0 (2025-11-13) + +Full Changelog: [v0.110.0...v0.111.0](https://github.com/lithic-com/lithic-java/compare/v0.110.0...v0.111.0) + +### Features + +* **api:** re-add rules metadata to tokenization events ([a6c8aab](https://github.com/lithic-com/lithic-java/commit/a6c8aabdecb7f8fdd1bb3c979a6d9550c3d420bb)) +* **api:** remove deprecated fields from Cardholder Authentication object ([a6c8aab](https://github.com/lithic-com/lithic-java/commit/a6c8aabdecb7f8fdd1bb3c979a6d9550c3d420bb)) + + +### Bug Fixes + +* **api:** adjust Auth Rules spec for better SDK structure ([a6c8aab](https://github.com/lithic-com/lithic-java/commit/a6c8aabdecb7f8fdd1bb3c979a6d9550c3d420bb)) +* **client:** multi-value header serialization ([26cec99](https://github.com/lithic-com/lithic-java/commit/26cec993b5d2d2ed0ee382726743d5573a942426)) + ## 0.110.0 (2025-11-10) Full Changelog: [v0.109.0...v0.110.0](https://github.com/lithic-com/lithic-java/compare/v0.109.0...v0.110.0) diff --git a/README.md b/README.md index 0f829317..286679ae 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.lithic.api/lithic-java)](https://central.sonatype.com/artifact/com.lithic.api/lithic-java/0.110.0) -[![javadoc](https://javadoc.io/badge2/com.lithic.api/lithic-java/0.110.0/javadoc.svg)](https://javadoc.io/doc/com.lithic.api/lithic-java/0.110.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.lithic.api/lithic-java)](https://central.sonatype.com/artifact/com.lithic.api/lithic-java/0.111.0) +[![javadoc](https://javadoc.io/badge2/com.lithic.api/lithic-java/0.111.0/javadoc.svg)](https://javadoc.io/doc/com.lithic.api/lithic-java/0.111.0) @@ -13,7 +13,7 @@ The Lithic Java SDK is similar to the Lithic Kotlin SDK but with minor differenc -The REST API documentation can be found on [docs.lithic.com](https://docs.lithic.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.lithic.api/lithic-java/0.110.0). +The REST API documentation can be found on [docs.lithic.com](https://docs.lithic.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.lithic.api/lithic-java/0.111.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [docs.lithic.com](https://docs.lithic ### Gradle ```kotlin -implementation("com.lithic.api:lithic-java:0.110.0") +implementation("com.lithic.api:lithic-java:0.111.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.lithic.api:lithic-java:0.110.0") com.lithic.api lithic-java - 0.110.0 + 0.111.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 816a8aa9..d50b6512 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.lithic.api" - version = "0.110.0" // x-release-please-version + version = "0.111.0" // x-release-please-version } subprojects {