Implemented setting preferred TanMethod and TanMedium
This commit is contained in:
parent
4ec82a44d7
commit
3e8d1e6dc6
|
@ -66,7 +66,7 @@ open class FinTsClient(
|
||||||
|
|
||||||
/* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */
|
/* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */
|
||||||
|
|
||||||
jobExecutor.retrieveBasicDataLikeUsersTanMethods(bank) { newUserInfoResponse ->
|
jobExecutor.retrieveBasicDataLikeUsersTanMethods(bank, parameter.preferredTanMethods, parameter.preferredTanMedium) { newUserInfoResponse ->
|
||||||
|
|
||||||
if (newUserInfoResponse.successful == false) { // bank parameter (FinTS server address, ...) already seem to be wrong
|
if (newUserInfoResponse.successful == false) { // bank parameter (FinTS server address, ...) already seem to be wrong
|
||||||
callback(AddAccountResponse(newUserInfoResponse, bank))
|
callback(AddAccountResponse(newUserInfoResponse, bank))
|
||||||
|
|
|
@ -89,7 +89,8 @@ open class FinTsJobExecutor(
|
||||||
*
|
*
|
||||||
* Be aware this method resets BPD, UPD and selected TAN method!
|
* Be aware this method resets BPD, UPD and selected TAN method!
|
||||||
*/
|
*/
|
||||||
open fun retrieveBasicDataLikeUsersTanMethods(bank: BankData, closeDialog: Boolean = false, callback: (BankResponse) -> Unit) {
|
open fun retrieveBasicDataLikeUsersTanMethods(bank: BankData, preferredTanMethods: List<TanMethodType>? = null, preferredTanMedium: String? = null,
|
||||||
|
closeDialog: Boolean = false, callback: (BankResponse) -> Unit) {
|
||||||
// just to ensure settings are in its initial state and that bank sends us 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 methods for user (therefore the resetSelectedTanMethod())
|
// user parameter (UPD) and allowed tan methods for user (therefore the resetSelectedTanMethod())
|
||||||
bank.resetBpdVersion()
|
bank.resetBpdVersion()
|
||||||
|
@ -114,11 +115,11 @@ open class FinTsJobExecutor(
|
||||||
if (bank.tanMethodsAvailableForUser.isEmpty()) { // could not retrieve supported tan methods for user
|
if (bank.tanMethodsAvailableForUser.isEmpty()) { // could not retrieve supported tan methods for user
|
||||||
callback(getTanMethodsResponse)
|
callback(getTanMethodsResponse)
|
||||||
} else {
|
} else {
|
||||||
getUsersTanMethod(bank) {
|
getUsersTanMethod(bank, preferredTanMethods) {
|
||||||
if (bank.isTanMethodSelected == false) {
|
if (bank.isTanMethodSelected == false) {
|
||||||
callback(getTanMethodsResponse)
|
callback(getTanMethodsResponse)
|
||||||
} else if (bank.tanMedia.isEmpty() && isJobSupported(bank, CustomerSegmentId.TanMediaList)) { // tan media not retrieved yet
|
} else if (bank.tanMedia.isEmpty() && isJobSupported(bank, CustomerSegmentId.TanMediaList)) { // tan media not retrieved yet
|
||||||
getTanMediaList(bank, TanMedienArtVersion.Alle, TanMediumKlasse.AlleMedien) {
|
getTanMediaList(bank, TanMedienArtVersion.Alle, TanMediumKlasse.AlleMedien, preferredTanMedium) {
|
||||||
callback(getTanMethodsResponse) // TODO: judge if bank requires selecting TAN media and if though evaluate getTanMediaListResponse
|
callback(getTanMethodsResponse) // TODO: judge if bank requires selecting TAN media and if though evaluate getTanMediaListResponse
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,17 +316,22 @@ open class FinTsJobExecutor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun getTanMediaList(bank: BankData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle,
|
open fun getTanMediaList(bank: BankData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle, tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien,
|
||||||
tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien, callback: (GetTanMediaListResponse) -> Unit) {
|
callback: (GetTanMediaListResponse) -> Unit) {
|
||||||
|
getTanMediaList(bank, tanMediaKind, tanMediumClass, null, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun getTanMediaList(bank: BankData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle, tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien,
|
||||||
|
preferredTanMedium: String? = null, callback: (GetTanMediaListResponse) -> Unit) {
|
||||||
|
|
||||||
sendMessageAndHandleResponse(bank, CustomerSegmentId.TanMediaList, false, { dialogContext ->
|
sendMessageAndHandleResponse(bank, CustomerSegmentId.TanMediaList, false, { dialogContext ->
|
||||||
messageBuilder.createGetTanMediaListMessage(dialogContext, tanMediaKind, tanMediumClass)
|
messageBuilder.createGetTanMediaListMessage(dialogContext, tanMediaKind, tanMediumClass)
|
||||||
}) { response ->
|
}) { response ->
|
||||||
handleGetTanMediaListResponse(response, bank, callback)
|
handleGetTanMediaListResponse(response, bank, preferredTanMedium, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun handleGetTanMediaListResponse(response: BankResponse, bank: BankData, callback: (GetTanMediaListResponse) -> Unit) {
|
protected open fun handleGetTanMediaListResponse(response: BankResponse, bank: BankData, preferredTanMedium: String? = null, callback: (GetTanMediaListResponse) -> Unit) {
|
||||||
// TAN media list (= TAN generator list) is only returned for users with chipTAN TAN methods
|
// TAN media list (= TAN generator list) is only returned for users with chipTAN TAN methods
|
||||||
val tanMediaList = if (response.successful == false) null
|
val tanMediaList = if (response.successful == false) null
|
||||||
else response.getFirstSegmentById<TanMediaList>(InstituteSegmentId.TanMediaList)
|
else response.getFirstSegmentById<TanMediaList>(InstituteSegmentId.TanMediaList)
|
||||||
|
@ -333,7 +339,8 @@ open class FinTsJobExecutor(
|
||||||
tanMediaList?.let {
|
tanMediaList?.let {
|
||||||
bank.tanMedia = it.tanMedia
|
bank.tanMedia = it.tanMedia
|
||||||
|
|
||||||
bank.selectedTanMedium = bank.selectedTanMedium?.let { selected -> bank.tanMedia.firstOrNull { it.mediumName == selected.mediumName } } // try to find selectedTanMedium in new TanMedia instances
|
bank.selectedTanMedium = preferredTanMedium?.let { bank.tanMedia.firstOrNull { it.mediumName == preferredTanMedium } }
|
||||||
|
?: bank.selectedTanMedium?.let { selected -> bank.tanMedia.firstOrNull { it.mediumName == selected.mediumName } } // try to find selectedTanMedium in new TanMedia instances
|
||||||
?: bank.tanMedia.firstOrNull { it.mediumName != null }
|
?: bank.tanMedia.firstOrNull { it.mediumName != null }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,12 +674,18 @@ open class FinTsJobExecutor(
|
||||||
return BankResponse(true, noTanMethodSelected = noTanMethodSelected, internalError = errorMessage)
|
return BankResponse(true, noTanMethodSelected = noTanMethodSelected, internalError = errorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getUsersTanMethod(bank: BankData, done: (Boolean) -> Unit) {
|
open fun getUsersTanMethod(bank: BankData, preferredTanMethods: List<TanMethodType>? = null, done: (Boolean) -> Unit) {
|
||||||
if (bank.tanMethodsAvailableForUser.size == 1) { // user has only one TAN method -> set it and we're done
|
if (bank.tanMethodsAvailableForUser.size == 1) { // user has only one TAN method -> set it and we're done
|
||||||
bank.selectedTanMethod = bank.tanMethodsAvailableForUser.first()
|
bank.selectedTanMethod = bank.tanMethodsAvailableForUser.first()
|
||||||
done(true)
|
done(true)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
findPreferredTanMethod(bank, preferredTanMethods)?.let {
|
||||||
|
bank.selectedTanMethod = it
|
||||||
|
done(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// we know user's supported tan methods, now ask user which one to select
|
// we know user's supported tan methods, now ask user which one to select
|
||||||
callback.askUserForTanMethod(bank.tanMethodsAvailableForUser, selectSuggestedTanMethod(bank)) { selectedTanMethod ->
|
callback.askUserForTanMethod(bank.tanMethodsAvailableForUser, selectSuggestedTanMethod(bank)) { selectedTanMethod ->
|
||||||
if (selectedTanMethod != null) {
|
if (selectedTanMethod != null) {
|
||||||
|
@ -686,6 +699,16 @@ open class FinTsJobExecutor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findPreferredTanMethod(bank: BankData, preferredTanMethods: List<TanMethodType>?): TanMethod? {
|
||||||
|
preferredTanMethods?.forEach { preferredTanMethodType ->
|
||||||
|
bank.tanMethodsAvailableForUser.firstOrNull { it.type == preferredTanMethodType }?.let {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
protected open fun selectSuggestedTanMethod(bank: BankData): TanMethod? {
|
protected open fun selectSuggestedTanMethod(bank: BankData): TanMethod? {
|
||||||
return bank.tanMethodsAvailableForUser.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan && it.type != TanMethodType.ChipTanManuell }
|
return bank.tanMethodsAvailableForUser.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan && it.type != TanMethodType.ChipTanManuell }
|
||||||
?: bank.tanMethodsAvailableForUser.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan }
|
?: bank.tanMethodsAvailableForUser.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan }
|
||||||
|
|
|
@ -5,7 +5,9 @@ import kotlin.jvm.JvmOverloads
|
||||||
|
|
||||||
open class AddAccountParameter @JvmOverloads constructor(
|
open class AddAccountParameter @JvmOverloads constructor(
|
||||||
open val bank: BankData,
|
open val bank: BankData,
|
||||||
open val fetchBalanceAndTransactions: Boolean = true
|
open val fetchBalanceAndTransactions: Boolean = true,
|
||||||
|
open val preferredTanMethods: List<TanMethodType>? = null,
|
||||||
|
open val preferredTanMedium: String? = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(bankCode: String, customerId: String, pin: String, finTs3ServerAddress: String)
|
constructor(bankCode: String, customerId: String, pin: String, finTs3ServerAddress: String)
|
||||||
|
|
Loading…
Reference in New Issue