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 b213fcef..56425241 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 @@ -21,6 +21,8 @@ open class TanChallenge( open val isEnteringTanDone: Boolean get() = enterTanResult != null + private val userApprovedDecoupledTanCallbacks = mutableListOf<() -> Unit>() + fun userEnteredTan(enteredTan: String) { this.enterTanResult = EnterTanResult(enteredTan.replace(" ", "")) @@ -28,6 +30,9 @@ open class TanChallenge( internal fun userApprovedDecoupledTan(responseAfterApprovingDecoupledTan: BankResponse) { this.enterTanResult = EnterTanResult(null, true, responseAfterApprovingDecoupledTan) + + userApprovedDecoupledTanCallbacks.forEach { it.invoke() } + userApprovedDecoupledTanCallbacks.clear() } fun userDidNotEnterTan() { @@ -43,6 +48,15 @@ open class TanChallenge( } + fun addUserApprovedDecoupledTanCallback(callback: () -> Unit) { + if (isEnteringTanDone == false) { + this.userApprovedDecoupledTanCallbacks.add(callback) + } else if (enterTanResult != null && enterTanResult!!.userApprovedDecoupledTan == true) { + callback() + } + } + + override fun toString(): String { return "$tanMethod (medium: $tanMediaIdentifier): $messageToShowToUser" }