diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt index 2547819b..804c8b61 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt @@ -392,7 +392,7 @@ open class FinTsJobExecutor( // most TANs a valid 5 - 15 minutes. So terminate wait process after that time (tanChallenge.tanExpirationTime == null && now > tanChallenge.challengeCreationTimestamp.plusMinutes(15))) { if (tanChallenge.isEnteringTanDone == false) { - tanChallenge.userDidNotEnterTan() + tanChallenge.tanExpired() } break @@ -478,6 +478,8 @@ open class FinTsJobExecutor( } } + tanChallenge.tanExpired() + return null } diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt index d0b19cd7..5a8b6215 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt @@ -5,6 +5,7 @@ import net.codinux.banking.fints.extensions.nowExt import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMedium import net.codinux.banking.fints.response.BankResponse import net.codinux.banking.fints.response.client.FinTsClientResponse +import net.codinux.log.Log open class TanChallenge( @@ -30,6 +31,8 @@ open class TanChallenge( open val isEnteringTanDone: Boolean get() = enterTanResult != null + private val tanExpiredCallbacks = mutableListOf<() -> Unit>() + private val userApprovedDecoupledTanCallbacks = mutableListOf<() -> Unit>() @@ -40,7 +43,13 @@ open class TanChallenge( internal fun userApprovedDecoupledTan(responseAfterApprovingDecoupledTan: BankResponse) { this.enterTanResult = EnterTanResult(null, true, responseAfterApprovingDecoupledTan) - userApprovedDecoupledTanCallbacks.forEach { it.invoke() } + userApprovedDecoupledTanCallbacks.forEach { + try { + it.invoke() + } catch (e: Throwable) { + Log.error(e) { "Could not call userApprovedDecoupledTanCallback" } + } + } clearUserApprovedDecoupledTanCallbacks() } @@ -50,6 +59,20 @@ open class TanChallenge( this.enterTanResult = EnterTanResult(null) } + internal fun tanExpired() { + tanExpiredCallbacks.forEach { + try { + it.invoke() + } catch (e: Throwable) { + Log.error(e) { "Could not call tanExpiredCallback" } + } + } + + clearTanExpiredCallbacks() + + userDidNotEnterTan() + } + fun userAsksToChangeTanMethod(changeTanMethodTo: TanMethod) { clearUserApprovedDecoupledTanCallbacks() @@ -63,6 +86,16 @@ open class TanChallenge( } + fun addTanExpiredCallback(callback: () -> Unit) { + if (isEnteringTanDone == false) { + this.tanExpiredCallbacks.add(callback) + } + } + + protected open fun clearTanExpiredCallbacks() { + tanExpiredCallbacks.clear() + } + fun addUserApprovedDecoupledTanCallback(callback: () -> Unit) { if (isEnteringTanDone == false) { this.userApprovedDecoupledTanCallbacks.add(callback)