Fixed (once again) that Comdirect returns an error when fetching user's TAN procedure with TAN procedure code '999' but returns user's TAN procedures anyway

This commit is contained in:
dankito 2020-09-01 13:54:28 +02:00
parent 2b8c9316d0
commit 458da2a542
2 changed files with 38 additions and 11 deletions

View File

@ -15,10 +15,7 @@ import net.dankito.banking.fints.model.*
import net.dankito.banking.fints.response.InstituteSegmentId import net.dankito.banking.fints.response.InstituteSegmentId
import net.dankito.banking.fints.response.Response import net.dankito.banking.fints.response.Response
import net.dankito.banking.fints.response.ResponseParser import net.dankito.banking.fints.response.ResponseParser
import net.dankito.banking.fints.response.client.AddAccountResponse import net.dankito.banking.fints.response.client.*
import net.dankito.banking.fints.response.client.FinTsClientResponse
import net.dankito.banking.fints.response.client.GetTanMediaListResponse
import net.dankito.banking.fints.response.client.GetTransactionsResponse
import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.response.segments.*
import net.dankito.banking.fints.tan.FlickerCodeDecoder import net.dankito.banking.fints.tan.FlickerCodeDecoder
import net.dankito.banking.fints.tan.TanImageDecoder import net.dankito.banking.fints.tan.TanImageDecoder
@ -113,7 +110,7 @@ open class FinTsClient(
open fun getUsersTanProcedures(bank: BankData, customer: CustomerData, callback: (AddAccountResponse) -> Unit) { open fun getUsersTanProcedures(bank: BankData, customer: CustomerData, callback: (AddAccountResponse) -> Unit) {
// just to ensure settings are in its initial state and that bank sends use bank parameter (BPD), // just to ensure settings are in its initial state and that bank sends us bank parameter (BPD),
// user parameter (UPD) and allowed tan procedures for user (therefore the resetSelectedTanProcedure()) // user parameter (UPD) and allowed tan procedures for user (therefore the resetSelectedTanProcedure())
bank.resetBpdVersion() bank.resetBpdVersion()
customer.resetUpdVersion() customer.resetUpdVersion()
@ -138,17 +135,19 @@ open class FinTsClient(
} }
protected open fun handleGetUsersTanProceduresResponse(response: Response, dialogContext: DialogContext, callback: (AddAccountResponse) -> Unit) { protected open fun handleGetUsersTanProceduresResponse(response: Response, dialogContext: DialogContext, callback: (AddAccountResponse) -> Unit) {
if (response.successful) { // TODO: really update data only on complete successfully response? as it may contain useful information anyway // TODO: extract method for this code part val getUsersTanProceduresResponse = GetUserTanProceduresResponse(response)
updateBankData(dialogContext.bank, response)
updateCustomerData(dialogContext.customer, dialogContext.bank, response) if (getUsersTanProceduresResponse.successful) { // TODO: really update data only on complete successfully response? as it may contain useful information anyway // TODO: extract method for this code part
updateBankData(dialogContext.bank, getUsersTanProceduresResponse)
updateCustomerData(dialogContext.customer, dialogContext.bank, getUsersTanProceduresResponse)
} }
// even though it is required by specification some banks don't support retrieving user's TAN procedure by setting TAN procedure to '999' // even though it is required by specification some banks don't support retrieving user's TAN procedure by setting TAN procedure to '999'
if (bankDoesNotSupportRetrievingUsersTanProcedures(response)) { if (bankDoesNotSupportRetrievingUsersTanProcedures(getUsersTanProceduresResponse)) {
getBankAndCustomerInfoForNewUserViaAnonymousDialog(dialogContext.bank, dialogContext.customer, callback) // TODO: should not be necessary anymore getBankAndCustomerInfoForNewUserViaAnonymousDialog(dialogContext.bank, dialogContext.customer, callback) // TODO: should not be necessary anymore
} }
else { else {
callback(AddAccountResponse(response, dialogContext.bank, dialogContext.customer)) callback(AddAccountResponse(getUsersTanProceduresResponse, dialogContext.bank, dialogContext.customer))
} }
} }
@ -282,7 +281,9 @@ open class FinTsClient(
} }
} }
protected open fun addAccountGetAccountBalancesAndTransactions(customer: CustomerData, bank: BankData, newUserInfoResponse: AddAccountResponse, didOverwriteUserUnselectedTanProcedure: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, callback: (AddAccountResponse) -> Unit) { protected open fun addAccountGetAccountBalancesAndTransactions(customer: CustomerData, bank: BankData, newUserInfoResponse: AddAccountResponse,
didOverwriteUserUnselectedTanProcedure: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
callback: (AddAccountResponse) -> Unit) {
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>() val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
val balances = mutableMapOf<AccountData, Money>() val balances = mutableMapOf<AccountData, Money>()

View File

@ -0,0 +1,26 @@
package net.dankito.banking.fints.response.client
import net.dankito.banking.fints.response.Response
open class GetUserTanProceduresResponse(bankResponse: Response)
: Response(bankResponse.didReceiveResponse, bankResponse.receivedResponse, bankResponse.receivedSegments,
bankResponse.errorMessage, bankResponse.noTanProcedureSelected, bankResponse.messageCreationError) {
/**
* comdirect sends "9955::Unzulässiges TAN-Verfahren." even though '999' is a valid TAN procedure
* for init dialog if user's TAN procedures are not known yet
* -> check if the only error is '9955', then it's still a success.
*/
override val successful: Boolean
get() = noTanProcedureSelected == false && couldCreateMessage && didReceiveResponse
&& tanRequiredButUserDidNotEnterOne == false
&& (responseContainsErrors == false || containsOnlyInvalidTanProcedureError())
protected open fun containsOnlyInvalidTanProcedureError(): Boolean {
val errorFeedbacks = segmentFeedbacks.flatMap { it.feedbacks }.filter { it.isError }
return errorFeedbacks.size == 1 && errorFeedbacks.first().responseCode == 9955
}
}