Skip to main content

Crate fints_client

Crate fints_client 

Source
Expand description

§fints-client: a FinTS 3.0 PIN/TAN client

FinTS (formerly HBCI) is the online-banking protocol of German banks. This crate reads balances, transactions and securities holdings, and sends SEPA and instant transfers with the payee name check (Verification of Payee).

Banks answer only clients registered with the Deutsche Kreditwirtschaft: register your app at https://www.fints.org/de/hersteller/produktregistrierung and pass its product ID to jobs::BankClient::new. The crate ships with no product ID.

§Quick start

Every operation is async. The default http transport is reqwest and needs a tokio runtime.

use fints_client::jobs::{self, BankClient, Credentials, Step, TanKind};
use fints_client::{bank_by_blz, jiff::Timestamp, Pin, ProductId, SessionState, UserId};

let config = bank_by_blz("12030000").expect("BLZ in the bank directory"); // DKB
let client = BankClient::new(config, ProductId::new("YOUR-PRODUCT-ID"));
let user = UserId::new("user");
let creds = Credentials::new(user.clone(), Pin::new("pin"));
let state = SessionState::new(&client.config().blz, &user); // or SessionState::from_json(stored)

// Open the dialog. A bank that wants a TAN answers `NeedTan`.
let (mut dialog, mut step) = jobs::open(&client, &creds, &state).await?;
let opened = loop {
    match step {
        Step::Done(done) => break done.value,
        Step::NeedTan(challenge, resume) => {
            println!("{}", challenge.challenge);
            step = match challenge.kind {
                // App approval: wait as long as the bank asks, then ask once.
                TanKind::Decoupled { .. } => {
                    if let Some(at) = challenge.not_before {
                        let wait = at.duration_since(Timestamp::now());
                        tokio::time::sleep(wait.try_into().unwrap_or_default()).await;
                    }
                    dialog.poll(resume).await?
                }
                // chipTAN, smsTAN, photoTAN: the user types the TAN.
                TanKind::Typed { .. } => dialog.submit_tan(resume, &read_tan()).await?,
            };
        }
        _ => unreachable!("only a transfer pauses on its payee check"),
    }
};

let account = opened.accounts[0].account()?;
if let Step::Done(balance) = jobs::balance(&mut dialog, &account).await? {
    println!("{:?}", balance.value);
}
let state = dialog.end().await?;
std::fs::write("state.json", state.to_json()?)?; // encrypt this in a real app

§Steps instead of callbacks

Every job in jobs returns a jobs::Step: Done with the value, or a pause with a resume handle. NeedTan carries a jobs::TanChallenge; its jobs::TanKind says how to answer:

  • Typed (chipTAN, smsTAN, photoTAN): the user types the TAN, you call jobs::Dialog::submit_tan. A flicker code or photoTAN image comes in media for you to render.
  • Decoupled (app approval): sleep until not_before, then call jobs::Dialog::poll; repeat while the bank says it is still waiting. When auto_polling_allowed is Some(false), poll only when the user asks (a button), not on a timer.

A jobs::transfer may also pause on its payee check (NeedVopConfirmation). The library never sleeps and never calls back. A paused dialog can be frozen into a serialisable value and thawed in a new process (jobs::Dialog::freeze). jobs::synchronise learns the allowed TAN methods without a login, so the user can choose one before open.

§Banks

bank_by_blz looks a bank up in the bank directory by its BLZ (Bankleitzahl: the German bank code, characters 5 to 12 of the IBAN) and returns a BankConfig with its server and profile. A bank’s own behaviour lives in its BankProfile, not in code paths.

§Cargo features

  • http (default): HttpTransport (reqwest with rustls), the default transport of a jobs::Dialog. Without it you supply the transport.
  • trace: Recorder and Trace, masked recordings of dialogs.
  • testbank: registers the synthetic test bank (BLZ 12345678 on localhost) as a known bank.
  • tooling: the protocol internals (codec, protocol, types) for the test bank and wire-level tests. Applications use jobs.

§Dates

Dates and timestamps in the API are jiff types. The crate re-exports jiff so a caller can name the version this crate uses.

Re-exports§

pub use banks::BankConfig;
pub use banks::BankProfile;
pub use banks::BookingIdSource;
pub use banks::InitMode;
pub use banks::ProfileId;
pub use banks::all_banks;
pub use banks::bank_by_blz;
pub use error::AddressingReason;
pub use error::BankError;
pub use error::FinTSError;
pub use error::Result;
pub use error::TransportKind;
pub use jobs::CheckedTransfer;
pub use jobs::Instant;
pub use jobs::InvalidReason;
pub use jobs::InvalidTransfer;
pub use jobs::PayeeOutcome;
pub use jobs::PayeeResult;
pub use jobs::Transfer;
pub use jobs::TransferField;
pub use jobs::VopResult;
pub use return_code::Category;
pub use return_code::ClientWarning;
pub use return_code::Notice;
pub use return_code::NoticeDialog;
pub use return_code::ReturnCode;
pub use session::SessionState;
pub use jiff;

