Added enterTan(TanChallenge) to FinTsClientCallback to get tan from user

This commit is contained in:
dankl 2019-10-16 14:11:19 +02:00 committed by dankito
parent 7670a912e8
commit 3afd257320
6 changed files with 45 additions and 9 deletions

View File

@ -4,10 +4,7 @@ import net.dankito.banking.fints4java.android.Base64ServiceAndroid
import net.dankito.fints.FinTsClient import net.dankito.fints.FinTsClient
import net.dankito.fints.FinTsClientCallback import net.dankito.fints.FinTsClientCallback
import net.dankito.fints.banks.BankFinder import net.dankito.fints.banks.BankFinder
import net.dankito.fints.model.BankData import net.dankito.fints.model.*
import net.dankito.fints.model.BankInfo
import net.dankito.fints.model.CustomerData
import net.dankito.fints.model.TanProcedure
import net.dankito.fints.model.mapper.BankDataMapper import net.dankito.fints.model.mapper.BankDataMapper
import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.FinTsClientResponse
import net.dankito.fints.response.client.GetTransactionsResponse import net.dankito.fints.response.client.GetTransactionsResponse
@ -24,6 +21,10 @@ open class MainWindowPresenter {
return supportedTanProcedures.first() return supportedTanProcedures.first()
} }
override fun enterTan(tanChallenge: TanChallenge): String? {
return null
}
} }
protected val finTsClient = FinTsClient(callback, Base64ServiceAndroid()) protected val finTsClient = FinTsClient(callback, Base64ServiceAndroid())

View File

@ -443,13 +443,29 @@ open class FinTsClient @JvmOverloads constructor(
protected open fun handleMayRequiredTan(response: Response, bank: BankData, customer: CustomerData, dialogData: DialogData): Response { protected open fun handleMayRequiredTan(response: Response, bank: BankData, customer: CustomerData, dialogData: DialogData): Response {
if (response.isStrongAuthenticationRequired) { if (response.isStrongAuthenticationRequired) {
response.tanResponse?.let { tanResponse -> response.tanResponse?.let { tanResponse ->
response.tanRequiredButNotProvided = true // TODO: show to user and wait for feedback // TODO: is this true for all tan procedures?
val enteredTan = callback.enterTan(TanChallenge(tanResponse.challenge ?: "",
tanResponse.challengeHHD_UC ?: "", CustomerData.TanProcedureNotSelected)) // TODO: retrieve tan procedure
if (enteredTan == null) {
// i tried to send a HKTAN with cancelJob = true but then i saw there are no tan procedures that support cancellation (at least not at my bank)
// but it's not required anyway, tan times out after some time. Simply don't respond anything and close dialog
response.tanRequiredButNotProvided = true
}
else {
return sendTanToBank(enteredTan, tanResponse)
}
} }
} }
return response return response
} }
protected open fun sendTanToBank(enteredTan: String, tanResponse: TanResponse): Response {
// TODO
return Response(false)
}
protected open fun updateBankData(bank: BankData, response: Response) { protected open fun updateBankData(bank: BankData, response: Response) {
response.getFirstSegmentById<BankParameters>(InstituteSegmentId.BankParameters)?.let { bankParameters -> response.getFirstSegmentById<BankParameters>(InstituteSegmentId.BankParameters)?.let { bankParameters ->

View File

@ -1,5 +1,6 @@
package net.dankito.fints package net.dankito.fints
import net.dankito.fints.model.TanChallenge
import net.dankito.fints.model.TanProcedure import net.dankito.fints.model.TanProcedure
@ -7,4 +8,6 @@ interface FinTsClientCallback {
fun askUserForTanProcedure(supportedTanProcedures: List<TanProcedure>): TanProcedure? fun askUserForTanProcedure(supportedTanProcedures: List<TanProcedure>): TanProcedure?
fun enterTan(tanChallenge: TanChallenge): String?
} }

View File

@ -0,0 +1,8 @@
package net.dankito.fints.model
open class TanChallenge(
val messageToShowToUser: String,
val tanChallenge: String,
val tanProcedure: TanProcedure
)

View File

@ -38,6 +38,13 @@ public class JavaShowcase {
// TODO: if entering TAN is required select your tan procedure here // TODO: if entering TAN is required select your tan procedure here
return supportedTanProcedures.get(0); return supportedTanProcedures.get(0);
} }
@Nullable
@Override
public String enterTan(@NotNull TanChallenge tanChallenge) {
return null;
}
}; };
FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service()); FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service());

View File

@ -4,14 +4,12 @@ import net.dankito.fints.messages.datenelemente.abgeleiteteformate.Laenderkennze
import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache
import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatus import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatus
import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatusWerte import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatusWerte
import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion
import net.dankito.fints.model.* import net.dankito.fints.model.*
import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.FinTsClientResponse
import net.dankito.fints.util.Java8Base64Service import net.dankito.fints.util.Java8Base64Service
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Ignore import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.util.*
@Ignore // not an automatic test, supply your settings below @Ignore // not an automatic test, supply your settings below
@ -24,6 +22,10 @@ class FinTsClientTest {
return supportedTanProcedures.first() return supportedTanProcedures.first()
} }
override fun enterTan(tanChallenge: TanChallenge): String? {
return null
}
} }
@ -40,8 +42,7 @@ class FinTsClientTest {
// TODO: add your settings here: // TODO: add your settings here:
private val Bank = BankData("", Laenderkennzeichen.Germany, "", bic = "") private val Bank = BankData("", Laenderkennzeichen.Germany, "", bic = "")
private val Customer = CustomerData("", "", name = "", iban = "", private val Customer = CustomerData("", "", iban = "")
selectedTanProcedure = TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTan))
// transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2 // transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2
private val BankTransferData = BankTransferData(Customer.name, Customer.iban!!, Bank.bic!!, 0.01.toBigDecimal(), "Give it to me baby") private val BankTransferData = BankTransferData(Customer.name, Customer.iban!!, Bank.bic!!, 0.01.toBigDecimal(), "Give it to me baby")