diff --git a/config.sample.yml b/config.sample.yml index 8407256..2c312dc 100644 --- a/config.sample.yml +++ b/config.sample.yml @@ -19,3 +19,6 @@ accounts: password: # n26 password skip_pending_transactions: false # default: false, only imports transactions when they're processed set_category: false # default: false, sets the N26 category name as category +replacements: + - payee: "NETFLIX INTERNATIONAL B.V." + replacement: "Netflix" \ No newline at end of file diff --git a/lib/dumper.rb b/lib/dumper.rb index 9083022..dc398c9 100644 --- a/lib/dumper.rb +++ b/lib/dumper.rb @@ -9,6 +9,8 @@ def self.get_dumper(name) Dumper::N26 when :fints Dumper::Fints + when :deutschebank + Dumper::DeutscheBank else raise "Dumper \"#{name}\" not supported." end diff --git a/lib/dumper/deutschebank.rb b/lib/dumper/deutschebank.rb new file mode 100644 index 0000000..ec0d745 --- /dev/null +++ b/lib/dumper/deutschebank.rb @@ -0,0 +1,29 @@ +class Dumper + # Implements logic to fetch transactions via the Fints protocol + # and implements methods that convert the response to meaningful data. + class DeutscheBank < Fints + def payee_name(transaction) + if transaction.sepa["SVWZ"].nil? + puts transaction.inspect + puts transaction.to_json + end + if super == "DEUTSCHE BANK" || super == "" # This is either a interest statement or more likely a Payment with Apple Pay + if transaction.sepa.empty? + puts transaction.transaction_code + transaction.transaction_code + else + transaction.sepa["SVWZ"].split('//')[0] + end + else + super + end + end + def memo(transaction) + if transaction.sepa.empty? + transaction.information + else + transaction.sepa["SVWZ"] + end + end + end +end diff --git a/lib/dumper/fints.rb b/lib/dumper/fints.rb index c5fce5d..827424a 100644 --- a/lib/dumper/fints.rb +++ b/lib/dumper/fints.rb @@ -19,7 +19,7 @@ def fetch_transactions client = FinTS::PinTanClient.new(@blz, @username, @password, @endpoint) account = client.get_sepa_accounts.find { |a| a[:iban] == @iban } - statement = client.get_statement(account, Date.today - 35, Date.today) + statement = client.get_statement(account, Date.today - 10, Date.today) statement.map { |t| to_ynab_transaction(t) } end diff --git a/lib/transaction_creator.rb b/lib/transaction_creator.rb index a71337d..f641698 100644 --- a/lib/transaction_creator.rb +++ b/lib/transaction_creator.rb @@ -28,6 +28,7 @@ def call(options = {}) # rubocop:enable Metrics/MethodLength def payee_id(options) + return nil # ignore for now and let ynab calc that payee_id = options.fetch(:payee_id, nil) return payee_id if payee_id @@ -43,11 +44,21 @@ def payee_id(options) def payee_name(options) return nil if payee_id(options) payee = options.fetch(:payee_name, nil) + # try to replace + payee = replaceFromConfig(payee) # The api has a limit of 50 characters for the payee field payee = truncate(payee, 50) payee end + def replaceFromConfig(payee) + result = Settings.all['replacements'].find do |replacement| + replacement['payee'] == payee + end + return payee if result.nil? || result == "" + result['replacement'] + end + def memo(options) memo = options.fetch(:memo, nil) # The api has a limit of 100 characters for the momo field