Modules§

banks
Bank directory: known German banks with their FinTS endpoint URLs and bank profiles.
camt
CAMT.052 (ISO 20022 “Bank to Customer Account Report”) parser.
error
formats
Bank data formats.
jobs
Jobs as steps (docs/jobs-step-design.md).
mask
Masking of FinTS messages for logs and tooling.
quirks
Repairs for bank messages that break the message layout.
return_code
Return codes (“Rückmeldungen”) of HIRMG and HIRMS, Formals 2017 B.7.
session
The state a client keeps between runs.
tracetrace
Recording dialogs as masked, anonymised traces (feature trace).
transport
Transport layer: how a FinTS message reaches the bank.

Structs§

AccountNon-tooling
The account an order is for, as KTI (international: IBAN and BIC) and, where known, KTV (national: number, subaccount, bank code).
AccountBalanceNon-tooling
Account balance.
AccountKeyErrorNon-tooling
Why a string is not an AccountKey.
AccountLimitNon-tooling
Kontolimit, or the limit of one allowed order.
BankNameNon-tooling
Human-readable bank name.
BankTimeNon-tooling
A time the bank stamped on its data: the bank’s wall clock, and its UTC offset when the bank sent one. FinTS carries no time zones (Formals tim is the sender’s local time); SWIFT :13D: adds a fixed offset, the older :13: (HBCI 2.2 IX.2.9) has none. Not serde (jiff’s Offset is not); like jobs::Statement.
BicNon-tooling
BIC (Bank Identifier Code).
BlzNon-tooling
Bank code (Bankleitzahl), e.g. “12030000”.
ChallengeTextNon-tooling
TAN challenge text to display to the user.
CurrencyNon-tooling
Currency code (ISO 4217), e.g. “EUR”.
DepotTransactionNon-tooling
One depot transaction (securities movement) from an MT536 statement.
FinTSUrlNon-tooling
FinTS server URL.
FormatListsNon-tooling
The data formats of a VersionMismatch on a format.
IbanNon-tooling
IBAN (International Bank Account Number).
IsinNon-tooling
ISIN (International Securities Identification Number), e.g. “DE0005140008”.
PinNon-tooling
The user’s PIN. Debug and Display never show it.
ProductIdNon-tooling
FinTS product registration ID.
SecurityFunctionNon-tooling
Security function code, e.g. “940” for pushTAN, “999” for PIN-only.
SecurityHoldingNon-tooling
A single securities position in a depot.
SegmentTypeNon-tooling
Segment type identifier, e.g. “HKSAL”, “HKKAZ”.
SystemIdNon-tooling
System ID assigned by the bank via HKSYN.
TanMediumNameNon-tooling
TAN medium name (e.g. device name for pushTAN).
TanMethodNon-tooling
One TAN method the bank offers (an entry of HITANS).
TanOverridesNon-tooling
Per-order overrides, keyed by the order’s segment code (e.g. HKSAL).
TouchdownPointNon-tooling
Touchdown/pagination point returned by the bank (code 3040).
TransactionNon-tooling
A parsed transaction.
UserIdNon-tooling
FinTS user ID / login name.
VersionMismatchNon-tooling
No version of a job is both offered by the bank and implemented by us.
WknNon-tooling
WKN (Wertpapierkennnummer), e.g. “514000”.

Enums§

AccountClassNon-tooling
What kind of account a UPD entry is, from its “Kontoart” (Formals, data dictionary). The spec assigns each tens range one kind; the values inside a range are the bank’s own.
AccountKeyNon-tooling
The identity of an account of the UPD, stable across logins: its KTV (Kontoverbindung, HIUPD DE 1), or its IBAN when the UPD entry has no account number.
AllowanceNon-tooling
What the UPD says about an order for an account.
ClassSourceNon-tooling
Where an AccountClass came from.
DepotTransactionDirectionNon-tooling
Whether securities came into or left the depot (MT536 :22H::REDE).
LimitKindNon-tooling
Limitart.
TanMediaNon-tooling
HHD-UC challenge data sorted into something a user interface can show.
TanOverrideNon-tooling
A bank profile’s fixed answer for one order, beating HIPINS.
TanProcessNon-tooling
“TAN-Prozess” of a two-step method (PIN/TAN document, HITANS).
TransactionStatusNon-tooling
Whether a transaction is booked or pending (vorgemerkt).