Refactored handling TAN required methods
This commit is contained in:
parent
d18e939818
commit
2889d1b0ce
|
@ -752,31 +752,13 @@ open class FinTsClient(
|
|||
callback(response)
|
||||
return
|
||||
}
|
||||
|
||||
else if (response.tanResponse != null) {
|
||||
response.tanResponse?.let { tanResponse ->
|
||||
val customer = dialogContext.customer
|
||||
val enteredTanResult = this.callback.enterTan(customer, createTanChallenge(tanResponse, customer))
|
||||
handleEnteringTanRequired(tanResponse, response, dialogContext, callback)
|
||||
}
|
||||
|
||||
if (enteredTanResult.changeTanProcedureTo != null) {
|
||||
handleUserAsksToChangeTanProcedureAndResendLastMessage(enteredTanResult.changeTanProcedureTo,
|
||||
dialogContext, callback)
|
||||
return
|
||||
}
|
||||
else if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) {
|
||||
handleUserAsksToChangeTanMediumAndResendLastMessage(enteredTanResult.changeTanMediumTo,
|
||||
dialogContext, enteredTanResult.changeTanMediumResultCallback, callback)
|
||||
return
|
||||
}
|
||||
else if (enteredTanResult.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.tanRequiredButUserDidNotEnterOne = true
|
||||
}
|
||||
else {
|
||||
sendTanToBank(enteredTanResult.enteredTan, tanResponse, dialogContext, callback)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if response contains '3931 TAN-Generator gesperrt, Synchronisierung erforderlich' or
|
||||
|
@ -789,6 +771,15 @@ open class FinTsClient(
|
|||
callback(response)
|
||||
}
|
||||
|
||||
protected open fun handleEnteringTanRequired(tanResponse: TanResponse, response: Response, dialogContext: DialogContext, callback: (Response) -> Unit) {
|
||||
val customer = dialogContext.customer // TODO: copy required data to TanChallenge
|
||||
val tanChallenge = createTanChallenge(tanResponse, customer)
|
||||
|
||||
val enteredTanResult = this.callback.enterTan(customer, tanChallenge) // TODO: add callback to be more flexible in regard to thread handling
|
||||
|
||||
handleEnterTanResult(enteredTanResult, tanResponse, response, dialogContext, callback)
|
||||
}
|
||||
|
||||
protected open fun createTanChallenge(tanResponse: TanResponse, customer: CustomerData): TanChallenge {
|
||||
// TODO: is this true for all tan procedures?
|
||||
val messageToShowToUser = tanResponse.challenge ?: ""
|
||||
|
@ -808,6 +799,28 @@ open class FinTsClient(
|
|||
}
|
||||
}
|
||||
|
||||
protected open fun handleEnterTanResult(enteredTanResult: EnterTanResult, tanResponse: TanResponse, response: Response,
|
||||
dialogContext: DialogContext, callback: (Response) -> Unit) {
|
||||
|
||||
if (enteredTanResult.changeTanProcedureTo != null) {
|
||||
handleUserAsksToChangeTanProcedureAndResendLastMessage(enteredTanResult.changeTanProcedureTo, dialogContext, callback)
|
||||
}
|
||||
else if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) {
|
||||
handleUserAsksToChangeTanMediumAndResendLastMessage(enteredTanResult.changeTanMediumTo, dialogContext,
|
||||
enteredTanResult.changeTanMediumResultCallback, callback)
|
||||
}
|
||||
else if (enteredTanResult.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.tanRequiredButUserDidNotEnterOne = true
|
||||
|
||||
callback(response)
|
||||
}
|
||||
else {
|
||||
sendTanToBank(enteredTanResult.enteredTan, tanResponse, dialogContext, callback)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun sendTanToBank(enteredTan: String, tanResponse: TanResponse, dialogContext: DialogContext, callback: (Response) -> Unit) {
|
||||
|
||||
val message = messageBuilder.createSendEnteredTanMessage(enteredTan, tanResponse, dialogContext)
|
||||
|
|
Loading…
Reference in New Issue