From eaf44b107ba6c9c214aeff5abfb1055d96df92e1 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 18 Aug 2024 17:13:01 +0200 Subject: [PATCH] Added model for handling TAN --- .../client/model/request/EnterTanResultDto.kt | 10 +++++++ .../banking/client/model/response/Response.kt | 4 +++ .../client/model/response/TanRequired.kt | 6 ++--- .../client/model/tan/ActionRequiringTan.kt | 15 +++++++++++ .../client/model/tan/AllowedTanFormat.kt | 9 +++++++ .../client/model/tan/EnterTanResult.kt | 11 ++++++++ .../banking/client/model/tan/FlickerCode.kt | 26 +++++++++++++++++++ .../client/model/tan/MobilePhoneTanMedium.kt | 10 +++++++ .../banking/client/model/tan/TanChallenge.kt | 26 +++++++++++++++++++ .../client/model/tan/TanChallengeType.kt | 9 +++++++ .../client/model/tan/TanGeneratorTanMedium.kt | 10 +++++++ .../banking/client/model/tan/TanImage.kt | 26 +++++++++++++++++++ .../banking/client/model/tan/TanMedium.kt | 20 ++++++++++++++ .../client/model/tan/TanMediumStatus.kt | 7 +++++ .../banking/client/model/tan/TanMediumType.kt | 18 +++++++++++++ .../banking/client/model/tan/TanMethod.kt | 14 ++++++++++ .../banking/client/model/tan/TanMethodType.kt | 23 ++++++++++++++++ 17 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/EnterTanResultDto.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/ActionRequiringTan.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/AllowedTanFormat.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/EnterTanResult.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/FlickerCode.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/MobilePhoneTanMedium.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallengeType.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanGeneratorTanMedium.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanImage.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMedium.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumStatus.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumType.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethod.kt create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethodType.kt diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/EnterTanResultDto.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/EnterTanResultDto.kt new file mode 100644 index 00000000..1d5b9caf --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/EnterTanResultDto.kt @@ -0,0 +1,10 @@ +package net.codinux.banking.client.model.request + +import net.codinux.banking.client.model.tan.EnterTanResult + +class EnterTanResultDto( + val tanRequestId: String, + enteredTan: String? +) : EnterTanResult(enteredTan) { + override fun toString() = "$tanRequestId, entered Tan: $enteredTan" +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt index 5fb815b0..fb305f3f 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt @@ -2,6 +2,7 @@ package net.codinux.banking.client.model.response import net.codinux.banking.client.model.config.NoArgConstructor +// TODO: may differentiate between ClientResponse, which is either Success or Error, and RestResponse, which can be Success, Error and TanRequired @NoArgConstructor open class Response protected constructor( val type: ResponseType, @@ -17,6 +18,9 @@ open class Response protected constructor( fun error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List = emptyList()): Response = Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank)) + fun tanRequired(tanRequired: TanRequired): Response = + Response(ResponseType.TanRequired, null, null, tanRequired) + fun bankReturnedError(errorMessagesFromBank: List): Response = Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank) } diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TanRequired.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TanRequired.kt index 6abf4555..526f44ef 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TanRequired.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TanRequired.kt @@ -1,12 +1,12 @@ package net.codinux.banking.client.model.response import net.codinux.banking.client.model.config.NoArgConstructor +import net.codinux.banking.client.model.tan.TanChallenge @NoArgConstructor open class TanRequired ( val tanRequestId: String, - // TODO: add TAN model -// val tanChallenge: TanChallenge + val tanChallenge: TanChallenge ) { - + override fun toString() = "$tanChallenge" } \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/ActionRequiringTan.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/ActionRequiringTan.kt new file mode 100644 index 00000000..8af33f30 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/ActionRequiringTan.kt @@ -0,0 +1,15 @@ +package net.codinux.banking.client.model.tan + +enum class ActionRequiringTan { + GetAnonymousBankInfo, + + GetTanMedia, + + ChangeTanMedium, + + GetAccountInfo, + + GetTransactions, + + TransferMoney +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/AllowedTanFormat.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/AllowedTanFormat.kt new file mode 100644 index 00000000..985902e4 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/AllowedTanFormat.kt @@ -0,0 +1,9 @@ +package net.codinux.banking.client.model.tan + +enum class AllowedTanFormat { + Numeric, + + Alphanumeric, + + TanIsEnteredOnOtherDevice +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/EnterTanResult.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/EnterTanResult.kt new file mode 100644 index 00000000..07f999b5 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/EnterTanResult.kt @@ -0,0 +1,11 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class EnterTanResult( + val enteredTan: String?, +// val changeTanMethodTo: TanMethod? = null, +// val changeTanMediumTo: TanMedium? = null, +// val changeTanMediumResultCallback: ((BankingClientResponse) -> Unit)? = null +) \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/FlickerCode.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/FlickerCode.kt new file mode 100644 index 00000000..0a21d3d1 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/FlickerCode.kt @@ -0,0 +1,26 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.JsonIgnore +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class FlickerCode( + val challengeHHD_UC: String, + val parsedDataSet: String, + val decodingError: String? = null +) { + + @JsonIgnore + val decodingSuccessful: Boolean + get() = decodingError == null + + + override fun toString(): String { + if (decodingSuccessful == false) { + return "Decoding error: $decodingError" + } + + return "Parsed $challengeHHD_UC to $parsedDataSet" + } + +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/MobilePhoneTanMedium.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/MobilePhoneTanMedium.kt new file mode 100644 index 00000000..5c3f2d53 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/MobilePhoneTanMedium.kt @@ -0,0 +1,10 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class MobilePhoneTanMedium( + val phoneNumber: String? +) { + override fun toString() = phoneNumber ?: "No phone number" +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt new file mode 100644 index 00000000..eb525597 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt @@ -0,0 +1,26 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.CustomerAccount +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class TanChallenge( + val type: TanChallengeType, + val forAction: ActionRequiringTan, + val customer: CustomerAccount, + val messageToShowToUser: String, + val tanMethod: TanMethod, + val tanImage: TanImage? = null, + val flickerCode: FlickerCode? = null + // TODO: add availableTanMethods, selectedTanMedium, availableTanMedia +) { + + override fun toString(): String { + return "$tanMethod: $messageToShowToUser" + when (type) { + TanChallengeType.EnterTan -> "" + TanChallengeType.Image -> ", Image: $tanImage" + TanChallengeType.Flickercode -> ", FlickerCode: $flickerCode" + } + } + +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallengeType.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallengeType.kt new file mode 100644 index 00000000..fcc53a25 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallengeType.kt @@ -0,0 +1,9 @@ +package net.codinux.banking.client.model.tan + +enum class TanChallengeType { + Image, + + Flickercode, + + EnterTan +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanGeneratorTanMedium.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanGeneratorTanMedium.kt new file mode 100644 index 00000000..6aea9f96 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanGeneratorTanMedium.kt @@ -0,0 +1,10 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class TanGeneratorTanMedium( + val cardNumber: String +) { + override fun toString() = cardNumber +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanImage.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanImage.kt new file mode 100644 index 00000000..bc0cb512 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanImage.kt @@ -0,0 +1,26 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.JsonIgnore +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class TanImage( + val mimeType: String, + val imageBytesBase64: String, + val decodingError: String? = null +) { + + @JsonIgnore + val decodingSuccessful: Boolean + get() = decodingError == null + + + override fun toString(): String { + if (decodingSuccessful == false) { + return "Decoding error: $decodingError" + } + + return mimeType + } + +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMedium.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMedium.kt new file mode 100644 index 00000000..ce5817cb --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMedium.kt @@ -0,0 +1,20 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class TanMedium( + val type: TanMediumType, + val displayName: String, + val status: TanMediumStatus, + /** + * Only set if [type] is [TanMediumType.TanGenerator]. + */ + val tanGenerator: TanGeneratorTanMedium? = null, + /** + * Only set if [type] is [TanMediumType.MobilePhone]. + */ + val mobilePhone: MobilePhoneTanMedium? = null +) { + override fun toString() = "$displayName $status" +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumStatus.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumStatus.kt new file mode 100644 index 00000000..771ec25e --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumStatus.kt @@ -0,0 +1,7 @@ +package net.codinux.banking.client.model.tan + +enum class TanMediumStatus { + Used, + + Available +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumType.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumType.kt new file mode 100644 index 00000000..36d73ac0 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMediumType.kt @@ -0,0 +1,18 @@ +package net.codinux.banking.client.model.tan + +enum class TanMediumType { + /** + * All other TAN media, like AppTan. + */ + Generic, + + /** + * If I'm not wrong MobilePhone is only used for SmsTan. + */ + MobilePhone, + + /** + * Mostly used for chipTan. + */ + TanGenerator +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethod.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethod.kt new file mode 100644 index 00000000..6f1a740a --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethod.kt @@ -0,0 +1,14 @@ +package net.codinux.banking.client.model.tan + +import net.codinux.banking.client.model.config.NoArgConstructor + +@NoArgConstructor +open class TanMethod( + val displayName: String, + val type: TanMethodType, + val identifier: String, + val maxTanInputLength: Int? = null, + val allowedTanFormat: AllowedTanFormat = AllowedTanFormat.Alphanumeric +) { + override fun toString() = "$displayName ($type, ${identifier})" +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethodType.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethodType.kt new file mode 100644 index 00000000..725936b3 --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanMethodType.kt @@ -0,0 +1,23 @@ +package net.codinux.banking.client.model.tan + +enum class TanMethodType { + EnterTan, + + ChipTanManuell, + + ChipTanFlickercode, + + ChipTanUsb, + + ChipTanQrCode, + + ChipTanPhotoTanMatrixCode, + + SmsTan, + + AppTan, + + photoTan, + + QrCode +} \ No newline at end of file