diff --git a/lib/dumper/n26.rb b/lib/dumper/n26.rb index 959ddc9..00e5b24 100644 --- a/lib/dumper/n26.rb +++ b/lib/dumper/n26.rb @@ -36,7 +36,13 @@ def fetch_transactions def accept?(transaction) return true unless @skip_pending_transactions - already_processed?(transaction) + + # Card authorizations (if a company reserves some small amount) + # to check if your card is valid are the same type + # as processing transactions. So if we ignore those, we need to ignore + # the type for transactions where you get that authorization-money back. + already_processed?(transaction) && + !returned_authorization?(transaction) end private @@ -102,5 +108,11 @@ def import_id(transaction) def already_processed?(transaction) transaction['type'] != 'AA' end + + # This can be true if a company reserved some small money + # that they will give you back. + def returned_authorization?(transaction) + transaction['type'] == 'AV' + end end end diff --git a/spec/dumper/n26_spec.rb b/spec/dumper/n26_spec.rb index 9362180..ea48056 100644 --- a/spec/dumper/n26_spec.rb +++ b/spec/dumper/n26_spec.rb @@ -202,6 +202,19 @@ expect(accept?).to be_truthy end end + + context 'when the transaction is processed ' \ + 'but a returned authorization' do + let(:transaction) do + t = transaction_processed + t['type'] = 'AV' + t + end + + it 'returns true' do + expect(accept?).to be_falsy + end + end end end end