From ce6f548cebbf2e6c9c2cd9bf6d4ec5680cf3be2b Mon Sep 17 00:00:00 2001 From: dankl Date: Wed, 1 Jan 2020 20:59:15 +0100 Subject: [PATCH] When adding a new account selecting now a default TAN procedure, could remove FinTsClientCallback.askUserForTanProcedure() therefore --- .../fints4java/android/MainActivity.kt | 10 +++---- .../android/mapper/fints4javaModelMapper.kt | 10 +++++++ .../kotlin/net/dankito/fints/FinTsClient.kt | 28 +++++-------------- .../net/dankito/fints/FinTsClientCallback.kt | 7 +++-- .../net/dankito/fints/java/JavaShowcase.java | 7 ----- .../net/dankito/fints/FinTsClientTest.kt | 7 ----- 6 files changed, 25 insertions(+), 44 deletions(-) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt index 22fd9e91..f2d07237 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt @@ -15,7 +15,10 @@ import net.dankito.banking.fints4java.android.ui.dialogs.EnterAtcDialog import net.dankito.banking.fints4java.android.ui.dialogs.EnterTanDialog import net.dankito.fints.FinTsClientCallback import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium -import net.dankito.fints.model.* +import net.dankito.fints.model.CustomerData +import net.dankito.fints.model.EnterTanGeneratorAtcResult +import net.dankito.fints.model.EnterTanResult +import net.dankito.fints.model.TanChallenge import java.util.concurrent.CountDownLatch import java.util.concurrent.atomic.AtomicReference @@ -26,11 +29,6 @@ class MainActivity : AppCompatActivity() { val presenter = MainWindowPresenter(Base64ServiceAndroid(), object : FinTsClientCallback { - override fun askUserForTanProcedure(supportedTanProcedures: List): TanProcedure? { - // TODO: show dialog and ask user - return supportedTanProcedures.first() - } - override fun enterTan(customer: CustomerData, tanChallenge: TanChallenge): EnterTanResult { return getTanFromUserOffUiThread(customer, tanChallenge) } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/mapper/fints4javaModelMapper.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/mapper/fints4javaModelMapper.kt index 66229e62..c61709db 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/mapper/fints4javaModelMapper.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/mapper/fints4javaModelMapper.kt @@ -22,6 +22,12 @@ open class fints4javaModelMapper { account.bankAccounts = mapBankAccounts(account, customer.accounts) account.supportedTanProcedures = mapTanProcedures(customer.supportedTanProcedures) + if (customer.isTanProcedureSelected) { + account.selectedTanProcedure = findMappedTanProcedure(account, customer.selectedTanProcedure) + } + else { + account.selectedTanProcedure = null + } account.tanMedia = mapTanMediums(customer.tanMedia) return account @@ -90,6 +96,10 @@ open class fints4javaModelMapper { } } + protected open fun findMappedTanProcedure(account: Account, tanProcedure: net.dankito.fints.model.TanProcedure): TanProcedure? { + return account.supportedTanProcedures.firstOrNull { it.bankInternalProcedureCode == tanProcedure.securityFunction.code } + } + open fun mapTanMediums(tanMediums: List): List { return tanMediums.map { mapTanMedium(it) } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 9b34200f..3902ab05 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -136,15 +136,6 @@ open class FinTsClient @JvmOverloads constructor( } - // do not ask user for tan at this stage - var didOverwriteUserUnselectedTanProcedure = false - if (customer.isTanProcedureSelected == false && customer.supportedTanProcedures.isNotEmpty()) { - - didOverwriteUserUnselectedTanProcedure = true - customer.selectedTanProcedure = customer.supportedTanProcedures.first() - } - - val synchronizeCustomerResponse = synchronizeCustomerSystemId(bank, customer) getTanMediaList(bank, customer, TanMedienArtVersion.Alle, TanMediumKlasse.AlleMedien) @@ -152,11 +143,6 @@ open class FinTsClient @JvmOverloads constructor( // also check if retrieving account transactions of last 90 days without tan is supported (and thereby may retrieve first account transactions) val transactionsOfLast90DaysResponse = tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, false) - - if (didOverwriteUserUnselectedTanProcedure) { - customer.resetSelectedTanProcedure() - } - return AddAccountResponse(synchronizeCustomerResponse.toResponse(), bank, customer, transactionsOfLast90DaysResponse.isSuccessful, transactionsOfLast90DaysResponse.bookedTransactions, @@ -509,8 +495,6 @@ open class FinTsClient @JvmOverloads constructor( protected open fun ensureBasicBankDataRetrieved(bank: BankData, customer: CustomerData): Response { if (bank.supportedTanProcedures.isEmpty() || bank.supportedJobs.isEmpty()) { - bank.resetBpdVersion() - val getBankInfoResponse = getBankAndCustomerInfoForNewUser(bank, customer) if (getBankInfoResponse.isSuccessful == false || bank.supportedTanProcedures.isEmpty() @@ -533,11 +517,6 @@ open class FinTsClient @JvmOverloads constructor( if (customer.supportedTanProcedures.isEmpty()) { // could not retrieve supported tan procedures for user return Response(false, noTanProcedureSelected = true) } - - // we know user's supported tan procedure, now ask user which one to select - callback.askUserForTanProcedure(customer.supportedTanProcedures)?.let { - customer.selectedTanProcedure = it - } } return Response(customer.isTanProcedureSelected, noTanProcedureSelected = !!!customer.isTanProcedureSelected) @@ -810,6 +789,13 @@ open class FinTsClient @JvmOverloads constructor( if (response.supportedTanProceduresForUser.isNotEmpty()) { customer.supportedTanProcedures = response.supportedTanProceduresForUser.mapNotNull { findTanProcedure(it, bank) } + + if (customer.isTanProcedureSelected == false) { + (customer.supportedTanProcedures.firstOrNull { it.displayName.contains("manuell", true) == false } + ?: customer.supportedTanProcedures.firstOrNull())?.let { + customer.selectedTanProcedure = it + } + } } } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt index d539e458..70baaa5d 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt @@ -1,13 +1,14 @@ package net.dankito.fints import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium -import net.dankito.fints.model.* +import net.dankito.fints.model.CustomerData +import net.dankito.fints.model.EnterTanGeneratorAtcResult +import net.dankito.fints.model.EnterTanResult +import net.dankito.fints.model.TanChallenge interface FinTsClientCallback { - fun askUserForTanProcedure(supportedTanProcedures: List): TanProcedure? - fun enterTan(customer: CustomerData, tanChallenge: TanChallenge): EnterTanResult /** diff --git a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java index f25286a3..d05abb2c 100644 --- a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java +++ b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java @@ -33,13 +33,6 @@ public class JavaShowcase { customer.setSelectedTanProcedure(new TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTanOptisch)); FinTsClientCallback callback = new FinTsClientCallback() { - @Nullable - @Override - public TanProcedure askUserForTanProcedure(@NotNull List supportedTanProcedures) { - // TODO: if entering TAN is required select your tan procedure here - return supportedTanProcedures.get(0); - } - @Nullable @Override public EnterTanResult enterTan(@NotNull CustomerData customer, @NotNull TanChallenge tanChallenge) { diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index 36faa573..ae9d0433 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -30,13 +30,6 @@ class FinTsClientTest { private val callback = object : FinTsClientCallback { - override fun askUserForTanProcedure(supportedTanProcedures: List): TanProcedure? { - didAskUserForTanProcedure.set(true) - - // TODO: if entering TAN is required select your tan procedure here - return supportedTanProcedures.first() - } - override fun enterTan(customer: CustomerData, tanChallenge: TanChallenge): EnterTanResult { didAskUserToEnterTan.set(true)