Updated Java showcase code
This commit is contained in:
parent
8b2e200583
commit
5b5173132f
|
@ -3,17 +3,16 @@ package net.dankito.fints.java;
|
||||||
import net.dankito.fints.FinTsClient;
|
import net.dankito.fints.FinTsClient;
|
||||||
import net.dankito.fints.FinTsClientCallback;
|
import net.dankito.fints.FinTsClientCallback;
|
||||||
import net.dankito.fints.banks.BankFinder;
|
import net.dankito.fints.banks.BankFinder;
|
||||||
import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion;
|
|
||||||
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 net.dankito.fints.model.mapper.BankDataMapper;
|
import net.dankito.fints.model.mapper.BankDataMapper;
|
||||||
|
import net.dankito.fints.response.client.AddAccountResponse;
|
||||||
|
import net.dankito.fints.response.client.FinTsClientResponse;
|
||||||
import net.dankito.fints.response.client.GetTransactionsResponse;
|
import net.dankito.fints.response.client.GetTransactionsResponse;
|
||||||
import net.dankito.fints.util.Java8Base64Service;
|
import net.dankito.fints.util.Java8Base64Service;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,13 +23,12 @@ public class JavaShowcase {
|
||||||
|
|
||||||
// set your bank code (Bankleitzahl) here. Or create BankData manually. Required fields are:
|
// set your bank code (Bankleitzahl) here. Or create BankData manually. Required fields are:
|
||||||
// bankCode, bankCountryCode (Germany = 280), finTs3ServerAddress and for bank transfers bic
|
// bankCode, bankCountryCode (Germany = 280), finTs3ServerAddress and for bank transfers bic
|
||||||
List<BankInfo> foundBanks = bankFinder.findBankByBankCode("10070000");
|
List<BankInfo> foundBanks = bankFinder.findBankByBankCode("<bank_code>");
|
||||||
|
|
||||||
if (foundBanks.isEmpty() == false) {
|
if (foundBanks.isEmpty() == false) {
|
||||||
BankData bank = new BankDataMapper().mapFromBankInfo(foundBanks.get(0));
|
BankData bank = new BankDataMapper().mapFromBankInfo(foundBanks.get(0));
|
||||||
// set your customer data (customerId = Kontonummer in most cases, pin = online banking pin)
|
// set your customer data (customerId = Kontonummer in most cases, pin = online banking pin)
|
||||||
CustomerData customer = new CustomerData("<customer_id>", "<pin>");
|
CustomerData customer = new CustomerData("<customer_id>", "<pin>");
|
||||||
customer.setSelectedTanProcedure(new TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTanOptisch));
|
|
||||||
|
|
||||||
FinTsClientCallback callback = new FinTsClientCallback() {
|
FinTsClientCallback callback = new FinTsClientCallback() {
|
||||||
|
|
||||||
|
@ -55,18 +53,43 @@ public class JavaShowcase {
|
||||||
|
|
||||||
FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service());
|
FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service());
|
||||||
|
|
||||||
// some banks support retrieving account transactions of last 90 days without TAN
|
AddAccountResponse addAccountResponse = finTsClient.addAccount(bank, customer);
|
||||||
long ninetyDaysAgoMilliseconds = 90 * 24 * 60 * 60 * 1000L;
|
if (addAccountResponse.isSuccessful()) {
|
||||||
Date ninetyDaysAgo = new Date(new Date().getTime() - ninetyDaysAgoMilliseconds);
|
System.out.println("Could not add account for " + bank.getBankCode() + " " + customer.getCustomerId() + ":");
|
||||||
|
showResponseError(addAccountResponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
GetTransactionsResponse response = finTsClient.getTransactions(
|
System.out.println("Successfully added account for " + bank.getBankCode() + " " + customer.getCustomerId());
|
||||||
new GetTransactionsParameter(true, ninetyDaysAgo), bank, customer);
|
|
||||||
|
|
||||||
showResponse(response);
|
/* Other stuff you can do with the lib */
|
||||||
|
|
||||||
|
for (AccountData account : customer.getAccounts()) { // accounts are now retrieved
|
||||||
|
if (account.getSupportsRetrievingAccountTransactions()) {
|
||||||
|
// retrieves all account transactions, but requires entering a TAN (FinTsClientCallback.enterTan() will be called)
|
||||||
|
// GetTransactionsResponse response = finTsClient.getTransactions(
|
||||||
|
// new GetTransactionsParameter(true), bank, customer, account);
|
||||||
|
//
|
||||||
|
// showGetTransactionsResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.getSupportsTransferringMoney()) {
|
||||||
|
// transfer 0.01 € to yourself
|
||||||
|
// BankTransferData data = new BankTransferData(customer.getName(), account.getIban(), bank.getBic(), new BigDecimal("0.01"), "Hey I can transfer money to myself")
|
||||||
|
// FinTsClientResponse transferMoneyResponse = finTsClient.doBankTransfer(data, bank, customer, account);
|
||||||
|
//
|
||||||
|
// if (transferMoneyResponse.isSuccessful()) {
|
||||||
|
// System.out.println("Successfully transferred " + data.getAmount() + " to " + data.getCreditorIban());
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// showResponseError(transferMoneyResponse);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showResponse(GetTransactionsResponse response) {
|
private static void showGetTransactionsResponse(GetTransactionsResponse response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
System.out.println("Balance (Saldo) = " + response.getBalance());
|
System.out.println("Balance (Saldo) = " + response.getBalance());
|
||||||
|
|
||||||
|
@ -82,16 +105,20 @@ public class JavaShowcase {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("An error occurred:");
|
System.out.println("An error occurred:");
|
||||||
if (response.getException() != null) { // something severe occurred
|
showResponseError(response);
|
||||||
System.out.println(response.getException().getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
// error messages retrieved from bank (e.g. PIN is wrong, message contains errors, ...)
|
|
||||||
for (String retrievedErrorMessage : response.getErrorsToShowToUser()) {
|
|
||||||
System.out.println(retrievedErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void showResponseError(FinTsClientResponse response) {
|
||||||
|
if (response.getException() != null) { // something severe occurred
|
||||||
|
System.out.println(response.getException().getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// error messages retrieved from bank (e.g. PIN is wrong, message contains errors, ...)
|
||||||
|
for (String retrievedErrorMessage : response.getErrorsToShowToUser()) {
|
||||||
|
System.out.println(retrievedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue