From 7670a912e8e223f34852f5acc870a72c4bf21bb8 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 16 Oct 2019 01:08:07 +0200 Subject: [PATCH] Started to implement infrastructure for entering tan --- .../kotlin/net/dankito/fints/FinTsClient.kt | 23 ++++++++++++++++--- .../ZweiSchrittTanEinreichung.kt | 2 +- .../net/dankito/fints/response/Response.kt | 6 +++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 3d9bb7ed..ed6c4dac 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -200,7 +200,7 @@ open class FinTsClient @JvmOverloads constructor( val message = messageBuilder.createGetTransactionsMessage(parameter, bank, customer, product, dialogData) - val response = getAndHandleResponseForMessage(message, bank) + val response = getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData) closeDialog(bank, customer, dialogData) @@ -255,9 +255,9 @@ open class FinTsClient @JvmOverloads constructor( dialogData.increaseMessageNumber() - val requestBody = messageBuilder.createBankTransferMessage(bankTransferData, bank, customer, dialogData) + val message = messageBuilder.createBankTransferMessage(bankTransferData, bank, customer, dialogData) - val response = getAndHandleResponseForMessage(requestBody, bank) + val response = getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData) closeDialog(bank, customer, dialogData) @@ -387,6 +387,13 @@ open class FinTsClient @JvmOverloads constructor( } + protected open fun getAndHandleResponseForMessageThatMayRequiresTan(message: MessageBuilderResult, bank: BankData, + customer: CustomerData, dialogData: DialogData): Response { + val response = getAndHandleResponseForMessage(message, bank) + + return handleMayRequiredTan(response, bank, customer, dialogData) + } + protected open fun getAndHandleResponseForMessage(message: MessageBuilderResult, bank: BankData): Response { message.createdMessage?.let { requestBody -> return getAndHandleResponseForMessage(requestBody, bank) @@ -433,6 +440,16 @@ open class FinTsClient @JvmOverloads constructor( return base64Service.decode(responseBody.replace("\r", "").replace("\n", "")) } + protected open fun handleMayRequiredTan(response: Response, bank: BankData, customer: CustomerData, dialogData: DialogData): Response { + if (response.isStrongAuthenticationRequired) { + response.tanResponse?.let { tanResponse -> + response.tanRequiredButNotProvided = true // TODO: show to user and wait for feedback + } + } + + return response + } + protected open fun updateBankData(bank: BankData, response: Response) { response.getFirstSegmentById(InstituteSegmentId.BankParameters)?.let { bankParameters -> diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/ZweiSchrittTanEinreichung.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/ZweiSchrittTanEinreichung.kt index d4078489..4fcc7410 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/ZweiSchrittTanEinreichung.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/ZweiSchrittTanEinreichung.kt @@ -29,7 +29,7 @@ open class ZweiSchrittTanEinreichung( AuftragsHashwert(jobHashValue ?: "", Existenzstatus.NotAllowed), // M: bei AuftragsHashwertverfahren<>0 und TAN-Prozess=1. N: sonst Auftragsreferenz(jobReference ?: "", Existenzstatus.Mandatory), // M: bei TAN-Prozess=2, 3, 4. O: bei TAN-Prozess=1 JaNein(furtherTanFollows, if (process == TanProcess.TanProcess1 || process == TanProcess.TanProcess2) Existenzstatus.Mandatory else Existenzstatus.NotAllowed), // M: bei TAN-Prozess=1, 2. N: bei TAN-Prozess=3, 4 - JaNein(cancelJob, if (process == TanProcess.TanProcess2 && furtherTanFollows != null) Existenzstatus.Optional else Existenzstatus.NotAllowed), // O: bei TAN-Prozess=2 und „Auftragsstorno erlaubt“=J. N: sonst + JaNein(cancelJob, if (process == TanProcess.TanProcess2 && cancelJob != null) Existenzstatus.Optional else Existenzstatus.NotAllowed), // O: bei TAN-Prozess=2 und „Auftragsstorno erlaubt“=J. N: sonst NotAllowedDatenelement(), // TODO: SMS-Abbuchungskonto // M: Bei TAN-Process=1, 3, 4 und „SMS-Abbuchungskonto erforderlich“=2. O: sonst NotAllowedDatenelement(), // TODO: Challenge-Klasse // M: bei TAN-Prozess=1 und „Challenge-Klasse erforderlich“=J. N: sonst NotAllowedDatenelement(), // TODO: Parameter Challenge-Klasse // O: Bei TAN-Process=1 „Challenge-Klasse erforderlich“=J. N: sonst diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt index d720cfdb..40db16bb 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt @@ -27,9 +27,11 @@ open class Response constructor( open val responseContainsErrors: Boolean get() = exception == null && messageFeedback?.isError == true + open var tanRequiredButNotProvided = false + open val successful: Boolean - get() = noTanProcedureSelected == false &&couldCreateMessage && didReceiveResponse - && responseContainsErrors == false + get() = noTanProcedureSelected == false && couldCreateMessage && didReceiveResponse + && responseContainsErrors == false && tanRequiredButNotProvided == false open val isStrongAuthenticationRequired: Boolean get() = tanResponse?.isStrongAuthenticationRequired == true