Implemented setting medium name also for unknown medium classes (e.g. Sparkasse sends for pushTan now 'AlleMedien' -> set medium name and everything just works fine)

This commit is contained in:
dankito 2020-11-16 21:53:13 +01:00
parent 7b94efb975
commit bc49b4ee20
1 changed files with 8 additions and 8 deletions

View File

@ -546,40 +546,40 @@ open class ResponseParser(
} }
val status = parseCodeEnum(dataElements[1], TanMediumStatus.values()) val status = parseCodeEnum(dataElements[1], TanMediumStatus.values())
val mediumName = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[10])
// TODO: may also parse 'Letzte Benutzung' (second last element) and 'Freigeschaltet am' (last element) // TODO: may also parse 'Letzte Benutzung' (second last element) and 'Freigeschaltet am' (last element)
val remainingDataElements = dataElements.subList(2, dataElements.size) val remainingDataElements = dataElements.subList(2, dataElements.size)
return when (mediumClass) { return when (mediumClass) {
TanMediumKlasse.TanGenerator -> parseTanGeneratorTanMedium(mediumClass, status, hitabVersion, remainingDataElements) TanMediumKlasse.TanGenerator -> parseTanGeneratorTanMedium(mediumClass, status, mediumName, hitabVersion, remainingDataElements)
TanMediumKlasse.MobiltelefonMitMobileTan -> parseMobilePhoneTanMedium(mediumClass, status, hitabVersion, remainingDataElements) TanMediumKlasse.MobiltelefonMitMobileTan -> parseMobilePhoneTanMedium(mediumClass, status, mediumName, hitabVersion, remainingDataElements)
else -> TanMedium(mediumClass, status, "Unbekannte TAN Medium Klasse") else -> TanMedium(mediumClass, status, mediumName) // Sparkasse sends for pushTan now class 'AlleMedien' -> set medium name and everything just works fine
} }
} }
protected open fun parseTanGeneratorTanMedium(mediumClass: TanMediumKlasse, status: TanMediumStatus, protected open fun parseTanGeneratorTanMedium(mediumClass: TanMediumKlasse, status: TanMediumStatus, mediumName: String?,
hitabVersion: Int, dataElements: List<String>): TanGeneratorTanMedium { hitabVersion: Int, dataElements: List<String>): TanGeneratorTanMedium {
val cardType = if (hitabVersion < 2) null else parseNullableInt(dataElements[2]) val cardType = if (hitabVersion < 2) null else parseNullableInt(dataElements[2])
// TODO: may also parse account info // TODO: may also parse account info
val validFrom = if (hitabVersion < 2) null else parseNullableDate(dataElements[8]) val validFrom = if (hitabVersion < 2) null else parseNullableDate(dataElements[8])
val validTo = if (hitabVersion < 2) null else parseNullableDate(dataElements[9]) val validTo = if (hitabVersion < 2) null else parseNullableDate(dataElements[9])
val mediumName = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[10])
return TanGeneratorTanMedium(mediumClass, status, parseString(dataElements[0]), parseStringToNullIfEmpty(dataElements[1]), return TanGeneratorTanMedium(mediumClass, status, parseString(dataElements[0]), parseStringToNullIfEmpty(dataElements[1]),
cardType, validFrom, validTo, mediumName) cardType, validFrom, validTo, mediumName)
} }
protected open fun parseMobilePhoneTanMedium(mediumClass: TanMediumKlasse, status: TanMediumStatus, protected open fun parseMobilePhoneTanMedium(mediumClass: TanMediumKlasse, status: TanMediumStatus, mediumName: String?,
hitabVersion: Int, dataElements: List<String>): MobilePhoneTanMedium { hitabVersion: Int, dataElements: List<String>): MobilePhoneTanMedium {
val mediumName = parseString(dataElements[10])
val concealedPhoneNumber = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[11]) val concealedPhoneNumber = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[11])
val phoneNumber = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[12]) val phoneNumber = if (hitabVersion < 2) null else parseStringToNullIfEmpty(dataElements[12])
val smsDebitAccount: KontoverbindungInternational? = null // TODO: may parse 13th data element to KontoverbindungInternational val smsDebitAccount: KontoverbindungInternational? = null // TODO: may parse 13th data element to KontoverbindungInternational
return MobilePhoneTanMedium(mediumClass, status, mediumName, concealedPhoneNumber, phoneNumber, smsDebitAccount) // mediumName should actually never be unset according to spec
return MobilePhoneTanMedium(mediumClass, status, mediumName ?: "", concealedPhoneNumber, phoneNumber, smsDebitAccount)
} }