FinTsClientCallback returns now EnterTanGeneratorAtcResult instead of EnterTanGeneratorAtcResult? and EnterAtcDialog returns EnterTanGeneratorAtcResult now
This commit is contained in:
parent
7b57e449ba
commit
d7e0846433
|
@ -17,7 +17,6 @@ import net.dankito.fints.FinTsClientCallback
|
||||||
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
|
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
|
||||||
import net.dankito.fints.model.*
|
import net.dankito.fints.model.*
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
return getTanFromUserOffUiThread(customer, tanChallenge)
|
return getTanFromUserOffUiThread(customer, tanChallenge)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||||
return getAtcFromUserOffUiThread(customer, tanMedium)
|
return getAtcFromUserOffUiThread(customer, tanMedium)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,23 +106,21 @@ class MainActivity : AppCompatActivity() {
|
||||||
return enteredTan.get()
|
return enteredTan.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAtcFromUserOffUiThread(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
private fun getAtcFromUserOffUiThread(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||||
val enteredTan = AtomicReference<String>(null)
|
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
||||||
val enteredAtc = AtomicInteger()
|
|
||||||
val tanEnteredLatch = CountDownLatch(1)
|
val tanEnteredLatch = CountDownLatch(1)
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
// TODO: don't create a fints4javaModelMapper instance here, let MainWindowPresenter do the job
|
// TODO: don't create a fints4javaModelMapper instance here, let MainWindowPresenter do the job
|
||||||
EnterAtcDialog().show(fints4javaModelMapper().mapTanMedium(tanMedium), this@MainActivity, false) { tan, atc ->
|
EnterAtcDialog().show(fints4javaModelMapper().mapTanMedium(tanMedium), this@MainActivity, false) { enteredResult ->
|
||||||
enteredTan.set(tan)
|
result.set(enteredResult)
|
||||||
atc?.let { enteredAtc.set(atc) }
|
|
||||||
tanEnteredLatch.countDown()
|
tanEnteredLatch.countDown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||||
|
|
||||||
return if (enteredTan.get() == null) null else EnterTanGeneratorAtcResult(enteredTan.get(), enteredAtc.get())
|
return result.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.view.ViewGroup
|
||||||
import kotlinx.android.synthetic.main.dialog_enter_atc.view.*
|
import kotlinx.android.synthetic.main.dialog_enter_atc.view.*
|
||||||
import net.dankito.banking.fints4java.android.R
|
import net.dankito.banking.fints4java.android.R
|
||||||
import net.dankito.banking.ui.model.TanMedium
|
import net.dankito.banking.ui.model.TanMedium
|
||||||
|
import net.dankito.fints.model.EnterTanGeneratorAtcResult
|
||||||
|
|
||||||
|
|
||||||
open class EnterAtcDialog : DialogFragment() {
|
open class EnterAtcDialog : DialogFragment() {
|
||||||
|
@ -22,11 +23,11 @@ open class EnterAtcDialog : DialogFragment() {
|
||||||
|
|
||||||
protected lateinit var tanMedium: TanMedium
|
protected lateinit var tanMedium: TanMedium
|
||||||
|
|
||||||
protected lateinit var atcEnteredCallback: (tan: String?, atc: Int?) -> Unit
|
protected lateinit var atcEnteredCallback: (EnterTanGeneratorAtcResult) -> Unit
|
||||||
|
|
||||||
|
|
||||||
open fun show(tanMedium: TanMedium, activity: AppCompatActivity,
|
open fun show(tanMedium: TanMedium, activity: AppCompatActivity,
|
||||||
fullscreen: Boolean = false, atcEnteredCallback: (tan: String?, atc: Int?) -> Unit) {
|
fullscreen: Boolean = false, atcEnteredCallback: (EnterTanGeneratorAtcResult?) -> Unit) {
|
||||||
|
|
||||||
this.tanMedium = tanMedium
|
this.tanMedium = tanMedium
|
||||||
this.atcEnteredCallback = atcEnteredCallback
|
this.atcEnteredCallback = atcEnteredCallback
|
||||||
|
@ -69,7 +70,10 @@ open class EnterAtcDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
atcEnteredCallback(enteredTan, enteredAtc)
|
val result = if (enteredTan == null || enteredAtc == null) EnterTanGeneratorAtcResult.userDidNotEnterTan()
|
||||||
|
else EnterTanGeneratorAtcResult.userEnteredAtc(enteredTan, enteredAtc)
|
||||||
|
|
||||||
|
atcEnteredCallback(result)
|
||||||
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,7 +339,7 @@ open class FinTsClient @JvmOverloads constructor(
|
||||||
if (bank.changeTanMediumParameters?.enteringAtcAndTanRequired == true) {
|
if (bank.changeTanMediumParameters?.enteringAtcAndTanRequired == true) {
|
||||||
enteredAtc = callback.enterTanGeneratorAtc(customer, newActiveTanMedium)
|
enteredAtc = callback.enterTanGeneratorAtc(customer, newActiveTanMedium)
|
||||||
|
|
||||||
if (enteredAtc == null) {
|
if (enteredAtc.hasAtcBeenEntered) {
|
||||||
val message = "Bank requires to enter ATC and TAN in order to change TAN medium." // TODO: translate
|
val message = "Bank requires to enter ATC and TAN in order to change TAN medium." // TODO: translate
|
||||||
return FinTsClientResponse(Response(false, exception = Exception(message)))
|
return FinTsClientResponse(Response(false, exception = Exception(message)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,6 @@ interface FinTsClientCallback {
|
||||||
/**
|
/**
|
||||||
* This method gets called for chipTan TAN generators when the bank asks the customer to synchronize her/his TAN generator.
|
* This method gets called for chipTan TAN generators when the bank asks the customer to synchronize her/his TAN generator.
|
||||||
*/
|
*/
|
||||||
fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult?
|
fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,11 +1,28 @@
|
||||||
package net.dankito.fints.model
|
package net.dankito.fints.model
|
||||||
|
|
||||||
|
|
||||||
open class EnterTanGeneratorAtcResult(
|
open class EnterTanGeneratorAtcResult protected constructor(
|
||||||
val tan: String,
|
val tan: String?,
|
||||||
val atc: Int
|
val atc: Int?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun userEnteredAtc(enteredTan: String, enteredAtc: Int): EnterTanGeneratorAtcResult {
|
||||||
|
return EnterTanGeneratorAtcResult(enteredTan, enteredAtc)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun userDidNotEnterTan(): EnterTanGeneratorAtcResult {
|
||||||
|
return EnterTanGeneratorAtcResult(null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val hasAtcBeenEntered: Boolean
|
||||||
|
get() = tan != null && atc != null
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "TAN: $tan, ATC: $atc"
|
return "TAN: $tan, ATC: $atc"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package net.dankito.fints.model
|
||||||
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium
|
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium
|
||||||
|
|
||||||
|
|
||||||
open class EnterTanResult constructor(
|
open class EnterTanResult protected constructor(
|
||||||
val enteredTan: String?,
|
val enteredTan: String?,
|
||||||
val changeTanMediumTo: TanMedium?
|
val changeTanMediumTo: TanMedium?
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class JavaShowcase {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public EnterTanGeneratorAtcResult enterTanGeneratorAtc(@NotNull CustomerData customer, @NotNull TanGeneratorTanMedium tanMedium) {
|
public EnterTanGeneratorAtcResult enterTanGeneratorAtc(@NotNull CustomerData customer, @NotNull TanGeneratorTanMedium tanMedium) {
|
||||||
return null;
|
return EnterTanGeneratorAtcResult.Companion.userDidNotEnterTan();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,10 @@ class FinTsClientTest {
|
||||||
return EnterTanResult.userDidNotEnterTan()
|
return EnterTanResult.userDidNotEnterTan()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||||
Assert.fail("Bank asks you to synchronize your TAN generator for card ${tanMedium.cardNumber} " +
|
Assert.fail("Bank asks you to synchronize your TAN generator for card ${tanMedium.cardNumber} " +
|
||||||
"(card sequence number ${tanMedium.cardSequenceNumber}). Please do this via your online banking portal or Banking UI.")
|
"(card sequence number ${tanMedium.cardSequenceNumber}). Please do this via your online banking portal or Banking UI.")
|
||||||
return null // should actually never be called
|
return EnterTanGeneratorAtcResult.userDidNotEnterTan() // should actually never be called
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue