diff --git a/.release-please-manifest.json b/.release-please-manifest.json index dbeb1ee3c..2292ca706 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.94.1" + ".": "0.95.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index dc05581d2..b57de73da 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 165 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-aa684ff2a2af585fe502a6e44520ddd883f5141a1113fc9dbe7830027842aa09.yml -openapi_spec_hash: b58989fdc04768fc1eb758e180c5f128 -config_hash: 1a83dceb58f6f525b19a5775018db7e8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-41b87f6139d55188993492b9c042a6bc1bc0506c166334c387072b57b6c79869.yml +openapi_spec_hash: 3327246caf3bcbd3504ce99c81062075 +config_hash: b7425db12ddcc27a89a38de7042c4fa2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f3bb4369..c5f786210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 0.95.0 (2025-07-08) + +Full Changelog: [v0.94.1...v0.95.0](https://github.com/lithic-com/lithic-java/compare/v0.94.1...v0.95.0) + +### Features + +* **api:** add models for merchant_lock_parameters and conditional_3ds_action_parameters ([b59636c](https://github.com/lithic-com/lithic-java/commit/b59636c2cb89ade70cf550def6e9725bc1b12543)) +* **api:** api update ([e2c3beb](https://github.com/lithic-com/lithic-java/commit/e2c3beb77d4ad2fe19de8b912c2ed76cb18cfc4c)) +* **api:** api update ([18b0eaf](https://github.com/lithic-com/lithic-java/commit/18b0eafd592ef69be6a1908fad502beb11a85091)) +* **api:** api update ([999bba7](https://github.com/lithic-com/lithic-java/commit/999bba7db4343cf712dffde3201210a871772007)) + + +### Bug Fixes + +* **api:** name conflict between type and account type ([17cd5ef](https://github.com/lithic-com/lithic-java/commit/17cd5ef02e671bd45043c16dc447c6ce51af65e2)) + + +### Refactors + +* **internal:** minor `ClientOptionsTest` change ([017f196](https://github.com/lithic-com/lithic-java/commit/017f196c2c6801484b43f0ee54f2f5764ed22560)) + ## 0.94.1 (2025-06-29) Full Changelog: [v0.94.0...v0.94.1](https://github.com/lithic-com/lithic-java/compare/v0.94.0...v0.94.1) diff --git a/README.md b/README.md index d98d067b5..f7901d551 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.94.1) -[![javadoc](https://javadoc.io/badge2/com.lithic.api/lithic-java/0.94.1/javadoc.svg)](https://javadoc.io/doc/com.lithic.api/lithic-java/0.94.1) +[![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.95.0) +[![javadoc](https://javadoc.io/badge2/com.lithic.api/lithic-java/0.95.0/javadoc.svg)](https://javadoc.io/doc/com.lithic.api/lithic-java/0.95.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.94.1). +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.95.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.94.1") +implementation("com.lithic.api:lithic-java:0.95.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.lithic.api:lithic-java:0.94.1") com.lithic.api lithic-java - 0.94.1 + 0.95.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 2ec19e53c..66686cd44 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.lithic.api" - version = "0.94.1" // x-release-please-version + version = "0.95.0" // x-release-please-version } subprojects { 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 33b3d1ed2..50e2c94f8 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 @@ -685,14 +685,14 @@ private constructor( /** * Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1058,1755 +1058,796 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { + /** + * The type of Auth Rule. Effectively determines the event stream during which it will + * be evaluated. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. + */ + class AuthRuleType + @JsonCreator + private constructor(private val value: JsonField) : Enum { - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) + /** + * 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 - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") + companion object { - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants + @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + @JvmField val MERCHANT_LOCK = of("MERCHANT_LOCK") - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { + @JvmField val CONDITIONAL_3DS_ACTION = of("CONDITIONAL_3DS_ACTION") - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() + @JvmStatic fun of(value: String) = AuthRuleType(JsonField.of(value)) + } - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } + /** An enum containing [AuthRuleType]'s known values. */ + enum class Known { + CONDITIONAL_BLOCK, + VELOCITY_LIMIT, + MERCHANT_LOCK, + CONDITIONAL_3DS_ACTION, + } - /** - * A list of merchant locks defining specific merchants or groups of - * merchants (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = - merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } + /** + * 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_3DS_ACTION, + /** + * An enum member indicating that [AuthRuleType] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } + /** + * 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_3DS_ACTION -> Value.CONDITIONAL_3DS_ACTION + else -> Value._UNKNOWN + } - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(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_3DS_ACTION -> Known.CONDITIONAL_3DS_ACTION + else -> throw LithicInvalidDataException("Unknown AuthRuleType: $value") + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, 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") + } - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + private var validated: Boolean = false - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun validate(): AuthRuleType = apply { + if (validated) { + return@apply + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + known() + validated = true + } - /** - * Returns an immutable instance of [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false } - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } + /** + * 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 - merchants().forEach { it.validate() } - validated = true + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + return /* spotless:off */ other is AuthRuleType && value == other.value /* spotless:on */ + } - /** - * 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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + override fun hashCode() = value.hashCode() - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and - * requires at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { + override fun toString() = value.toString() + } - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + return /* spotless:off */ other is CreateAuthRuleRequestAccountTokens && accountTokens == other.accountTokens && name == other.name && parameters == other.parameters && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } - fun toBuilder() = Builder().from(this) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(accountTokens, name, parameters, type, additionalProperties) } + /* spotless:on */ - companion object { + override fun hashCode(): Int = hashCode - /** - * Returns a mutable builder for constructing an instance of [Merchant]. - */ - @JvmStatic fun builder() = Builder() - } + override fun toString() = + "CreateAuthRuleRequestAccountTokens{accountTokens=$accountTokens, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" + } - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } + class CreateAuthRuleRequestCardTokens + private constructor( + private val cardTokens: JsonField>, + private val name: JsonField, + private val parameters: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { - this.comment = comment - } + @JsonCreator + private constructor( + @JsonProperty("card_tokens") + @ExcludeMissing + cardTokens: 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, name, parameters, type, mutableMapOf()) - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is - * typically the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = - descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } + /** + * Card tokens to which the Auth Rule applies. + * + * @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 cardTokens(): List = cardTokens.getRequired("card_tokens") - /** - * Unique alphanumeric identifier for the payment card acceptor - * (merchant). This attribute specifies the merchant entity that will be - * locked or referenced for authorization rules. - */ - fun merchantId(merchantId: String) = - merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } + /** + * 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") - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** + * 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") - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * The type of Auth Rule. Effectively determines the event stream during which it will + * be evaluated. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. + * + * @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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + /** + * Returns the raw JSON value of [cardTokens]. + * + * Unlike [cardTokens], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("card_tokens") + @ExcludeMissing + fun _cardTokens(): JsonField> = cardTokens - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + /** + * 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 - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * 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 an immutable instance of [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } + /** + * 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 - private var validated: Boolean = false + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - fun validate(): Merchant = apply { - if (validated) { - return@apply - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - comment() - descriptor() - merchantId() - validated = true - } + fun toBuilder() = Builder().from(this) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + companion object { - /** - * 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** + * Returns a mutable builder for constructing an instance of + * [CreateAuthRuleRequestCardTokens]. + * + * The following fields are required: + * ```java + * .cardTokens() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** A builder for [CreateAuthRuleRequestCardTokens]. */ + class Builder internal constructor() { + + private var cardTokens: 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() - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ + @JvmSynthetic + internal fun from( + createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens + ) = apply { + cardTokens = + createAuthRuleRequestCardTokens.cardTokens.map { it.toMutableList() } + name = createAuthRuleRequestCardTokens.name + parameters = createAuthRuleRequestCardTokens.parameters + type = createAuthRuleRequestCardTokens.type + additionalProperties = + createAuthRuleRequestCardTokens.additionalProperties.toMutableMap() + } - override fun hashCode(): Int = hashCode + /** Card tokens to which the Auth Rule applies. */ + fun cardTokens(cardTokens: List) = cardTokens(JsonField.of(cardTokens)) - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } + /** + * Sets [Builder.cardTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.cardTokens] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun cardTokens(cardTokens: JsonField>) = apply { + this.cardTokens = cardTokens.map { it.toMutableList() } + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** + * Adds a single [String] to [cardTokens]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addCardToken(cardToken: String) = apply { + cardTokens = + (cardTokens ?: JsonField.of(mutableListOf())).also { + checkKnown("cardTokens", it).add(cardToken) } + } - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** 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()) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ + /** + * 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 } - override fun hashCode(): Int = hashCode + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + /** + * 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 } - class Conditional3dsActionParameters - 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()) + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - /** - * 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") + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - /** - * @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") + /** + * Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. + */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - /** - * 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 + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * 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 + /** + * The type of Auth Rule. Effectively determines the event stream during which it + * will be evaluated. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. + */ + fun type(type: AuthRuleType) = type(JsonField.of(type)) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * 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 } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.additionalProperties.toMutableMap() - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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() } - } + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - /** - * 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 removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun additionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns an immutable instance of [CreateAuthRuleRequestCardTokens]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .cardTokens() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreateAuthRuleRequestCardTokens = + CreateAuthRuleRequestCardTokens( + checkRequired("cardTokens", cardTokens).map { it.toImmutable() }, + name, + parameters, + type, + additionalProperties.toMutableMap(), + ) + } - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + private var validated: Boolean = false - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun validate(): CreateAuthRuleRequestCardTokens = apply { + if (validated) { + return@apply + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + cardTokens() + name() + parameters().ifPresent { it.validate() } + type().ifPresent { it.validate() } + validated = true + } - /** - * Returns an immutable instance of [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - private var validated: Boolean = 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 = + (cardTokens.asKnown().getOrNull()?.size ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + /** 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 _json: JsonValue? = null, + ) { - action().validate() - conditions().forEach { it.validate() } - validated = true - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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)) - } + fun merchantLock(): Optional = + Optional.ofNullable(merchantLock) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - /** - * 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") - } + fun isConditionalBlock(): Boolean = conditionalBlock != 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 isVelocityLimitParams(): Boolean = velocityLimitParams != null - private var validated: Boolean = false + fun isMerchantLock(): Boolean = merchantLock != null - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun isConditional3dsAction(): Boolean = conditional3dsAction != null - known() - validated = true - } + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - /** - * 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 - } + fun asMerchantLock(): MerchantLockParameters = + merchantLock.getOrThrow("merchantLock") - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - override fun hashCode() = value.hashCode() + fun _json(): Optional = Optional.ofNullable(_json) - override fun toString() = value.toString() + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) } - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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() - } + private var validated: Boolean = false - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being - * processed. - */ - 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 - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** 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 + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** 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) + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } - - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - /** - * 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(), - ) } + ) + validated = true + } - private var validated: Boolean = false + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + override fun unknown(json: JsonValue?) = 0 + } + ) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] 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) { - MCC -> Value.MCC - COUNTRY -> Value.COUNTRY - CURRENCY -> Value.CURRENCY - MERCHANT_ID -> Value.MERCHANT_ID - DESCRIPTOR -> Value.DESCRIPTOR - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 - } + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun hashCode() = value.hashCode() + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - override fun toString() = value.toString() - } + companion object { - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - /** - * 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 + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - companion object { + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + @JvmStatic + fun ofConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = Parameters(conditional3dsAction = conditional3dsAction) + } - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + /** + * An interface that defines how to map each variant of [Parameters] to a value of + * type [T]. + */ + interface Visitor { - @JvmField val MATCHES = of("MATCHES") + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + /** + * 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") + } + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - else -> - throw LithicInvalidDataException( - "Unknown Operation: $value" + val bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), ) - } - - /** - * 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } + ?.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) + }, + ) + .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() = value.hashCode() + internal class Serializer : BaseSerializer(Parameters::class) { - override fun toString() = value.toString() + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") } + } + } + } - /** 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, - ) { + /** + * The type of Auth Rule. Effectively determines the event stream during which it will + * be evaluated. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. + */ + class AuthRuleType + @JsonCreator + private constructor(private val value: JsonField) : Enum { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - fun regex(): Optional = Optional.ofNullable(regex) + /** + * 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 - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun number(): Optional = Optional.ofNullable(number) + companion object { - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun listOfStrings(): Optional> = - Optional.ofNullable(listOfStrings) + @JvmField val CONDITIONAL_BLOCK = of("CONDITIONAL_BLOCK") - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - /** - * The type of Auth Rule. Effectively determines the event stream during which it will - * be evaluated. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. - */ - class AuthRuleType - @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 CONDITIONAL_BLOCK = of("CONDITIONAL_BLOCK") - - @JvmField val VELOCITY_LIMIT = of("VELOCITY_LIMIT") + @JvmField val VELOCITY_LIMIT = of("VELOCITY_LIMIT") @JvmField val MERCHANT_LOCK = of("MERCHANT_LOCK") @@ -2938,22 +1979,23 @@ private constructor( return true } - return /* spotless:off */ other is CreateAuthRuleRequestAccountTokens && accountTokens == other.accountTokens && name == other.name && parameters == other.parameters && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is CreateAuthRuleRequestCardTokens && cardTokens == other.cardTokens && name == other.name && parameters == other.parameters && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(accountTokens, name, parameters, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(cardTokens, name, parameters, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "CreateAuthRuleRequestAccountTokens{accountTokens=$accountTokens, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" + "CreateAuthRuleRequestCardTokens{cardTokens=$cardTokens, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" } - class CreateAuthRuleRequestCardTokens + class CreateAuthRuleRequestProgramLevel private constructor( - private val cardTokens: JsonField>, + private val programLevel: JsonField, + private val excludedCardTokens: JsonField>, private val name: JsonField, private val parameters: JsonField, private val type: JsonField, @@ -2962,9 +2004,12 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("card_tokens") + @JsonProperty("program_level") @ExcludeMissing - cardTokens: JsonField> = JsonMissing.of(), + programLevel: JsonField = JsonMissing.of(), + @JsonProperty("excluded_card_tokens") + @ExcludeMissing + excludedCardTokens: JsonField> = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("parameters") @ExcludeMissing @@ -2972,16 +2017,25 @@ private constructor( @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(cardTokens, name, parameters, type, mutableMapOf()) + ) : this(programLevel, excludedCardTokens, name, parameters, type, mutableMapOf()) /** - * Card tokens to which the Auth Rule applies. + * 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 cardTokens(): List = cardTokens.getRequired("card_tokens") + fun programLevel(): Boolean = programLevel.getRequired("program_level") + + /** + * Card tokens to which the Auth Rule does not apply. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun excludedCardTokens(): Optional> = + excludedCardTokens.getOptional("excluded_card_tokens") /** * Auth Rule Name @@ -3013,4777 +2067,563 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [cardTokens]. - * - * Unlike [cardTokens], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("card_tokens") - @ExcludeMissing - fun _cardTokens(): JsonField> = cardTokens - - /** - * 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 [parameters]. + * Returns the raw JSON value of [programLevel]. * - * Unlike [parameters], this method doesn't throw if the JSON field has an unexpected + * Unlike [programLevel], this method doesn't throw if the JSON field has an unexpected * type. */ - @JsonProperty("parameters") + @JsonProperty("program_level") @ExcludeMissing - fun _parameters(): JsonField = parameters + fun _programLevel(): JsonField = programLevel /** - * Returns the raw JSON value of [type]. + * Returns the raw JSON value of [excludedCardTokens]. * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [excludedCardTokens], 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) - } - - @JsonAnyGetter + @JsonProperty("excluded_card_tokens") @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CreateAuthRuleRequestCardTokens]. - * - * The following fields are required: - * ```java - * .cardTokens() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CreateAuthRuleRequestCardTokens]. */ - class Builder internal constructor() { - - private var cardTokens: 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( - createAuthRuleRequestCardTokens: CreateAuthRuleRequestCardTokens - ) = apply { - cardTokens = - createAuthRuleRequestCardTokens.cardTokens.map { it.toMutableList() } - name = createAuthRuleRequestCardTokens.name - parameters = createAuthRuleRequestCardTokens.parameters - type = createAuthRuleRequestCardTokens.type - additionalProperties = - createAuthRuleRequestCardTokens.additionalProperties.toMutableMap() - } - - /** Card tokens to which the Auth Rule applies. */ - fun cardTokens(cardTokens: List) = cardTokens(JsonField.of(cardTokens)) - - /** - * Sets [Builder.cardTokens] to an arbitrary JSON value. - * - * You should usually call [Builder.cardTokens] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun cardTokens(cardTokens: JsonField>) = apply { - this.cardTokens = cardTokens.map { it.toMutableList() } - } - - /** - * Adds a single [String] to [cardTokens]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addCardToken(cardToken: String) = apply { - cardTokens = - (cardTokens ?: JsonField.of(mutableListOf())).also { - checkKnown("cardTokens", it).add(cardToken) - } - } - - /** 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 - } - - /** - * 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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The type of Auth Rule. Effectively determines the event stream during which it - * will be evaluated. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_3DS_ACTION`: 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) - } - - 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 [CreateAuthRuleRequestCardTokens]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .cardTokens() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CreateAuthRuleRequestCardTokens = - CreateAuthRuleRequestCardTokens( - checkRequired("cardTokens", cardTokens).map { it.toImmutable() }, - name, - parameters, - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): CreateAuthRuleRequestCardTokens = apply { - if (validated) { - return@apply - } - - cardTokens() - name() - parameters().ifPresent { it.validate() } - type().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 = - (cardTokens.asKnown().getOrNull()?.size ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = - merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) - }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of - * merchants (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = - merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and - * requires at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { - this.comment = comment - } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is - * typically the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = - descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor - * (merchant). This attribute specifies the merchant entity that will be - * locked or referenced for authorization rules. - */ - fun merchantId(merchantId: String) = - merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being - * processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - /** - * The type of Auth Rule. Effectively determines the event stream during which it will - * be evaluated. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. - */ - class AuthRuleType - @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 CONDITIONAL_BLOCK = of("CONDITIONAL_BLOCK") - - @JvmField val VELOCITY_LIMIT = of("VELOCITY_LIMIT") - - @JvmField val MERCHANT_LOCK = of("MERCHANT_LOCK") - - @JvmField val CONDITIONAL_3DS_ACTION = of("CONDITIONAL_3DS_ACTION") - - @JvmStatic fun of(value: String) = AuthRuleType(JsonField.of(value)) - } - - /** An enum containing [AuthRuleType]'s known values. */ - enum class Known { - CONDITIONAL_BLOCK, - VELOCITY_LIMIT, - MERCHANT_LOCK, - CONDITIONAL_3DS_ACTION, - } - - /** - * 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_3DS_ACTION, - /** - * An enum member indicating that [AuthRuleType] 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) { - CONDITIONAL_BLOCK -> Value.CONDITIONAL_BLOCK - VELOCITY_LIMIT -> Value.VELOCITY_LIMIT - MERCHANT_LOCK -> Value.MERCHANT_LOCK - CONDITIONAL_3DS_ACTION -> Value.CONDITIONAL_3DS_ACTION - 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) { - CONDITIONAL_BLOCK -> Known.CONDITIONAL_BLOCK - VELOCITY_LIMIT -> Known.VELOCITY_LIMIT - MERCHANT_LOCK -> Known.MERCHANT_LOCK - CONDITIONAL_3DS_ACTION -> Known.CONDITIONAL_3DS_ACTION - else -> throw LithicInvalidDataException("Unknown AuthRuleType: $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(): AuthRuleType = 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 /* spotless:off */ other is AuthRuleType && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CreateAuthRuleRequestCardTokens && cardTokens == other.cardTokens && name == other.name && parameters == other.parameters && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(cardTokens, name, parameters, type, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CreateAuthRuleRequestCardTokens{cardTokens=$cardTokens, name=$name, parameters=$parameters, type=$type, additionalProperties=$additionalProperties}" - } - - class CreateAuthRuleRequestProgramLevel - private constructor( - private val programLevel: JsonField, - private val excludedCardTokens: JsonField>, - private val name: JsonField, - private val parameters: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("program_level") - @ExcludeMissing - programLevel: 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, excludedCardTokens, name, parameters, type, mutableMapOf()) - - /** - * 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") - - /** - * Card tokens to which the Auth Rule does not apply. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun excludedCardTokens(): Optional> = - excludedCardTokens.getOptional("excluded_card_tokens") - - /** - * 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") - - /** - * 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. Effectively determines the event stream during which it will - * be evaluated. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. - * - * @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") - - /** - * Returns the raw JSON value of [programLevel]. - * - * Unlike [programLevel], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("program_level") - @ExcludeMissing - fun _programLevel(): JsonField = programLevel - - /** - * Returns the raw JSON value of [excludedCardTokens]. - * - * Unlike [excludedCardTokens], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("excluded_card_tokens") - @ExcludeMissing - fun _excludedCardTokens(): JsonField> = excludedCardTokens - - /** - * 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 [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) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CreateAuthRuleRequestProgramLevel]. - * - * The following fields are required: - * ```java - * .programLevel() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [CreateAuthRuleRequestProgramLevel]. */ - class Builder internal constructor() { - - private var programLevel: JsonField? = null - 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 - excludedCardTokens = - createAuthRuleRequestProgramLevel.excludedCardTokens.map { - it.toMutableList() - } - name = createAuthRuleRequestProgramLevel.name - parameters = createAuthRuleRequestProgramLevel.parameters - type = createAuthRuleRequestProgramLevel.type - additionalProperties = - createAuthRuleRequestProgramLevel.additionalProperties.toMutableMap() - } - - /** 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 - } - - /** 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 - } - - /** - * 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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The type of Auth Rule. Effectively determines the event stream during which it - * will be evaluated. - * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. - * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. - * - `MERCHANT_LOCK`: AUTHORIZATION event stream. - * - `CONDITIONAL_3DS_ACTION`: 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) - } - - 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 [CreateAuthRuleRequestProgramLevel]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .programLevel() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): CreateAuthRuleRequestProgramLevel = - CreateAuthRuleRequestProgramLevel( - checkRequired("programLevel", programLevel), - (excludedCardTokens ?: JsonMissing.of()).map { it.toImmutable() }, - name, - parameters, - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): CreateAuthRuleRequestProgramLevel = apply { - if (validated) { - return@apply - } - - programLevel() - excludedCardTokens() - name() - parameters().ifPresent { it.validate() } - type().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 = - (if (programLevel.asKnown().isPresent) 1 else 0) + - (excludedCardTokens.asKnown().getOrNull()?.size ?: 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = - merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) - }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of - * merchants (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = - merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a - * non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and - * requires at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected - * type (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { - this.comment = comment - } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is - * typically the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = - descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor - * (merchant). This attribute specifies the merchant entity that will be - * locked or referenced for authorization rules. - */ - fun merchantId(merchantId: String) = - merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed - * [String] value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned - * instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 _excludedCardTokens(): JsonField> = excludedCardTokens - fun putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + /** + * 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 - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + /** + * 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 - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * 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 an immutable instance of [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - action().validate() - conditions().forEach { it.validate() } - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [CreateAuthRuleRequestProgramLevel]. + * + * The following fields are required: + * ```java + * .programLevel() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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)) - } + /** A builder for [CreateAuthRuleRequestProgramLevel]. */ + class Builder internal constructor() { - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + private var programLevel: JsonField? = null + 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() - /** - * 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, + @JvmSynthetic + internal fun from( + createAuthRuleRequestProgramLevel: CreateAuthRuleRequestProgramLevel + ) = apply { + programLevel = createAuthRuleRequestProgramLevel.programLevel + excludedCardTokens = + createAuthRuleRequestProgramLevel.excludedCardTokens.map { + it.toMutableList() } + name = createAuthRuleRequestProgramLevel.name + parameters = createAuthRuleRequestProgramLevel.parameters + type = createAuthRuleRequestProgramLevel.type + additionalProperties = + createAuthRuleRequestProgramLevel.additionalProperties.toMutableMap() + } - /** - * 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") - } + /** Whether the Auth Rule applies to all authorizations on the card program. */ + fun programLevel(programLevel: Boolean) = programLevel(JsonField.of(programLevel)) - /** - * 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") - } + /** + * 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 + } - private var validated: Boolean = false + /** Card tokens to which the Auth Rule does not apply. */ + fun excludedCardTokens(excludedCardTokens: List) = + excludedCardTokens(JsonField.of(excludedCardTokens)) - fun validate(): Action = apply { - if (validated) { - return@apply - } + /** + * 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() } + } - known() - validated = true + /** + * 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) } + } - 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 - } + /** Auth Rule Name */ + fun name(name: String?) = name(JsonField.ofNullable(name)) - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) - override fun hashCode() = value.hashCode() + /** + * 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 } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** + * Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. + */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of - * [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The type of Auth Rule. Effectively determines the event stream during which it + * will be evaluated. + * - `CONDITIONAL_BLOCK`: AUTHORIZATION event stream. + * - `VELOCITY_LIMIT`: AUTHORIZATION event stream. + * - `MERCHANT_LOCK`: AUTHORIZATION event stream. + * - `CONDITIONAL_3DS_ACTION`: THREE_DS_AUTHENTICATION event stream. + */ + fun type(type: AuthRuleType) = type(JsonField.of(type)) - /** 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() - } + /** + * 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 } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level - * associated with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being - * processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [CreateAuthRuleRequestProgramLevel]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .programLevel() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreateAuthRuleRequestProgramLevel = + CreateAuthRuleRequestProgramLevel( + checkRequired("programLevel", programLevel), + (excludedCardTokens ?: JsonMissing.of()).map { it.toImmutable() }, + name, + parameters, + type, + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): CreateAuthRuleRequestProgramLevel = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + programLevel() + excludedCardTokens() + name() + parameters().ifPresent { it.validate() } + type().ifPresent { it.validate() } + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 (programLevel.asKnown().isPresent) 1 else 0) + + (excludedCardTokens.asKnown().getOrNull()?.size ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with - * an unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = + Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = + merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with - * an unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings( - listOfStrings: List - ) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of + * type [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or - * `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) + }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, 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 ec430a542..8a3fd1a6b 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 @@ -143,7 +139,7 @@ private constructor( } /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = apply { + fun parameters(merchantLock: MerchantLockParameters) = apply { body.parameters(merchantLock) } @@ -151,7 +147,7 @@ private constructor( * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = apply { + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = apply { body.parameters(conditional3dsAction) } @@ -390,14 +386,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) fun additionalProperties(additionalProperties: Map) = apply { @@ -721,1656 +717,6 @@ private constructor( } } } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants (based on - * descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented - * or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each merchant - * object allows transaction rules to work at a granular level and requires at least one - * of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule management - * purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label shown - * on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("comment") @ExcludeMissing fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(conditional3dsActionParameters: Conditional3dsActionParameters) = - apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{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/Conditional3dsActionParameters.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Conditional3dsActionParameters.kt new file mode 100644 index 000000000..7d53bd088 --- /dev/null +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Conditional3dsActionParameters.kt @@ -0,0 +1,1190 @@ +// 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 Conditional3dsActionParameters +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 + * [Conditional3dsActionParameters]. + * + * The following fields are required: + * ```java + * .action() + * .conditions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Conditional3dsActionParameters]. */ + class Builder internal constructor() { + + private var action: JsonField? = null + private var conditions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(conditional3dsActionParameters: Conditional3dsActionParameters) = apply { + action = conditional3dsActionParameters.action + conditions = conditional3dsActionParameters.conditions.map { it.toMutableList() } + additionalProperties = + conditional3dsActionParameters.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 [Conditional3dsActionParameters]. + * + * 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(): Conditional3dsActionParameters = + Conditional3dsActionParameters( + checkRequired("action", action), + checkRequired("conditions", conditions).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Condition + 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. + * - `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. + * - `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authentication. 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. + * - `MESSAGE_CATEGORY`: The category of the authentication being processed. + * + * @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. + * - `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. + * - `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authentication. 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. + * - `MESSAGE_CATEGORY`: The category of the authentication being processed. + */ + 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. + * - `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. + * - `RISK_SCORE`: Network-provided score assessing risk level associated with a given + * authentication. 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. + * - `MESSAGE_CATEGORY`: The category of the authentication being processed. + */ + 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") + + @JvmField val RISK_SCORE = of("RISK_SCORE") + + @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") + + @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, + TRANSACTION_AMOUNT, + RISK_SCORE, + MESSAGE_CATEGORY, + } + + /** + * 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, + TRANSACTION_AMOUNT, + RISK_SCORE, + MESSAGE_CATEGORY, + /** + * 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 + TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT + RISK_SCORE -> Value.RISK_SCORE + MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY + 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 + TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT + RISK_SCORE -> Known.RISK_SCORE + MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY + 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ + } + + 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_GREATER_THAN = of("IS_GREATER_THAN") + + @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + + @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_GREATER_THAN, + IS_LESS_THAN, + } + + /** + * 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_GREATER_THAN, + IS_LESS_THAN, + /** + * 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_GREATER_THAN -> Value.IS_GREATER_THAN + IS_LESS_THAN -> Value.IS_LESS_THAN + 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_GREATER_THAN -> Known.IS_GREATER_THAN + IS_LESS_THAN -> Known.IS_LESS_THAN + 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + } + + 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` or `IS_LESS_THAN` */ + 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` or `IS_LESS_THAN` */ + 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + + 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` or `IS_LESS_THAN` */ + @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) + } + + /** + * 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` or `IS_LESS_THAN` */ + 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } + /* spotless:on */ + + 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" +} diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Event.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Event.kt index b8fd06755..6bc95a92b 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/Event.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/Event.kt @@ -440,6 +440,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -505,6 +509,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -560,6 +566,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -621,6 +629,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -683,6 +693,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventListParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventListParams.kt index 549b4d743..089349a66 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventListParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventListParams.kt @@ -400,6 +400,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -465,6 +469,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -520,6 +526,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -581,6 +589,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -643,6 +653,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscription.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscription.kt index a73c02546..0ce734af0 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscription.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscription.kt @@ -403,6 +403,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -468,6 +472,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -523,6 +529,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -584,6 +592,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -646,6 +656,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionCreateParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionCreateParams.kt index 3136ab4f9..f95808c2d 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionCreateParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionCreateParams.kt @@ -718,6 +718,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -783,6 +787,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -838,6 +844,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -899,6 +907,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -961,6 +971,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionSendSimulatedExampleParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionSendSimulatedExampleParams.kt index e254343b9..26ba59b9d 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionSendSimulatedExampleParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionSendSimulatedExampleParams.kt @@ -491,6 +491,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -556,6 +560,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -611,6 +617,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -672,6 +680,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -734,6 +744,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionUpdateParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionUpdateParams.kt index 26ede5807..75f4e7432 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionUpdateParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/EventSubscriptionUpdateParams.kt @@ -741,6 +741,10 @@ private constructor( @JvmField val MANAGEMENT_OPERATION_UPDATED = of("management_operation.updated") + @JvmField val NETWORK_TOTAL_CREATED = of("network_total.created") + + @JvmField val NETWORK_TOTAL_UPDATED = of("network_total.updated") + @JvmField val PAYMENT_TRANSACTION_CREATED = of("payment_transaction.created") @JvmField val PAYMENT_TRANSACTION_UPDATED = of("payment_transaction.updated") @@ -806,6 +810,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -861,6 +867,8 @@ private constructor( LOAN_TAPE_UPDATED, MANAGEMENT_OPERATION_CREATED, MANAGEMENT_OPERATION_UPDATED, + NETWORK_TOTAL_CREATED, + NETWORK_TOTAL_UPDATED, PAYMENT_TRANSACTION_CREATED, PAYMENT_TRANSACTION_UPDATED, INTERNAL_TRANSACTION_CREATED, @@ -922,6 +930,8 @@ private constructor( LOAN_TAPE_UPDATED -> Value.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Value.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Value.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Value.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Value.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Value.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Value.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Value.INTERNAL_TRANSACTION_CREATED @@ -984,6 +994,8 @@ private constructor( LOAN_TAPE_UPDATED -> Known.LOAN_TAPE_UPDATED MANAGEMENT_OPERATION_CREATED -> Known.MANAGEMENT_OPERATION_CREATED MANAGEMENT_OPERATION_UPDATED -> Known.MANAGEMENT_OPERATION_UPDATED + NETWORK_TOTAL_CREATED -> Known.NETWORK_TOTAL_CREATED + NETWORK_TOTAL_UPDATED -> Known.NETWORK_TOTAL_UPDATED PAYMENT_TRANSACTION_CREATED -> Known.PAYMENT_TRANSACTION_CREATED PAYMENT_TRANSACTION_UPDATED -> Known.PAYMENT_TRANSACTION_UPDATED INTERNAL_TRANSACTION_CREATED -> Known.INTERNAL_TRANSACTION_CREATED diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt index 991fefbaf..f9f4b5e1a 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt @@ -2043,7 +2043,7 @@ private constructor( private val owner: JsonField, private val ownerType: JsonField, private val routingNumber: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationMethod: JsonField, private val accountToken: JsonField, private val address: JsonField, @@ -2073,7 +2073,9 @@ private constructor( @JsonProperty("routing_number") @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), @JsonProperty("verification_method") @ExcludeMissing verificationMethod: JsonField = @@ -2177,7 +2179,7 @@ private constructor( * unexpectedly missing or null (e.g. if the server responded with an unexpected * value). */ - fun type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * Verification Method @@ -2305,7 +2307,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationMethod]. @@ -2423,7 +2425,7 @@ private constructor( private var owner: JsonField? = null private var ownerType: JsonField? = null private var routingNumber: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationMethod: JsonField? = null private var accountToken: JsonField = JsonMissing.of() @@ -2548,16 +2550,16 @@ private constructor( } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** Verification Method */ fun verificationMethod(verificationMethod: ExternallyVerifiedVerificationMethod) = @@ -2792,8 +2794,9 @@ private constructor( (if (userDefinedId.asKnown().isPresent) 1 else 0) /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : - Enum { + class AccountType + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** * Returns this class instance's raw value. @@ -2811,19 +2814,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -2833,7 +2836,8 @@ private constructor( CHECKING, SAVINGS, /** - * An enum member indicating that [Type] was instantiated with an unknown value. + * An enum member indicating that [AccountType] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -2865,7 +2869,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -2884,7 +2888,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -2914,7 +2918,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() @@ -3082,7 +3086,7 @@ private constructor( private val owner: JsonField, private val ownerType: JsonField, private val routingNumber: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationMethod: JsonField, private val accountToken: JsonField, private val address: JsonField, @@ -3112,7 +3116,9 @@ private constructor( @JsonProperty("routing_number") @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + type: JsonField = JsonMissing.of(), @JsonProperty("verification_method") @ExcludeMissing verificationMethod: JsonField = JsonMissing.of(), @@ -3215,7 +3221,7 @@ private constructor( * unexpectedly missing or null (e.g. if the server responded with an unexpected * value). */ - fun type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * Verification Method @@ -3343,7 +3349,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationMethod]. @@ -3460,7 +3466,7 @@ private constructor( private var owner: JsonField? = null private var ownerType: JsonField? = null private var routingNumber: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationMethod: JsonField? = null private var accountToken: JsonField = JsonMissing.of() private var address: JsonField = JsonMissing.of() @@ -3581,16 +3587,16 @@ private constructor( } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** Verification Method */ fun verificationMethod(verificationMethod: UnverifiedVerificationMethod) = @@ -3825,8 +3831,9 @@ private constructor( (if (userDefinedId.asKnown().isPresent) 1 else 0) /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : - Enum { + class AccountType + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** * Returns this class instance's raw value. @@ -3844,19 +3851,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -3866,7 +3873,8 @@ private constructor( CHECKING, SAVINGS, /** - * An enum member indicating that [Type] was instantiated with an unknown value. + * An enum member indicating that [AccountType] was instantiated with an unknown + * value. */ _UNKNOWN, } @@ -3898,7 +3906,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -3917,7 +3925,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -3947,7 +3955,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponse.kt index b8f080af6..dcf992821 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -700,15 +700,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1285,7 +1286,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1303,19 +1305,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1324,7 +1326,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1355,7 +1359,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1372,7 +1376,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1402,7 +1406,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountListResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountListResponse.kt index 955a79160..aff3b5d2c 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountListResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountListResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -699,15 +699,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1284,7 +1285,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1302,19 +1304,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1323,7 +1325,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1354,7 +1358,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1371,7 +1375,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1401,7 +1405,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponse.kt index d39d334f9..95e3fe19e 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -700,15 +700,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1285,7 +1286,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1303,19 +1305,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1324,7 +1326,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1355,7 +1359,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1372,7 +1376,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1402,7 +1406,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponse.kt index 5e523bdc6..9539a3570 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -704,15 +704,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1289,7 +1290,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1307,19 +1309,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1328,7 +1330,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1359,7 +1363,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1376,7 +1380,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1406,7 +1410,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponse.kt index 99f2f5505..b9a0af299 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -701,15 +701,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1158,7 +1159,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1176,19 +1178,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1197,7 +1199,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1228,7 +1232,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1245,7 +1249,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1275,7 +1279,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponse.kt index d7b48171c..1e306f18c 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -536,7 +536,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -700,15 +700,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1285,7 +1286,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1303,19 +1305,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1324,7 +1326,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1355,7 +1359,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1372,7 +1376,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1402,7 +1406,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/MerchantLockParameters.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/MerchantLockParameters.kt new file mode 100644 index 000000000..8ebec6cf1 --- /dev/null +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/MerchantLockParameters.kt @@ -0,0 +1,438 @@ +// 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.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.checkKnown +import com.lithic.api.core.checkRequired +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 MerchantLockParameters +private constructor( + private val merchants: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("merchants") + @ExcludeMissing + merchants: JsonField> = JsonMissing.of() + ) : this(merchants, mutableMapOf()) + + /** + * A list of merchant locks defining specific merchants or groups of merchants (based on + * descriptors or IDs) that the lock applies to. + * + * @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 merchants(): List = merchants.getRequired("merchants") + + /** + * Returns the raw JSON value of [merchants]. + * + * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("merchants") + @ExcludeMissing + fun _merchants(): JsonField> = merchants + + @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 [MerchantLockParameters]. + * + * The following fields are required: + * ```java + * .merchants() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MerchantLockParameters]. */ + class Builder internal constructor() { + + private var merchants: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(merchantLockParameters: MerchantLockParameters) = apply { + merchants = merchantLockParameters.merchants.map { it.toMutableList() } + additionalProperties = merchantLockParameters.additionalProperties.toMutableMap() + } + + /** + * A list of merchant locks defining specific merchants or groups of merchants (based on + * descriptors or IDs) that the lock applies to. + */ + fun merchants(merchants: List) = merchants(JsonField.of(merchants)) + + /** + * Sets [Builder.merchants] to an arbitrary JSON value. + * + * You should usually call [Builder.merchants] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun merchants(merchants: JsonField>) = apply { + this.merchants = merchants.map { it.toMutableList() } + } + + /** + * Adds a single [Merchant] to [merchants]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addMerchant(merchant: Merchant) = apply { + merchants = + (merchants ?: JsonField.of(mutableListOf())).also { + checkKnown("merchants", it).add(merchant) + } + } + + 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 [MerchantLockParameters]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .merchants() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MerchantLockParameters = + MerchantLockParameters( + checkRequired("merchants", merchants).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MerchantLockParameters = apply { + if (validated) { + return@apply + } + + merchants().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 = + (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + /** + * Represents a specific merchant lock based on their ID or descriptor. Each merchant object + * allows transaction rules to work at a granular level and requires at least one of merchant_id + * or descriptor. + */ + class Merchant + private constructor( + private val comment: JsonField, + private val descriptor: JsonField, + private val merchantId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("comment") @ExcludeMissing comment: JsonField = JsonMissing.of(), + @JsonProperty("descriptor") + @ExcludeMissing + descriptor: JsonField = JsonMissing.of(), + @JsonProperty("merchant_id") + @ExcludeMissing + merchantId: JsonField = JsonMissing.of(), + ) : this(comment, descriptor, merchantId, mutableMapOf()) + + /** + * A comment or explanation about the merchant, used internally for rule management + * purposes. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun comment(): Optional = comment.getOptional("comment") + + /** + * Short description of the merchant, often used to provide more human-readable context + * about the transaction merchant. This is typically the name or label shown on transaction + * summaries. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun descriptor(): Optional = descriptor.getOptional("descriptor") + + /** + * Unique alphanumeric identifier for the payment card acceptor (merchant). This attribute + * specifies the merchant entity that will be locked or referenced for authorization rules. + * + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun merchantId(): Optional = merchantId.getOptional("merchant_id") + + /** + * Returns the raw JSON value of [comment]. + * + * Unlike [comment], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("comment") @ExcludeMissing fun _comment(): JsonField = comment + + /** + * Returns the raw JSON value of [descriptor]. + * + * Unlike [descriptor], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("descriptor") + @ExcludeMissing + fun _descriptor(): JsonField = descriptor + + /** + * Returns the raw JSON value of [merchantId]. + * + * Unlike [merchantId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("merchant_id") + @ExcludeMissing + fun _merchantId(): JsonField = merchantId + + @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 [Merchant]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Merchant]. */ + class Builder internal constructor() { + + private var comment: JsonField = JsonMissing.of() + private var descriptor: JsonField = JsonMissing.of() + private var merchantId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(merchant: Merchant) = apply { + comment = merchant.comment + descriptor = merchant.descriptor + merchantId = merchant.merchantId + additionalProperties = merchant.additionalProperties.toMutableMap() + } + + /** + * A comment or explanation about the merchant, used internally for rule management + * purposes. + */ + fun comment(comment: String) = comment(JsonField.of(comment)) + + /** + * Sets [Builder.comment] to an arbitrary JSON value. + * + * You should usually call [Builder.comment] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun comment(comment: JsonField) = apply { this.comment = comment } + + /** + * Short description of the merchant, often used to provide more human-readable context + * about the transaction merchant. This is typically the name or label shown on + * transaction summaries. + */ + fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) + + /** + * Sets [Builder.descriptor] to an arbitrary JSON value. + * + * You should usually call [Builder.descriptor] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun descriptor(descriptor: JsonField) = apply { this.descriptor = descriptor } + + /** + * Unique alphanumeric identifier for the payment card acceptor (merchant). This + * attribute specifies the merchant entity that will be locked or referenced for + * authorization rules. + */ + fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) + + /** + * Sets [Builder.merchantId] to an arbitrary JSON value. + * + * You should usually call [Builder.merchantId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun merchantId(merchantId: JsonField) = apply { this.merchantId = merchantId } + + 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 [Merchant]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Merchant = + Merchant(comment, descriptor, merchantId, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Merchant = apply { + if (validated) { + return@apply + } + + comment() + descriptor() + merchantId() + 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 (comment.asKnown().isPresent) 1 else 0) + + (if (descriptor.asKnown().isPresent) 1 else 0) + + (if (merchantId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" +} diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/MicroDepositCreateResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/MicroDepositCreateResponse.kt index cf0c7f498..b305e4775 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/MicroDepositCreateResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/MicroDepositCreateResponse.kt @@ -31,7 +31,7 @@ private constructor( private val ownerType: JsonField, private val routingNumber: JsonField, private val state: JsonField, - private val type: JsonField, + private val type: JsonField, private val verificationAttempts: JsonField, private val verificationMethod: JsonField, private val verificationState: JsonField, @@ -64,7 +64,7 @@ private constructor( @ExcludeMissing routingNumber: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("verification_attempts") @ExcludeMissing verificationAttempts: JsonField = JsonMissing.of(), @@ -203,7 +203,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 type(): Type = type.getRequired("type") + fun type(): AccountType = type.getRequired("type") /** * The number of attempts at verification @@ -377,7 +377,7 @@ private constructor( * * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type /** * Returns the raw JSON value of [verificationAttempts]. @@ -535,7 +535,7 @@ private constructor( private var ownerType: JsonField? = null private var routingNumber: JsonField? = null private var state: JsonField? = null - private var type: JsonField? = null + private var type: JsonField? = null private var verificationAttempts: JsonField? = null private var verificationMethod: JsonField? = null private var verificationState: JsonField? = null @@ -696,15 +696,16 @@ private constructor( fun state(state: JsonField) = apply { this.state = state } /** Account Type */ - fun type(type: Type) = type(JsonField.of(type)) + fun type(type: AccountType) = type(JsonField.of(type)) /** * Sets [Builder.type] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.type] with a well-typed [AccountType] 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 type(type: JsonField) = apply { this.type = type } /** The number of attempts at verification */ fun verificationAttempts(verificationAttempts: Long) = @@ -1281,7 +1282,8 @@ private constructor( } /** Account Type */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class AccountType @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -1299,19 +1301,19 @@ private constructor( @JvmField val SAVINGS = of("SAVINGS") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [AccountType]'s known values. */ enum class Known { CHECKING, SAVINGS, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [AccountType] 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. @@ -1320,7 +1322,9 @@ private constructor( enum class Value { CHECKING, SAVINGS, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + /** + * An enum member indicating that [AccountType] was instantiated with an unknown value. + */ _UNKNOWN, } @@ -1351,7 +1355,7 @@ private constructor( when (this) { CHECKING -> Known.CHECKING SAVINGS -> Known.SAVINGS - else -> throw LithicInvalidDataException("Unknown Type: $value") + else -> throw LithicInvalidDataException("Unknown AccountType: $value") } /** @@ -1368,7 +1372,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): AccountType = apply { if (validated) { return@apply } @@ -1398,7 +1402,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalListResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalListResponse.kt index 34a604caf..c56cd2df1 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalListResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalListResponse.kt @@ -27,6 +27,7 @@ private constructor( private val created: JsonField, private val currency: JsonField, private val institutionId: JsonField, + private val isComplete: JsonField, private val network: JsonField, private val reportDate: JsonField, private val settlementInstitutionId: JsonField, @@ -47,6 +48,9 @@ private constructor( @JsonProperty("institution_id") @ExcludeMissing institutionId: JsonField = JsonMissing.of(), + @JsonProperty("is_complete") + @ExcludeMissing + isComplete: JsonField = JsonMissing.of(), @JsonProperty("network") @ExcludeMissing network: JsonField = JsonMissing.of(), @JsonProperty("report_date") @ExcludeMissing @@ -67,6 +71,7 @@ private constructor( created, currency, institutionId, + isComplete, network, reportDate, settlementInstitutionId, @@ -116,7 +121,16 @@ private constructor( fun institutionId(): String = institutionId.getRequired("institution_id") /** - * Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. + * Indicates that all settlement records related to this Network Total are available in the + * details endpoint. + * + * @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 isComplete(): Boolean = isComplete.getRequired("is_complete") + + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or INTERLINK. * * @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). @@ -202,6 +216,13 @@ private constructor( @ExcludeMissing fun _institutionId(): JsonField = institutionId + /** + * Returns the raw JSON value of [isComplete]. + * + * Unlike [isComplete], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_complete") @ExcludeMissing fun _isComplete(): JsonField = isComplete + /** * Returns the raw JSON value of [network]. * @@ -276,6 +297,7 @@ private constructor( * .created() * .currency() * .institutionId() + * .isComplete() * .network() * .reportDate() * .settlementInstitutionId() @@ -294,6 +316,7 @@ private constructor( private var created: JsonField? = null private var currency: JsonField? = null private var institutionId: JsonField? = null + private var isComplete: JsonField? = null private var network: JsonField? = null private var reportDate: JsonField? = null private var settlementInstitutionId: JsonField? = null @@ -309,6 +332,7 @@ private constructor( created = networkTotalListResponse.created currency = networkTotalListResponse.currency institutionId = networkTotalListResponse.institutionId + isComplete = networkTotalListResponse.isComplete network = networkTotalListResponse.network reportDate = networkTotalListResponse.reportDate settlementInstitutionId = networkTotalListResponse.settlementInstitutionId @@ -381,7 +405,23 @@ private constructor( } /** - * Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. + * Indicates that all settlement records related to this Network Total are available in the + * details endpoint. + */ + fun isComplete(isComplete: Boolean) = isComplete(JsonField.of(isComplete)) + + /** + * Sets [Builder.isComplete] to an arbitrary JSON value. + * + * You should usually call [Builder.isComplete] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isComplete(isComplete: JsonField) = apply { this.isComplete = isComplete } + + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or + * INTERLINK. */ fun network(network: Network) = network(JsonField.of(network)) @@ -492,6 +532,7 @@ private constructor( * .created() * .currency() * .institutionId() + * .isComplete() * .network() * .reportDate() * .settlementInstitutionId() @@ -508,6 +549,7 @@ private constructor( checkRequired("created", created), checkRequired("currency", currency), checkRequired("institutionId", institutionId), + checkRequired("isComplete", isComplete), checkRequired("network", network), checkRequired("reportDate", reportDate), checkRequired("settlementInstitutionId", settlementInstitutionId), @@ -530,6 +572,7 @@ private constructor( created() currency() institutionId() + isComplete() network().validate() reportDate() settlementInstitutionId() @@ -559,6 +602,7 @@ private constructor( (if (created.asKnown().isPresent) 1 else 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (institutionId.asKnown().isPresent) 1 else 0) + + (if (isComplete.asKnown().isPresent) 1 else 0) + (network.asKnown().getOrNull()?.validity() ?: 0) + (if (reportDate.asKnown().isPresent) 1 else 0) + (if (settlementInstitutionId.asKnown().isPresent) 1 else 0) + @@ -863,7 +907,9 @@ private constructor( "Amounts{grossSettlement=$grossSettlement, interchangeFees=$interchangeFees, netSettlement=$netSettlement, visaCharges=$visaCharges, additionalProperties=$additionalProperties}" } - /** Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. */ + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or INTERLINK. + */ class Network @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -878,6 +924,8 @@ private constructor( companion object { + @JvmField val AMEX = of("AMEX") + @JvmField val VISA = of("VISA") @JvmField val MASTERCARD = of("MASTERCARD") @@ -891,6 +939,7 @@ private constructor( /** An enum containing [Network]'s known values. */ enum class Known { + AMEX, VISA, MASTERCARD, MAESTRO, @@ -907,6 +956,7 @@ private constructor( * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { + AMEX, VISA, MASTERCARD, MAESTRO, @@ -924,6 +974,7 @@ private constructor( */ fun value(): Value = when (this) { + AMEX -> Value.AMEX VISA -> Value.VISA MASTERCARD -> Value.MASTERCARD MAESTRO -> Value.MAESTRO @@ -942,6 +993,7 @@ private constructor( */ fun known(): Known = when (this) { + AMEX -> Known.AMEX VISA -> Known.VISA MASTERCARD -> Known.MASTERCARD MAESTRO -> Known.MAESTRO @@ -1006,15 +1058,15 @@ private constructor( return true } - return /* spotless:off */ other is NetworkTotalListResponse && token == other.token && amounts == other.amounts && created == other.created && currency == other.currency && institutionId == other.institutionId && network == other.network && reportDate == other.reportDate && settlementInstitutionId == other.settlementInstitutionId && settlementService == other.settlementService && updated == other.updated && cycle == other.cycle && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is NetworkTotalListResponse && token == other.token && amounts == other.amounts && created == other.created && currency == other.currency && institutionId == other.institutionId && isComplete == other.isComplete && network == other.network && reportDate == other.reportDate && settlementInstitutionId == other.settlementInstitutionId && settlementService == other.settlementService && updated == other.updated && cycle == other.cycle && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(token, amounts, created, currency, institutionId, network, reportDate, settlementInstitutionId, settlementService, updated, cycle, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(token, amounts, created, currency, institutionId, isComplete, network, reportDate, settlementInstitutionId, settlementService, updated, cycle, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "NetworkTotalListResponse{token=$token, amounts=$amounts, created=$created, currency=$currency, institutionId=$institutionId, network=$network, reportDate=$reportDate, settlementInstitutionId=$settlementInstitutionId, settlementService=$settlementService, updated=$updated, cycle=$cycle, additionalProperties=$additionalProperties}" + "NetworkTotalListResponse{token=$token, amounts=$amounts, created=$created, currency=$currency, institutionId=$institutionId, isComplete=$isComplete, network=$network, reportDate=$reportDate, settlementInstitutionId=$settlementInstitutionId, settlementService=$settlementService, updated=$updated, cycle=$cycle, additionalProperties=$additionalProperties}" } diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponse.kt index 20f282da6..ac09d0fa2 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponse.kt @@ -27,6 +27,7 @@ private constructor( private val created: JsonField, private val currency: JsonField, private val institutionId: JsonField, + private val isComplete: JsonField, private val network: JsonField, private val reportDate: JsonField, private val settlementInstitutionId: JsonField, @@ -47,6 +48,9 @@ private constructor( @JsonProperty("institution_id") @ExcludeMissing institutionId: JsonField = JsonMissing.of(), + @JsonProperty("is_complete") + @ExcludeMissing + isComplete: JsonField = JsonMissing.of(), @JsonProperty("network") @ExcludeMissing network: JsonField = JsonMissing.of(), @JsonProperty("report_date") @ExcludeMissing @@ -67,6 +71,7 @@ private constructor( created, currency, institutionId, + isComplete, network, reportDate, settlementInstitutionId, @@ -116,7 +121,16 @@ private constructor( fun institutionId(): String = institutionId.getRequired("institution_id") /** - * Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. + * Indicates that all settlement records related to this Network Total are available in the + * details endpoint. + * + * @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 isComplete(): Boolean = isComplete.getRequired("is_complete") + + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or INTERLINK. * * @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). @@ -202,6 +216,13 @@ private constructor( @ExcludeMissing fun _institutionId(): JsonField = institutionId + /** + * Returns the raw JSON value of [isComplete]. + * + * Unlike [isComplete], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_complete") @ExcludeMissing fun _isComplete(): JsonField = isComplete + /** * Returns the raw JSON value of [network]. * @@ -276,6 +297,7 @@ private constructor( * .created() * .currency() * .institutionId() + * .isComplete() * .network() * .reportDate() * .settlementInstitutionId() @@ -294,6 +316,7 @@ private constructor( private var created: JsonField? = null private var currency: JsonField? = null private var institutionId: JsonField? = null + private var isComplete: JsonField? = null private var network: JsonField? = null private var reportDate: JsonField? = null private var settlementInstitutionId: JsonField? = null @@ -309,6 +332,7 @@ private constructor( created = networkTotalRetrieveResponse.created currency = networkTotalRetrieveResponse.currency institutionId = networkTotalRetrieveResponse.institutionId + isComplete = networkTotalRetrieveResponse.isComplete network = networkTotalRetrieveResponse.network reportDate = networkTotalRetrieveResponse.reportDate settlementInstitutionId = networkTotalRetrieveResponse.settlementInstitutionId @@ -381,7 +405,23 @@ private constructor( } /** - * Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. + * Indicates that all settlement records related to this Network Total are available in the + * details endpoint. + */ + fun isComplete(isComplete: Boolean) = isComplete(JsonField.of(isComplete)) + + /** + * Sets [Builder.isComplete] to an arbitrary JSON value. + * + * You should usually call [Builder.isComplete] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun isComplete(isComplete: JsonField) = apply { this.isComplete = isComplete } + + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or + * INTERLINK. */ fun network(network: Network) = network(JsonField.of(network)) @@ -492,6 +532,7 @@ private constructor( * .created() * .currency() * .institutionId() + * .isComplete() * .network() * .reportDate() * .settlementInstitutionId() @@ -508,6 +549,7 @@ private constructor( checkRequired("created", created), checkRequired("currency", currency), checkRequired("institutionId", institutionId), + checkRequired("isComplete", isComplete), checkRequired("network", network), checkRequired("reportDate", reportDate), checkRequired("settlementInstitutionId", settlementInstitutionId), @@ -530,6 +572,7 @@ private constructor( created() currency() institutionId() + isComplete() network().validate() reportDate() settlementInstitutionId() @@ -559,6 +602,7 @@ private constructor( (if (created.asKnown().isPresent) 1 else 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (institutionId.asKnown().isPresent) 1 else 0) + + (if (isComplete.asKnown().isPresent) 1 else 0) + (network.asKnown().getOrNull()?.validity() ?: 0) + (if (reportDate.asKnown().isPresent) 1 else 0) + (if (settlementInstitutionId.asKnown().isPresent) 1 else 0) + @@ -863,7 +907,9 @@ private constructor( "Amounts{grossSettlement=$grossSettlement, interchangeFees=$interchangeFees, netSettlement=$netSettlement, visaCharges=$visaCharges, additionalProperties=$additionalProperties}" } - /** Card network where the transaction took place. VISA, MASTERCARD, MAESTRO, or INTERLINK. */ + /** + * Card network where the transaction took place. AMEX, VISA, MASTERCARD, MAESTRO, or INTERLINK. + */ class Network @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -878,6 +924,8 @@ private constructor( companion object { + @JvmField val AMEX = of("AMEX") + @JvmField val VISA = of("VISA") @JvmField val MASTERCARD = of("MASTERCARD") @@ -891,6 +939,7 @@ private constructor( /** An enum containing [Network]'s known values. */ enum class Known { + AMEX, VISA, MASTERCARD, MAESTRO, @@ -907,6 +956,7 @@ private constructor( * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { + AMEX, VISA, MASTERCARD, MAESTRO, @@ -924,6 +974,7 @@ private constructor( */ fun value(): Value = when (this) { + AMEX -> Value.AMEX VISA -> Value.VISA MASTERCARD -> Value.MASTERCARD MAESTRO -> Value.MAESTRO @@ -942,6 +993,7 @@ private constructor( */ fun known(): Known = when (this) { + AMEX -> Known.AMEX VISA -> Known.VISA MASTERCARD -> Known.MASTERCARD MAESTRO -> Known.MAESTRO @@ -1006,15 +1058,15 @@ private constructor( return true } - return /* spotless:off */ other is NetworkTotalRetrieveResponse && token == other.token && amounts == other.amounts && created == other.created && currency == other.currency && institutionId == other.institutionId && network == other.network && reportDate == other.reportDate && settlementInstitutionId == other.settlementInstitutionId && settlementService == other.settlementService && updated == other.updated && cycle == other.cycle && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is NetworkTotalRetrieveResponse && token == other.token && amounts == other.amounts && created == other.created && currency == other.currency && institutionId == other.institutionId && isComplete == other.isComplete && network == other.network && reportDate == other.reportDate && settlementInstitutionId == other.settlementInstitutionId && settlementService == other.settlementService && updated == other.updated && cycle == other.cycle && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(token, amounts, created, currency, institutionId, network, reportDate, settlementInstitutionId, settlementService, updated, cycle, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(token, amounts, created, currency, institutionId, isComplete, network, reportDate, settlementInstitutionId, settlementService, updated, cycle, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "NetworkTotalRetrieveResponse{token=$token, amounts=$amounts, created=$created, currency=$currency, institutionId=$institutionId, network=$network, reportDate=$reportDate, settlementInstitutionId=$settlementInstitutionId, settlementService=$settlementService, updated=$updated, cycle=$cycle, additionalProperties=$additionalProperties}" + "NetworkTotalRetrieveResponse{token=$token, amounts=$amounts, created=$created, currency=$currency, institutionId=$institutionId, isComplete=$isComplete, network=$network, reportDate=$reportDate, settlementInstitutionId=$settlementInstitutionId, settlementService=$settlementService, updated=$updated, cycle=$cycle, additionalProperties=$additionalProperties}" } 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 7b138cefc..9d9e10227 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 @@ -7659,6 +7659,7 @@ private constructor( private val result: JsonField, private val ruleResults: JsonField>, private val type: JsonField, + private val accountType: JsonField, private val networkSpecificData: JsonField, private val additionalProperties: MutableMap, ) { @@ -7689,6 +7690,9 @@ private constructor( @ExcludeMissing ruleResults: JsonField> = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("account_type") + @ExcludeMissing + accountType: JsonField = JsonMissing.of(), @JsonProperty("network_specific_data") @ExcludeMissing networkSpecificData: JsonField = JsonMissing.of(), @@ -7703,6 +7707,7 @@ private constructor( result, ruleResults, type, + accountType, networkSpecificData, mutableMapOf(), ) @@ -7788,6 +7793,12 @@ private constructor( */ fun type(): Type = type.getRequired("type") + /** + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun accountType(): Optional = accountType.getOptional("account_type") + /** * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -7880,6 +7891,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [accountType]. + * + * Unlike [accountType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("account_type") + @ExcludeMissing + fun _accountType(): JsonField = accountType + /** * Returns the raw JSON value of [networkSpecificData]. * @@ -7937,6 +7957,7 @@ private constructor( private var result: JsonField? = null private var ruleResults: JsonField>? = null private var type: JsonField? = null + private var accountType: JsonField = JsonMissing.of() private var networkSpecificData: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -7952,6 +7973,7 @@ private constructor( result = transactionEvent.result ruleResults = transactionEvent.ruleResults.map { it.toMutableList() } type = transactionEvent.type + accountType = transactionEvent.accountType networkSpecificData = transactionEvent.networkSpecificData additionalProperties = transactionEvent.additionalProperties.toMutableMap() } @@ -8124,6 +8146,19 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun accountType(accountType: AccountType) = accountType(JsonField.of(accountType)) + + /** + * Sets [Builder.accountType] to an arbitrary JSON value. + * + * You should usually call [Builder.accountType] with a well-typed [AccountType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun accountType(accountType: JsonField) = apply { + this.accountType = accountType + } + fun networkSpecificData(networkSpecificData: NetworkSpecificData) = networkSpecificData(JsonField.of(networkSpecificData)) @@ -8190,6 +8225,7 @@ private constructor( checkRequired("result", result), checkRequired("ruleResults", ruleResults).map { it.toImmutable() }, checkRequired("type", type), + accountType, networkSpecificData, additionalProperties.toMutableMap(), ) @@ -8212,6 +8248,7 @@ private constructor( result().validate() ruleResults().forEach { it.validate() } type().validate() + accountType().ifPresent { it.validate() } networkSpecificData().ifPresent { it.validate() } validated = true } @@ -8242,6 +8279,7 @@ private constructor( (result.asKnown().getOrNull()?.validity() ?: 0) + (ruleResults.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (accountType.asKnown().getOrNull()?.validity() ?: 0) + (networkSpecificData.asKnown().getOrNull()?.validity() ?: 0) class TransactionEventAmounts @@ -12465,6 +12503,137 @@ private constructor( override fun toString() = value.toString() } + class AccountType @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 CHECKING = of("CHECKING") + + @JvmField val SAVINGS = of("SAVINGS") + + @JvmStatic fun of(value: String) = AccountType(JsonField.of(value)) + } + + /** An enum containing [AccountType]'s known values. */ + enum class Known { + CHECKING, + SAVINGS, + } + + /** + * An enum containing [AccountType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AccountType] 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 { + CHECKING, + SAVINGS, + /** + * An enum member indicating that [AccountType] 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) { + CHECKING -> Value.CHECKING + SAVINGS -> Value.SAVINGS + 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) { + CHECKING -> Known.CHECKING + SAVINGS -> Known.SAVINGS + else -> throw LithicInvalidDataException("Unknown AccountType: $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(): AccountType = 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 /* spotless:off */ other is AccountType && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + class NetworkSpecificData private constructor( private val mastercard: JsonField, @@ -13466,17 +13635,17 @@ private constructor( return true } - return /* spotless:off */ other is TransactionEvent && token == other.token && amount == other.amount && amounts == other.amounts && created == other.created && detailedResults == other.detailedResults && effectivePolarity == other.effectivePolarity && networkInfo == other.networkInfo && result == other.result && ruleResults == other.ruleResults && type == other.type && networkSpecificData == other.networkSpecificData && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TransactionEvent && token == other.token && amount == other.amount && amounts == other.amounts && created == other.created && detailedResults == other.detailedResults && effectivePolarity == other.effectivePolarity && networkInfo == other.networkInfo && result == other.result && ruleResults == other.ruleResults && type == other.type && accountType == other.accountType && networkSpecificData == other.networkSpecificData && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(token, amount, amounts, created, detailedResults, effectivePolarity, networkInfo, result, ruleResults, type, networkSpecificData, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(token, amount, amounts, created, detailedResults, effectivePolarity, networkInfo, result, ruleResults, type, accountType, networkSpecificData, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "TransactionEvent{token=$token, amount=$amount, amounts=$amounts, created=$created, detailedResults=$detailedResults, effectivePolarity=$effectivePolarity, networkInfo=$networkInfo, result=$result, ruleResults=$ruleResults, type=$type, networkSpecificData=$networkSpecificData, additionalProperties=$additionalProperties}" + "TransactionEvent{token=$token, amount=$amount, amounts=$amounts, created=$created, detailedResults=$detailedResults, effectivePolarity=$effectivePolarity, networkInfo=$networkInfo, result=$result, ruleResults=$ruleResults, type=$type, accountType=$accountType, networkSpecificData=$networkSpecificData, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ApplyResponse.kt b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ApplyResponse.kt index 95479f50d..78991efbb 100644 --- a/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ApplyResponse.kt +++ b/lithic-java-core/src/main/kotlin/com/lithic/api/models/V2ApplyResponse.kt @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 2bb9289fb..0dae29d7c 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 8f36a8c3f..ddf8c5793 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 8f70d0fee..a0bb95e92 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 c709acc43..8fb7a6494 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 5152259f4..d9b83a82b 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } 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 bbe4ff4cd..606f2b2cf 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 @@ -757,14 +757,14 @@ private constructor( parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ - fun parameters(merchantLock: Parameters.MerchantLockParameters) = + fun parameters(merchantLock: MerchantLockParameters) = parameters(Parameters.ofMerchantLock(merchantLock)) /** * Alias for calling [parameters] with * `Parameters.ofConditional3dsAction(conditional3dsAction)`. */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) /** @@ -1107,3849 +1107,491 @@ private constructor( } } } + } - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" - } - - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Conditional3dsActionParameters = 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 /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - class Condition - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } - - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } - - 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_GREATER_THAN = of("IS_GREATER_THAN") - - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") - - @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_GREATER_THAN, - IS_LESS_THAN, - } - - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ - } - - 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` or `IS_LESS_THAN` */ - 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ - - 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` or `IS_LESS_THAN` */ - @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) - } - - /** - * 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` or `IS_LESS_THAN` */ - 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 /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" - } - - class DraftVersion - private constructor( - private val parameters: JsonField, - private val version: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("parameters") - @ExcludeMissing - parameters: JsonField = JsonMissing.of(), - @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), - ) : this(parameters, version, 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 version of the rule, this is incremented whenever the rule's parameters change. - * - * @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 version(): Long = version.getRequired("version") - - /** - * 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 [version]. - * - * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - - @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 [DraftVersion]. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DraftVersion]. */ - class Builder internal constructor() { - - private var parameters: JsonField? = null - private var version: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(draftVersion: DraftVersion) = apply { - parameters = draftVersion.parameters - version = draftVersion.version - additionalProperties = draftVersion.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: Parameters.MerchantLockParameters) = - parameters(Parameters.ofMerchantLock(merchantLock)) - - /** - * Alias for calling [parameters] with - * `Parameters.ofConditional3dsAction(conditional3dsAction)`. - */ - fun parameters(conditional3dsAction: Parameters.Conditional3dsActionParameters) = - parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - - /** - * The version of the rule, this is incremented whenever the rule's parameters change. - */ - fun version(version: Long) = version(JsonField.of(version)) - - /** - * Sets [Builder.version] to an arbitrary JSON value. - * - * You should usually call [Builder.version] with a well-typed [Long] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun version(version: JsonField) = apply { this.version = version } - - 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 [DraftVersion]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .parameters() - * .version() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DraftVersion = - DraftVersion( - checkRequired("parameters", parameters), - checkRequired("version", version), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): DraftVersion = apply { - if (validated) { - return@apply - } - - parameters().validate() - version() - 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 = - (parameters.asKnown().getOrNull()?.validity() ?: 0) + - (if (version.asKnown().isPresent) 1 else 0) - - /** 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 _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 isConditionalBlock(): Boolean = conditionalBlock != null - - fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - - fun isMerchantLock(): Boolean = merchantLock != null - - fun isConditional3dsAction(): Boolean = conditional3dsAction != null - - fun asConditionalBlock(): ConditionalBlockParameters = - conditionalBlock.getOrThrow("conditionalBlock") - - fun asVelocityLimitParams(): VelocityLimitParams = - velocityLimitParams.getOrThrow("velocityLimitParams") - - fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - - fun asConditional3dsAction(): Conditional3dsActionParameters = - conditional3dsAction.getOrThrow("conditional3dsAction") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) - velocityLimitParams != null -> - visitor.visitVelocityLimitParams(velocityLimitParams) - merchantLock != null -> visitor.visitMerchantLock(merchantLock) - conditional3dsAction != null -> - visitor.visitConditional3dsAction(conditional3dsAction) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Parameters = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) { - conditionalBlock.validate() - } - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) { - velocityLimitParams.validate() - } - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) { - merchantLock.validate() - } - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) { - conditional3dsAction.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 = - accept( - object : Visitor { - override fun visitConditionalBlock( - conditionalBlock: ConditionalBlockParameters - ) = conditionalBlock.validity() - - override fun visitVelocityLimitParams( - velocityLimitParams: VelocityLimitParams - ) = velocityLimitParams.validity() - - override fun visitMerchantLock(merchantLock: MerchantLockParameters) = - merchantLock.validity() - - override fun visitConditional3dsAction( - conditional3dsAction: Conditional3dsActionParameters - ) = conditional3dsAction.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - - override fun toString(): String = - when { - conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" - velocityLimitParams != null -> - "Parameters{velocityLimitParams=$velocityLimitParams}" - merchantLock != null -> "Parameters{merchantLock=$merchantLock}" - conditional3dsAction != null -> - "Parameters{conditional3dsAction=$conditional3dsAction}" - _json != null -> "Parameters{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Parameters") - } - - companion object { - - @JvmStatic - fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = - Parameters(conditionalBlock = conditionalBlock) - - @JvmStatic - fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = - Parameters(velocityLimitParams = velocityLimitParams) - - @JvmStatic - fun ofMerchantLock(merchantLock: MerchantLockParameters) = - Parameters(merchantLock = merchantLock) - - @JvmStatic - fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = - Parameters(conditional3dsAction = conditional3dsAction) - } - - /** - * 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 - - /** - * 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) }, - ) - .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._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Parameters") - } - } - } - - class MerchantLockParameters - private constructor( - private val merchants: JsonField>, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("merchants") - @ExcludeMissing - merchants: JsonField> = JsonMissing.of() - ) : this(merchants, mutableMapOf()) - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - * - * @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 merchants(): List = merchants.getRequired("merchants") - - /** - * Returns the raw JSON value of [merchants]. - * - * Unlike [merchants], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("merchants") - @ExcludeMissing - fun _merchants(): JsonField> = merchants - - @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 - * [MerchantLockParameters]. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [MerchantLockParameters]. */ - class Builder internal constructor() { - - private var merchants: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(merchantLockParameters: MerchantLockParameters) = apply { - merchants = merchantLockParameters.merchants.map { it.toMutableList() } - additionalProperties = - merchantLockParameters.additionalProperties.toMutableMap() - } - - /** - * A list of merchant locks defining specific merchants or groups of merchants - * (based on descriptors or IDs) that the lock applies to. - */ - fun merchants(merchants: List) = merchants(JsonField.of(merchants)) - - /** - * Sets [Builder.merchants] to an arbitrary JSON value. - * - * You should usually call [Builder.merchants] with a well-typed - * `List` value instead. This method is primarily for setting the - * field to an undocumented or not yet supported value. - */ - fun merchants(merchants: JsonField>) = apply { - this.merchants = merchants.map { it.toMutableList() } - } - - /** - * Adds a single [Merchant] to [merchants]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addMerchant(merchant: Merchant) = apply { - merchants = - (merchants ?: JsonField.of(mutableListOf())).also { - checkKnown("merchants", it).add(merchant) - } - } - - 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 [MerchantLockParameters]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .merchants() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): MerchantLockParameters = - MerchantLockParameters( - checkRequired("merchants", merchants).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): MerchantLockParameters = apply { - if (validated) { - return@apply - } - - merchants().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 = - (merchants.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - /** - * Represents a specific merchant lock based on their ID or descriptor. Each - * merchant object allows transaction rules to work at a granular level and requires - * at least one of merchant_id or descriptor. - */ - class Merchant - private constructor( - private val comment: JsonField, - private val descriptor: JsonField, - private val merchantId: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("comment") - @ExcludeMissing - comment: JsonField = JsonMissing.of(), - @JsonProperty("descriptor") - @ExcludeMissing - descriptor: JsonField = JsonMissing.of(), - @JsonProperty("merchant_id") - @ExcludeMissing - merchantId: JsonField = JsonMissing.of(), - ) : this(comment, descriptor, merchantId, mutableMapOf()) - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun comment(): Optional = comment.getOptional("comment") - - /** - * Short description of the merchant, often used to provide more human-readable - * context about the transaction merchant. This is typically the name or label - * shown on transaction summaries. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun descriptor(): Optional = descriptor.getOptional("descriptor") - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). This - * attribute specifies the merchant entity that will be locked or referenced for - * authorization rules. - * - * @throws LithicInvalidDataException if the JSON field has an unexpected type - * (e.g. if the server responded with an unexpected value). - */ - fun merchantId(): Optional = merchantId.getOptional("merchant_id") - - /** - * Returns the raw JSON value of [comment]. - * - * Unlike [comment], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("comment") - @ExcludeMissing - fun _comment(): JsonField = comment - - /** - * Returns the raw JSON value of [descriptor]. - * - * Unlike [descriptor], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("descriptor") - @ExcludeMissing - fun _descriptor(): JsonField = descriptor - - /** - * Returns the raw JSON value of [merchantId]. - * - * Unlike [merchantId], this method doesn't throw if the JSON field has an - * unexpected type. - */ - @JsonProperty("merchant_id") - @ExcludeMissing - fun _merchantId(): JsonField = merchantId - - @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 [Merchant]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Merchant]. */ - class Builder internal constructor() { - - private var comment: JsonField = JsonMissing.of() - private var descriptor: JsonField = JsonMissing.of() - private var merchantId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = - mutableMapOf() - - @JvmSynthetic - internal fun from(merchant: Merchant) = apply { - comment = merchant.comment - descriptor = merchant.descriptor - merchantId = merchant.merchantId - additionalProperties = merchant.additionalProperties.toMutableMap() - } - - /** - * A comment or explanation about the merchant, used internally for rule - * management purposes. - */ - fun comment(comment: String) = comment(JsonField.of(comment)) - - /** - * Sets [Builder.comment] to an arbitrary JSON value. - * - * You should usually call [Builder.comment] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun comment(comment: JsonField) = apply { this.comment = comment } - - /** - * Short description of the merchant, often used to provide more - * human-readable context about the transaction merchant. This is typically - * the name or label shown on transaction summaries. - */ - fun descriptor(descriptor: String) = descriptor(JsonField.of(descriptor)) - - /** - * Sets [Builder.descriptor] to an arbitrary JSON value. - * - * You should usually call [Builder.descriptor] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun descriptor(descriptor: JsonField) = apply { - this.descriptor = descriptor - } - - /** - * Unique alphanumeric identifier for the payment card acceptor (merchant). - * This attribute specifies the merchant entity that will be locked or - * referenced for authorization rules. - */ - fun merchantId(merchantId: String) = merchantId(JsonField.of(merchantId)) - - /** - * Sets [Builder.merchantId] to an arbitrary JSON value. - * - * You should usually call [Builder.merchantId] with a well-typed [String] - * value instead. This method is primarily for setting the field to an - * undocumented or not yet supported value. - */ - fun merchantId(merchantId: JsonField) = apply { - this.merchantId = merchantId - } - - 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 [Merchant]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Merchant = - Merchant( - comment, - descriptor, - merchantId, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Merchant = apply { - if (validated) { - return@apply - } - - comment() - descriptor() - merchantId() - 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 (comment.asKnown().isPresent) 1 else 0) + - (if (descriptor.asKnown().isPresent) 1 else 0) + - (if (merchantId.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Merchant && comment == other.comment && descriptor == other.descriptor && merchantId == other.merchantId && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(comment, descriptor, merchantId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Merchant{comment=$comment, descriptor=$descriptor, merchantId=$merchantId, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MerchantLockParameters && merchants == other.merchants && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(merchants, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "MerchantLockParameters{merchants=$merchants, additionalProperties=$additionalProperties}" + override fun equals(other: Any?): Boolean { + if (this === other) { + return true } - class Conditional3dsActionParameters - 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 - * [Conditional3dsActionParameters]. - * - * The following fields are required: - * ```java - * .action() - * .conditions() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Conditional3dsActionParameters]. */ - class Builder internal constructor() { - - private var action: JsonField? = null - private var conditions: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from( - conditional3dsActionParameters: Conditional3dsActionParameters - ) = apply { - action = conditional3dsActionParameters.action - conditions = - conditional3dsActionParameters.conditions.map { it.toMutableList() } - additionalProperties = - conditional3dsActionParameters.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 [Conditional3dsActionParameters]. - * - * 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(): Conditional3dsActionParameters = - Conditional3dsActionParameters( - checkRequired("action", action), - checkRequired("conditions", conditions).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } + return /* spotless:off */ other is CurrentVersion && parameters == other.parameters && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(parameters, version, additionalProperties) } + /* spotless:on */ - fun validate(): Conditional3dsActionParameters = apply { - if (validated) { - return@apply - } + override fun hashCode(): Int = hashCode - action().validate() - conditions().forEach { it.validate() } - validated = true - } + override fun toString() = + "CurrentVersion{parameters=$parameters, version=$version, additionalProperties=$additionalProperties}" + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + class DraftVersion + private constructor( + private val parameters: JsonField, + private val version: JsonField, + private val additionalProperties: MutableMap, + ) { - /** - * 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)) - } + @JsonCreator + private constructor( + @JsonProperty("parameters") + @ExcludeMissing + parameters: JsonField = JsonMissing.of(), + @JsonProperty("version") @ExcludeMissing version: JsonField = JsonMissing.of(), + ) : this(parameters, version, mutableMapOf()) - /** An enum containing [Action]'s known values. */ - enum class Known { - DECLINE, - CHALLENGE, - } + /** + * 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") - /** - * 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, - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + * + * @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 version(): Long = version.getRequired("version") - /** - * 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 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 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 the raw JSON value of [version]. + * + * Unlike [version], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - /** - * 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") - } + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - fun validate(): Action = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - known() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: LithicInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [DraftVersion]. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - /** - * 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 - } + /** A builder for [DraftVersion]. */ + class Builder internal constructor() { - return /* spotless:off */ other is Action && value == other.value /* spotless:on */ - } + private var parameters: JsonField? = null + private var version: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - override fun hashCode() = value.hashCode() + @JvmSynthetic + internal fun from(draftVersion: DraftVersion) = apply { + parameters = draftVersion.parameters + version = draftVersion.version + additionalProperties = draftVersion.additionalProperties.toMutableMap() + } - override fun toString() = value.toString() - } + /** Parameters for the Auth Rule */ + fun parameters(parameters: Parameters) = parameters(JsonField.of(parameters)) - class Condition - private constructor( - private val attribute: JsonField, - private val operation: JsonField, - private val value: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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 + } - @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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - * - * @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) - } + /** + * Alias for calling [parameters] with + * `Parameters.ofConditionalBlock(conditionalBlock)`. + */ + fun parameters(conditionalBlock: ConditionalBlockParameters) = + parameters(Parameters.ofConditionalBlock(conditionalBlock)) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Alias for calling [parameters] with + * `Parameters.ofVelocityLimitParams(velocityLimitParams)`. + */ + fun parameters(velocityLimitParams: VelocityLimitParams) = + parameters(Parameters.ofVelocityLimitParams(velocityLimitParams)) - fun toBuilder() = Builder().from(this) + /** Alias for calling [parameters] with `Parameters.ofMerchantLock(merchantLock)`. */ + fun parameters(merchantLock: MerchantLockParameters) = + parameters(Parameters.ofMerchantLock(merchantLock)) - companion object { + /** + * Alias for calling [parameters] with + * `Parameters.ofConditional3dsAction(conditional3dsAction)`. + */ + fun parameters(conditional3dsAction: Conditional3dsActionParameters) = + parameters(Parameters.ofConditional3dsAction(conditional3dsAction)) - /** - * Returns a mutable builder for constructing an instance of [Condition]. - */ - @JvmStatic fun builder() = Builder() - } + /** + * The version of the rule, this is incremented whenever the rule's parameters change. + */ + fun version(version: Long) = version(JsonField.of(version)) - /** 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() - } + /** + * Sets [Builder.version] to an arbitrary JSON value. + * + * You should usually call [Builder.version] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun version(version: JsonField) = apply { this.version = version } - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated - * with a given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 - } + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** 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 - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - /** 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 putAllAdditionalProperties( - additionalProperties: Map - ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns an immutable instance of [DraftVersion]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .parameters() + * .version() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DraftVersion = + DraftVersion( + checkRequired("parameters", parameters), + checkRequired("version", version), + additionalProperties.toMutableMap(), + ) + } - /** - * 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 - private var validated: Boolean = false + fun validate(): DraftVersion = apply { + if (validated) { + return@apply + } - fun validate(): Condition = apply { - if (validated) { - return@apply - } + parameters().validate() + version() + validated = true + } - attribute().ifPresent { it.validate() } - operation().ifPresent { it.validate() } - value().ifPresent { it.validate() } - validated = true - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - 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 = + (parameters.asKnown().getOrNull()?.validity() ?: 0) + + (if (version.asKnown().isPresent) 1 else 0) - /** - * 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. - * - `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. - * - `RISK_SCORE`: Network-provided score assessing risk level associated with a - * given authentication. 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. - * - `MESSAGE_CATEGORY`: The category of the authentication being processed. - */ - 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 TRANSACTION_AMOUNT = of("TRANSACTION_AMOUNT") - - @JvmField val RISK_SCORE = of("RISK_SCORE") - - @JvmField val MESSAGE_CATEGORY = of("MESSAGE_CATEGORY") - - @JvmStatic fun of(value: String) = Attribute(JsonField.of(value)) - } + /** 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 _json: JsonValue? = null, + ) { - /** An enum containing [Attribute]'s known values. */ - enum class Known { - MCC, - COUNTRY, - CURRENCY, - MERCHANT_ID, - DESCRIPTOR, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - } + fun conditionalBlock(): Optional = + Optional.ofNullable(conditionalBlock) - /** - * 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, - TRANSACTION_AMOUNT, - RISK_SCORE, - MESSAGE_CATEGORY, - /** - * An enum member indicating that [Attribute] was instantiated with an - * unknown value. - */ - _UNKNOWN, - } + fun velocityLimitParams(): Optional = + Optional.ofNullable(velocityLimitParams) - /** - * 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 - TRANSACTION_AMOUNT -> Value.TRANSACTION_AMOUNT - RISK_SCORE -> Value.RISK_SCORE - MESSAGE_CATEGORY -> Value.MESSAGE_CATEGORY - 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 - TRANSACTION_AMOUNT -> Known.TRANSACTION_AMOUNT - RISK_SCORE -> Known.RISK_SCORE - MESSAGE_CATEGORY -> Known.MESSAGE_CATEGORY - 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 merchantLock(): Optional = Optional.ofNullable(merchantLock) - 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 /* spotless:off */ other is Attribute && value == other.value /* spotless:on */ - } + fun conditional3dsAction(): Optional = + Optional.ofNullable(conditional3dsAction) - override fun hashCode() = value.hashCode() + fun isConditionalBlock(): Boolean = conditionalBlock != null - override fun toString() = value.toString() - } + fun isVelocityLimitParams(): Boolean = velocityLimitParams != null - /** The operation to apply to the attribute */ - class Operation - @JsonCreator - private constructor(private val value: JsonField) : Enum { + fun isMerchantLock(): Boolean = merchantLock != 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 isConditional3dsAction(): Boolean = conditional3dsAction != null - companion object { + fun asConditionalBlock(): ConditionalBlockParameters = + conditionalBlock.getOrThrow("conditionalBlock") - @JvmField val IS_ONE_OF = of("IS_ONE_OF") + fun asVelocityLimitParams(): VelocityLimitParams = + velocityLimitParams.getOrThrow("velocityLimitParams") - @JvmField val IS_NOT_ONE_OF = of("IS_NOT_ONE_OF") + fun asMerchantLock(): MerchantLockParameters = merchantLock.getOrThrow("merchantLock") - @JvmField val MATCHES = of("MATCHES") + fun asConditional3dsAction(): Conditional3dsActionParameters = + conditional3dsAction.getOrThrow("conditional3dsAction") - @JvmField val DOES_NOT_MATCH = of("DOES_NOT_MATCH") + fun _json(): Optional = Optional.ofNullable(_json) - @JvmField val IS_GREATER_THAN = of("IS_GREATER_THAN") + fun accept(visitor: Visitor): T = + when { + conditionalBlock != null -> visitor.visitConditionalBlock(conditionalBlock) + velocityLimitParams != null -> + visitor.visitVelocityLimitParams(velocityLimitParams) + merchantLock != null -> visitor.visitMerchantLock(merchantLock) + conditional3dsAction != null -> + visitor.visitConditional3dsAction(conditional3dsAction) + else -> visitor.unknown(_json) + } - @JvmField val IS_LESS_THAN = of("IS_LESS_THAN") + private var validated: Boolean = false - @JvmStatic fun of(value: String) = Operation(JsonField.of(value)) - } + fun validate(): Parameters = apply { + if (validated) { + return@apply + } - /** An enum containing [Operation]'s known values. */ - enum class Known { - IS_ONE_OF, - IS_NOT_ONE_OF, - MATCHES, - DOES_NOT_MATCH, - IS_GREATER_THAN, - IS_LESS_THAN, + accept( + object : Visitor { + override fun visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) { + conditionalBlock.validate() } - /** - * 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_GREATER_THAN, - IS_LESS_THAN, - /** - * An enum member indicating that [Operation] was instantiated with an - * unknown value. - */ - _UNKNOWN, + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) { + velocityLimitParams.validate() } - /** - * 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_GREATER_THAN -> Value.IS_GREATER_THAN - IS_LESS_THAN -> Value.IS_LESS_THAN - 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_GREATER_THAN -> Known.IS_GREATER_THAN - IS_LESS_THAN -> Known.IS_LESS_THAN - 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 + override fun visitMerchantLock(merchantLock: MerchantLockParameters) { + merchantLock.validate() } - 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 /* spotless:off */ other is Operation && value == other.value /* spotless:on */ + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) { + conditional3dsAction.validate() } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() } + ) + validated = true + } - /** 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` or `IS_LESS_THAN` */ - 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") + fun isValid(): Boolean = + try { + validate() + true + } catch (e: LithicInvalidDataException) { + false + } - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - fun asNumber(): Long = number.getOrThrow("number") + /** + * 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 visitConditionalBlock( + conditionalBlock: ConditionalBlockParameters + ) = conditionalBlock.validity() - /** An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` */ - fun asListOfStrings(): List = - listOfStrings.getOrThrow("listOfStrings") + override fun visitVelocityLimitParams( + velocityLimitParams: VelocityLimitParams + ) = velocityLimitParams.validity() - fun _json(): Optional = Optional.ofNullable(_json) + override fun visitMerchantLock(merchantLock: MerchantLockParameters) = + merchantLock.validity() - 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) - } + override fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ) = conditional3dsAction.validity() - private var validated: Boolean = false + override fun unknown(json: JsonValue?) = 0 + } + ) - fun validate(): Value = apply { - if (validated) { - return@apply - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - accept( - object : Visitor { - override fun visitRegex(regex: String) {} + return /* spotless:off */ other is Parameters && conditionalBlock == other.conditionalBlock && velocityLimitParams == other.velocityLimitParams && merchantLock == other.merchantLock && conditional3dsAction == other.conditional3dsAction /* spotless:on */ + } - override fun visitNumber(number: Long) {} + override fun hashCode(): Int = /* spotless:off */ Objects.hash(conditionalBlock, velocityLimitParams, merchantLock, conditional3dsAction) /* spotless:on */ - override fun visitListOfStrings(listOfStrings: List) {} - } - ) - validated = true - } + override fun toString(): String = + when { + conditionalBlock != null -> "Parameters{conditionalBlock=$conditionalBlock}" + velocityLimitParams != null -> + "Parameters{velocityLimitParams=$velocityLimitParams}" + merchantLock != null -> "Parameters{merchantLock=$merchantLock}" + conditional3dsAction != null -> + "Parameters{conditional3dsAction=$conditional3dsAction}" + _json != null -> "Parameters{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Parameters") + } - 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 - } - ) + companion object { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + @JvmStatic + fun ofConditionalBlock(conditionalBlock: ConditionalBlockParameters) = + Parameters(conditionalBlock = conditionalBlock) - return /* spotless:off */ other is Value && regex == other.regex && number == other.number && listOfStrings == other.listOfStrings /* spotless:on */ - } + @JvmStatic + fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) = + Parameters(velocityLimitParams = velocityLimitParams) - override fun hashCode(): Int = /* spotless:off */ Objects.hash(regex, number, listOfStrings) /* spotless:on */ + @JvmStatic + fun ofMerchantLock(merchantLock: MerchantLockParameters) = + Parameters(merchantLock = merchantLock) - 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") - } + @JvmStatic + fun ofConditional3dsAction(conditional3dsAction: Conditional3dsActionParameters) = + Parameters(conditional3dsAction = conditional3dsAction) + } - companion object { + /** + * An interface that defines how to map each variant of [Parameters] to a value of type + * [T]. + */ + interface Visitor { - /** A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH` */ - @JvmStatic fun ofRegex(regex: String) = Value(regex = regex) + fun visitConditionalBlock(conditionalBlock: ConditionalBlockParameters): T - /** A number, to be used with `IS_GREATER_THAN` or `IS_LESS_THAN` */ - @JvmStatic fun ofNumber(number: Long) = Value(number = number) + fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T - /** - * An array of strings, to be used with `IS_ONE_OF` or `IS_NOT_ONE_OF` - */ - @JvmStatic - fun ofListOfStrings(listOfStrings: List) = - Value(listOfStrings = listOfStrings) - } + fun visitMerchantLock(merchantLock: MerchantLockParameters): T - /** - * 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` or `IS_LESS_THAN` */ - 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") - } - } + fun visitConditional3dsAction( + conditional3dsAction: Conditional3dsActionParameters + ): T - 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() - } - } - } + /** + * 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 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") - } - } - } - } + internal class Deserializer : BaseDeserializer(Parameters::class) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun ObjectCodec.deserialize(node: JsonNode): Parameters { + val json = JsonValue.fromJsonNode(node) - return /* spotless:off */ other is Condition && attribute == other.attribute && operation == other.operation && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + 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) }, + ) + .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() } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(attribute, operation, value, additionalProperties) } - /* spotless:on */ - - 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 - } + internal class Serializer : BaseSerializer(Parameters::class) { - return /* spotless:off */ other is Conditional3dsActionParameters && action == other.action && conditions == other.conditions && additionalProperties == other.additionalProperties /* spotless:on */ + 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._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Parameters") + } } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(action, conditions, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Conditional3dsActionParameters{action=$action, conditions=$conditions, additionalProperties=$additionalProperties}" } } diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/core/ClientOptionsTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/core/ClientOptionsTest.kt index 75e472f33..b2e104573 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/core/ClientOptionsTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/core/ClientOptionsTest.kt @@ -14,9 +14,10 @@ import org.mockito.kotlin.verify @ExtendWith(MockitoExtension::class) internal class ClientOptionsTest { + private val httpClient = mock() + @Test fun toBuilder_whenOriginalClientOptionsGarbageCollected_doesNotCloseOriginalClient() { - val httpClient = mock() var clientOptions = ClientOptions.builder().httpClient(httpClient).apiKey("My Lithic API Key").build() verify(httpClient, never()).close() diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/Conditional3dsActionParametersTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/Conditional3dsActionParametersTest.kt new file mode 100644 index 000000000..a098cd990 --- /dev/null +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/Conditional3dsActionParametersTest.kt @@ -0,0 +1,62 @@ +// 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 Conditional3dsActionParametersTest { + + @Test + fun create() { + val conditional3dsActionParameters = + Conditional3dsActionParameters.builder() + .action(Conditional3dsActionParameters.Action.DECLINE) + .addCondition( + Conditional3dsActionParameters.Condition.builder() + .attribute(Conditional3dsActionParameters.Condition.Attribute.MCC) + .operation(Conditional3dsActionParameters.Condition.Operation.IS_ONE_OF) + .value("string") + .build() + ) + .build() + + assertThat(conditional3dsActionParameters.action()) + .isEqualTo(Conditional3dsActionParameters.Action.DECLINE) + assertThat(conditional3dsActionParameters.conditions()) + .containsExactly( + Conditional3dsActionParameters.Condition.builder() + .attribute(Conditional3dsActionParameters.Condition.Attribute.MCC) + .operation(Conditional3dsActionParameters.Condition.Operation.IS_ONE_OF) + .value("string") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val conditional3dsActionParameters = + Conditional3dsActionParameters.builder() + .action(Conditional3dsActionParameters.Action.DECLINE) + .addCondition( + Conditional3dsActionParameters.Condition.builder() + .attribute(Conditional3dsActionParameters.Condition.Attribute.MCC) + .operation(Conditional3dsActionParameters.Condition.Operation.IS_ONE_OF) + .value("string") + .build() + ) + .build() + + val roundtrippedConditional3dsActionParameters = + jsonMapper.readValue( + jsonMapper.writeValueAsString(conditional3dsActionParameters), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConditional3dsActionParameters) + .isEqualTo(conditional3dsActionParameters) + } +} diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponseTest.kt index 82668f5bf..436c9b7bc 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountCreateResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountCreateResponseTest { .ownerType(ExternalBankAccountCreateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountCreateResponse.State.ENABLED) - .type(ExternalBankAccountCreateResponse.Type.CHECKING) + .type(ExternalBankAccountCreateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountCreateResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountCreateResponse.VerificationState.PENDING) @@ -62,7 +62,7 @@ internal class ExternalBankAccountCreateResponseTest { assertThat(externalBankAccountCreateResponse.state()) .isEqualTo(ExternalBankAccountCreateResponse.State.ENABLED) assertThat(externalBankAccountCreateResponse.type()) - .isEqualTo(ExternalBankAccountCreateResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountCreateResponse.AccountType.CHECKING) assertThat(externalBankAccountCreateResponse.verificationAttempts()).isEqualTo(0L) assertThat(externalBankAccountCreateResponse.verificationMethod()) .isEqualTo(ExternalBankAccountCreateResponse.VerificationMethod.MANUAL) @@ -107,7 +107,7 @@ internal class ExternalBankAccountCreateResponseTest { .ownerType(ExternalBankAccountCreateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountCreateResponse.State.ENABLED) - .type(ExternalBankAccountCreateResponse.Type.CHECKING) + .type(ExternalBankAccountCreateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountCreateResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountCreateResponse.VerificationState.PENDING) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListPageResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListPageResponseTest.kt index fcd237f76..952b9bfb1 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListPageResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListPageResponseTest.kt @@ -26,7 +26,7 @@ internal class ExternalBankAccountListPageResponseTest { .ownerType(ExternalBankAccountListResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountListResponse.State.ENABLED) - .type(ExternalBankAccountListResponse.Type.CHECKING) + .type(ExternalBankAccountListResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod( ExternalBankAccountListResponse.VerificationMethod.MANUAL @@ -69,7 +69,7 @@ internal class ExternalBankAccountListPageResponseTest { .ownerType(ExternalBankAccountListResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountListResponse.State.ENABLED) - .type(ExternalBankAccountListResponse.Type.CHECKING) + .type(ExternalBankAccountListResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountListResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountListResponse.VerificationState.PENDING) @@ -112,7 +112,7 @@ internal class ExternalBankAccountListPageResponseTest { .ownerType(ExternalBankAccountListResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountListResponse.State.ENABLED) - .type(ExternalBankAccountListResponse.Type.CHECKING) + .type(ExternalBankAccountListResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod( ExternalBankAccountListResponse.VerificationMethod.MANUAL diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListResponseTest.kt index e86cb03aa..5187e76a3 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountListResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountListResponseTest { .ownerType(ExternalBankAccountListResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountListResponse.State.ENABLED) - .type(ExternalBankAccountListResponse.Type.CHECKING) + .type(ExternalBankAccountListResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountListResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountListResponse.VerificationState.PENDING) @@ -62,7 +62,7 @@ internal class ExternalBankAccountListResponseTest { assertThat(externalBankAccountListResponse.state()) .isEqualTo(ExternalBankAccountListResponse.State.ENABLED) assertThat(externalBankAccountListResponse.type()) - .isEqualTo(ExternalBankAccountListResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountListResponse.AccountType.CHECKING) assertThat(externalBankAccountListResponse.verificationAttempts()).isEqualTo(0L) assertThat(externalBankAccountListResponse.verificationMethod()) .isEqualTo(ExternalBankAccountListResponse.VerificationMethod.MANUAL) @@ -106,7 +106,7 @@ internal class ExternalBankAccountListResponseTest { .ownerType(ExternalBankAccountListResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountListResponse.State.ENABLED) - .type(ExternalBankAccountListResponse.Type.CHECKING) + .type(ExternalBankAccountListResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountListResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountListResponse.VerificationState.PENDING) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponseTest.kt index ea69281ac..ba2eae536 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetrieveResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountRetrieveResponseTest { .ownerType(ExternalBankAccountRetrieveResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountRetrieveResponse.State.ENABLED) - .type(ExternalBankAccountRetrieveResponse.Type.CHECKING) + .type(ExternalBankAccountRetrieveResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountRetrieveResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountRetrieveResponse.VerificationState.PENDING) @@ -62,7 +62,7 @@ internal class ExternalBankAccountRetrieveResponseTest { assertThat(externalBankAccountRetrieveResponse.state()) .isEqualTo(ExternalBankAccountRetrieveResponse.State.ENABLED) assertThat(externalBankAccountRetrieveResponse.type()) - .isEqualTo(ExternalBankAccountRetrieveResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountRetrieveResponse.AccountType.CHECKING) assertThat(externalBankAccountRetrieveResponse.verificationAttempts()).isEqualTo(0L) assertThat(externalBankAccountRetrieveResponse.verificationMethod()) .isEqualTo(ExternalBankAccountRetrieveResponse.VerificationMethod.MANUAL) @@ -108,7 +108,7 @@ internal class ExternalBankAccountRetrieveResponseTest { .ownerType(ExternalBankAccountRetrieveResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountRetrieveResponse.State.ENABLED) - .type(ExternalBankAccountRetrieveResponse.Type.CHECKING) + .type(ExternalBankAccountRetrieveResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountRetrieveResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountRetrieveResponse.VerificationState.PENDING) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponseTest.kt index 8afcd1ad7..098feece0 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryMicroDepositsResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountRetryMicroDepositsResponseTest { .ownerType(ExternalBankAccountRetryMicroDepositsResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountRetryMicroDepositsResponse.State.ENABLED) - .type(ExternalBankAccountRetryMicroDepositsResponse.Type.CHECKING) + .type(ExternalBankAccountRetryMicroDepositsResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod( ExternalBankAccountRetryMicroDepositsResponse.VerificationMethod.MANUAL @@ -67,7 +67,7 @@ internal class ExternalBankAccountRetryMicroDepositsResponseTest { assertThat(externalBankAccountRetryMicroDepositsResponse.state()) .isEqualTo(ExternalBankAccountRetryMicroDepositsResponse.State.ENABLED) assertThat(externalBankAccountRetryMicroDepositsResponse.type()) - .isEqualTo(ExternalBankAccountRetryMicroDepositsResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountRetryMicroDepositsResponse.AccountType.CHECKING) assertThat(externalBankAccountRetryMicroDepositsResponse.verificationAttempts()) .isEqualTo(0L) assertThat(externalBankAccountRetryMicroDepositsResponse.verificationMethod()) @@ -115,7 +115,7 @@ internal class ExternalBankAccountRetryMicroDepositsResponseTest { .ownerType(ExternalBankAccountRetryMicroDepositsResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountRetryMicroDepositsResponse.State.ENABLED) - .type(ExternalBankAccountRetryMicroDepositsResponse.Type.CHECKING) + .type(ExternalBankAccountRetryMicroDepositsResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod( ExternalBankAccountRetryMicroDepositsResponse.VerificationMethod.MANUAL diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponseTest.kt index c76892654..25e22c403 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountRetryPrenoteResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountRetryPrenoteResponseTest { .ownerType(OwnerType.INDIVIDUAL) .routingNumber("routing_number") .state(ExternalBankAccountRetryPrenoteResponse.State.ENABLED) - .type(ExternalBankAccountRetryPrenoteResponse.Type.CHECKING) + .type(ExternalBankAccountRetryPrenoteResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(VerificationMethod.MANUAL) .verificationState( @@ -65,7 +65,7 @@ internal class ExternalBankAccountRetryPrenoteResponseTest { assertThat(externalBankAccountRetryPrenoteResponse.state()) .isEqualTo(ExternalBankAccountRetryPrenoteResponse.State.ENABLED) assertThat(externalBankAccountRetryPrenoteResponse.type()) - .isEqualTo(ExternalBankAccountRetryPrenoteResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountRetryPrenoteResponse.AccountType.CHECKING) assertThat(externalBankAccountRetryPrenoteResponse.verificationAttempts()).isEqualTo(0L) assertThat(externalBankAccountRetryPrenoteResponse.verificationMethod()) .isEqualTo(VerificationMethod.MANUAL) @@ -112,7 +112,7 @@ internal class ExternalBankAccountRetryPrenoteResponseTest { .ownerType(OwnerType.INDIVIDUAL) .routingNumber("routing_number") .state(ExternalBankAccountRetryPrenoteResponse.State.ENABLED) - .type(ExternalBankAccountRetryPrenoteResponse.Type.CHECKING) + .type(ExternalBankAccountRetryPrenoteResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(VerificationMethod.MANUAL) .verificationState( diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponseTest.kt index 08f9fc843..65c0a53d7 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountUpdateResponseTest.kt @@ -24,7 +24,7 @@ internal class ExternalBankAccountUpdateResponseTest { .ownerType(ExternalBankAccountUpdateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountUpdateResponse.State.ENABLED) - .type(ExternalBankAccountUpdateResponse.Type.CHECKING) + .type(ExternalBankAccountUpdateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountUpdateResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountUpdateResponse.VerificationState.PENDING) @@ -62,7 +62,7 @@ internal class ExternalBankAccountUpdateResponseTest { assertThat(externalBankAccountUpdateResponse.state()) .isEqualTo(ExternalBankAccountUpdateResponse.State.ENABLED) assertThat(externalBankAccountUpdateResponse.type()) - .isEqualTo(ExternalBankAccountUpdateResponse.Type.CHECKING) + .isEqualTo(ExternalBankAccountUpdateResponse.AccountType.CHECKING) assertThat(externalBankAccountUpdateResponse.verificationAttempts()).isEqualTo(0L) assertThat(externalBankAccountUpdateResponse.verificationMethod()) .isEqualTo(ExternalBankAccountUpdateResponse.VerificationMethod.MANUAL) @@ -107,7 +107,7 @@ internal class ExternalBankAccountUpdateResponseTest { .ownerType(ExternalBankAccountUpdateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(ExternalBankAccountUpdateResponse.State.ENABLED) - .type(ExternalBankAccountUpdateResponse.Type.CHECKING) + .type(ExternalBankAccountUpdateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(ExternalBankAccountUpdateResponse.VerificationMethod.MANUAL) .verificationState(ExternalBankAccountUpdateResponse.VerificationState.PENDING) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/MerchantLockParametersTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/MerchantLockParametersTest.kt new file mode 100644 index 000000000..819724323 --- /dev/null +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/MerchantLockParametersTest.kt @@ -0,0 +1,57 @@ +// 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 MerchantLockParametersTest { + + @Test + fun create() { + val merchantLockParameters = + MerchantLockParameters.builder() + .addMerchant( + MerchantLockParameters.Merchant.builder() + .comment("comment") + .descriptor("descriptor") + .merchantId("merchant_id") + .build() + ) + .build() + + assertThat(merchantLockParameters.merchants()) + .containsExactly( + MerchantLockParameters.Merchant.builder() + .comment("comment") + .descriptor("descriptor") + .merchantId("merchant_id") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val merchantLockParameters = + MerchantLockParameters.builder() + .addMerchant( + MerchantLockParameters.Merchant.builder() + .comment("comment") + .descriptor("descriptor") + .merchantId("merchant_id") + .build() + ) + .build() + + val roundtrippedMerchantLockParameters = + jsonMapper.readValue( + jsonMapper.writeValueAsString(merchantLockParameters), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMerchantLockParameters).isEqualTo(merchantLockParameters) + } +} diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/MicroDepositCreateResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/MicroDepositCreateResponseTest.kt index e9d063bb3..38d3aacc0 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/MicroDepositCreateResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/MicroDepositCreateResponseTest.kt @@ -24,7 +24,7 @@ internal class MicroDepositCreateResponseTest { .ownerType(MicroDepositCreateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(MicroDepositCreateResponse.State.ENABLED) - .type(MicroDepositCreateResponse.Type.CHECKING) + .type(MicroDepositCreateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(MicroDepositCreateResponse.VerificationMethod.MANUAL) .verificationState(MicroDepositCreateResponse.VerificationState.PENDING) @@ -62,7 +62,7 @@ internal class MicroDepositCreateResponseTest { assertThat(microDepositCreateResponse.state()) .isEqualTo(MicroDepositCreateResponse.State.ENABLED) assertThat(microDepositCreateResponse.type()) - .isEqualTo(MicroDepositCreateResponse.Type.CHECKING) + .isEqualTo(MicroDepositCreateResponse.AccountType.CHECKING) assertThat(microDepositCreateResponse.verificationAttempts()).isEqualTo(0L) assertThat(microDepositCreateResponse.verificationMethod()) .isEqualTo(MicroDepositCreateResponse.VerificationMethod.MANUAL) @@ -106,7 +106,7 @@ internal class MicroDepositCreateResponseTest { .ownerType(MicroDepositCreateResponse.OwnerType.BUSINESS) .routingNumber("routing_number") .state(MicroDepositCreateResponse.State.ENABLED) - .type(MicroDepositCreateResponse.Type.CHECKING) + .type(MicroDepositCreateResponse.AccountType.CHECKING) .verificationAttempts(0L) .verificationMethod(MicroDepositCreateResponse.VerificationMethod.MANUAL) .verificationState(MicroDepositCreateResponse.VerificationState.PENDING) diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalListResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalListResponseTest.kt index 82525aeb2..58d139032 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalListResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalListResponseTest.kt @@ -27,6 +27,7 @@ internal class NetworkTotalListResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalListResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") @@ -50,6 +51,7 @@ internal class NetworkTotalListResponseTest { .isEqualTo(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) assertThat(networkTotalListResponse.currency()).isEqualTo("CAD") assertThat(networkTotalListResponse.institutionId()).isEqualTo("1000000000") + assertThat(networkTotalListResponse.isComplete()).isEqualTo(true) assertThat(networkTotalListResponse.network()) .isEqualTo(NetworkTotalListResponse.Network.VISA) assertThat(networkTotalListResponse.reportDate()).isEqualTo(LocalDate.parse("2025-02-25")) @@ -77,6 +79,7 @@ internal class NetworkTotalListResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalListResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponseTest.kt index 63594fc65..256d8da4f 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/NetworkTotalRetrieveResponseTest.kt @@ -27,6 +27,7 @@ internal class NetworkTotalRetrieveResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalRetrieveResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") @@ -50,6 +51,7 @@ internal class NetworkTotalRetrieveResponseTest { .isEqualTo(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) assertThat(networkTotalRetrieveResponse.currency()).isEqualTo("CAD") assertThat(networkTotalRetrieveResponse.institutionId()).isEqualTo("1000000000") + assertThat(networkTotalRetrieveResponse.isComplete()).isEqualTo(true) assertThat(networkTotalRetrieveResponse.network()) .isEqualTo(NetworkTotalRetrieveResponse.Network.VISA) assertThat(networkTotalRetrieveResponse.reportDate()) @@ -78,6 +80,7 @@ internal class NetworkTotalRetrieveResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalRetrieveResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") diff --git a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ReportSettlementNetworkTotalListPageResponseTest.kt b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ReportSettlementNetworkTotalListPageResponseTest.kt index 6295e8ebf..3716902fd 100644 --- a/lithic-java-core/src/test/kotlin/com/lithic/api/models/ReportSettlementNetworkTotalListPageResponseTest.kt +++ b/lithic-java-core/src/test/kotlin/com/lithic/api/models/ReportSettlementNetworkTotalListPageResponseTest.kt @@ -29,6 +29,7 @@ internal class ReportSettlementNetworkTotalListPageResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalListResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") @@ -55,6 +56,7 @@ internal class ReportSettlementNetworkTotalListPageResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalListResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") @@ -85,6 +87,7 @@ internal class ReportSettlementNetworkTotalListPageResponseTest { .created(OffsetDateTime.parse("2025-02-25T13:07:31.419631Z")) .currency("CAD") .institutionId("1000000000") + .isComplete(true) .network(NetworkTotalListResponse.Network.VISA) .reportDate(LocalDate.parse("2025-02-25")) .settlementInstitutionId("1000000001") 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 807cc273e..68c73d861 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 @@ -238,6 +238,7 @@ internal class TransactionListPageResponseTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard( @@ -483,6 +484,7 @@ internal class TransactionListPageResponseTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard( @@ -747,6 +749,7 @@ internal class TransactionListPageResponseTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard( 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 badcbee63..62512a762 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 @@ -210,6 +210,7 @@ internal class TransactionTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard( @@ -441,6 +442,7 @@ internal class TransactionTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard( @@ -674,6 +676,7 @@ internal class TransactionTest { .build() ) .type(Transaction.TransactionEvent.Type.CLEARING) + .accountType(Transaction.TransactionEvent.AccountType.CHECKING) .networkSpecificData( Transaction.TransactionEvent.NetworkSpecificData.builder() .mastercard(