2020-01-02 21:39:02 +00:00
|
|
|
package net.dankito.banking
|
|
|
|
|
2020-01-02 23:35:36 +00:00
|
|
|
import net.dankito.banking.ui.BankingClientCallback
|
2020-01-02 21:39:02 +00:00
|
|
|
import net.dankito.banking.ui.IBankingClient
|
2020-01-02 23:35:36 +00:00
|
|
|
import net.dankito.banking.ui.model.Account
|
2020-01-02 21:39:02 +00:00
|
|
|
import net.dankito.banking.ui.model.BankAccount
|
|
|
|
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
|
|
|
|
import net.dankito.banking.ui.model.parameters.TransferMoneyData
|
|
|
|
import net.dankito.banking.ui.model.responses.AddAccountResponse
|
|
|
|
import net.dankito.banking.ui.model.responses.BankingClientResponse
|
|
|
|
import net.dankito.banking.ui.model.responses.GetTransactionsResponse
|
|
|
|
import net.dankito.fints.FinTsClientCallback
|
|
|
|
import net.dankito.fints.FinTsClientForCustomer
|
2020-01-02 23:35:36 +00:00
|
|
|
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
|
|
|
|
import net.dankito.fints.model.*
|
2020-01-02 21:39:02 +00:00
|
|
|
import net.dankito.fints.model.mapper.BankDataMapper
|
|
|
|
import net.dankito.fints.util.IBase64Service
|
|
|
|
import net.dankito.utils.IThreadPool
|
|
|
|
import net.dankito.utils.ThreadPool
|
|
|
|
import net.dankito.utils.web.client.IWebClient
|
|
|
|
import net.dankito.utils.web.client.OkHttpWebClient
|
|
|
|
|
|
|
|
|
|
|
|
open class fints4javaBankingClient(
|
|
|
|
bankInfo: BankInfo,
|
|
|
|
customerId: String,
|
|
|
|
pin: String,
|
|
|
|
webClient: IWebClient = OkHttpWebClient(),
|
|
|
|
base64Service: IBase64Service,
|
|
|
|
threadPool: IThreadPool = ThreadPool(),
|
2020-01-02 23:35:36 +00:00
|
|
|
callback: BankingClientCallback
|
2020-01-02 21:39:02 +00:00
|
|
|
|
|
|
|
) : IBankingClient {
|
|
|
|
|
|
|
|
protected val mapper = net.dankito.banking.mapper.fints4javaModelMapper()
|
|
|
|
|
|
|
|
protected val bankDataMapper = BankDataMapper()
|
|
|
|
|
|
|
|
protected val bank = bankDataMapper.mapFromBankInfo(bankInfo)
|
|
|
|
|
|
|
|
protected val customer = CustomerData(customerId, pin)
|
|
|
|
|
2020-01-02 23:35:36 +00:00
|
|
|
protected lateinit var account: Account
|
|
|
|
|
|
|
|
|
|
|
|
protected val client = FinTsClientForCustomer(bank, customer, webClient, base64Service, threadPool, object : FinTsClientCallback {
|
|
|
|
override fun enterTan(customer: CustomerData, tanChallenge: TanChallenge): EnterTanResult {
|
|
|
|
val result = callback.enterTan(account, mapper.mapTanChallenge(tanChallenge))
|
|
|
|
|
|
|
|
return mapper.mapEnterTanResult(result, customer)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
|
|
|
val result = callback.enterTanGeneratorAtc(mapper.mapTanMedium(tanMedium))
|
|
|
|
|
|
|
|
return mapper.mapEnterTanGeneratorAtcResult(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2020-01-02 21:39:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
override fun addAccountAsync(callback: (AddAccountResponse) -> Unit) {
|
|
|
|
client.addAccountAsync { response ->
|
2020-01-02 23:35:36 +00:00
|
|
|
this.account = mapper.mapAccount(customer, bank)
|
2020-01-02 21:39:02 +00:00
|
|
|
val mappedResponse = mapper.mapResponse(account, response)
|
|
|
|
|
|
|
|
callback(mappedResponse)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getTransactionsAsync(bankAccount: BankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) {
|
|
|
|
client.getTransactionsAsync(net.dankito.fints.model.GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate, parameter.toDate)) { response ->
|
|
|
|
|
|
|
|
val mappedResponse = mapper.mapResponse(bankAccount, response)
|
|
|
|
|
|
|
|
callback(mappedResponse)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) {
|
|
|
|
val mappedData = BankTransferData(data.creditorName, data.creditorIban, data.creditorBic, data.amount, data.usage)
|
|
|
|
|
|
|
|
client.doBankTransferAsync(mappedData) { response ->
|
|
|
|
callback(mapper.mapResponse(response))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|