jahir / kontify

Poll your bank accounts and get notifications for new transactions (while storing them in a database)
GNU General Public License v3.0
8 stars 5 forks source link

Don't rely on transaction order #3

Open jahir opened 4 years ago

jahir commented 4 years ago

FinTS unfortunately has no unique id or timestamp for transactions (or banks don't return it). So, to detect new transactions, we tag every transaction with a sequence number which is unique per account and day (starting with 1 on every new day).

This works quite fine as long as the bank returns transaction always in the same order and new transaction are returned after known ones. This is quite optimistic, but apparently true for most banks. There is at least one bank (namely 1822direkt) which returns intra-day transaction in reversed order, i.e. new transactions are returned before already known ones. Example:

  1. run: trans1
  2. run: trans2, trans1
  3. run: trans3, trans2, trans1

This results in trans1 to be considered a new transaction (and stored multiple times in the database) in every run.

A proper fix could be to calculate a transaction hash and to use it to identify known transactions. A transaction with the same properties could happen multiple times per day, so there must be extra logic, like tagging transactions retrieved from the database as "consumed" when a transaction with the same hash is returned from the bank, so a transaction with the same hash is considered new. The intradaynum field would be obsolete then and not used any more.