Added model for handling TAN

This commit is contained in:
dankito 2024-08-18 17:13:01 +02:00
parent 1a13d5620f
commit eaf44b107b
17 changed files with 241 additions and 3 deletions

View File

@ -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"
}

View File

@ -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<T> protected constructor(
val type: ResponseType,
@ -17,6 +18,9 @@ open class Response<T> protected constructor(
fun <T> error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List<String> = emptyList()): Response<T> =
Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank))
fun <T> tanRequired(tanRequired: TanRequired): Response<T> =
Response(ResponseType.TanRequired, null, null, tanRequired)
fun <T> bankReturnedError(errorMessagesFromBank: List<String>): Response<T> =
Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank)
}

View File

@ -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"
}

View File

@ -0,0 +1,15 @@
package net.codinux.banking.client.model.tan
enum class ActionRequiringTan {
GetAnonymousBankInfo,
GetTanMedia,
ChangeTanMedium,
GetAccountInfo,
GetTransactions,
TransferMoney
}

View File

@ -0,0 +1,9 @@
package net.codinux.banking.client.model.tan
enum class AllowedTanFormat {
Numeric,
Alphanumeric,
TanIsEnteredOnOtherDevice
}

View File

@ -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
)

View File

@ -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"
}
}

View File

@ -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"
}

View File

@ -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"
}
}
}

View File

@ -0,0 +1,9 @@
package net.codinux.banking.client.model.tan
enum class TanChallengeType {
Image,
Flickercode,
EnterTan
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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"
}

View File

@ -0,0 +1,7 @@
package net.codinux.banking.client.model.tan
enum class TanMediumStatus {
Used,
Available
}

View File

@ -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
}

View File

@ -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})"
}

View File

@ -0,0 +1,23 @@
package net.codinux.banking.client.model.tan
enum class TanMethodType {
EnterTan,
ChipTanManuell,
ChipTanFlickercode,
ChipTanUsb,
ChipTanQrCode,
ChipTanPhotoTanMatrixCode,
SmsTan,
AppTan,
photoTan,
QrCode
}