Skip to content

Commit f73b024

Browse files
Adding amex CSV import
Closes #105
1 parent 2539d06 commit f73b024

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ As well as real-time webhooks, we also support bulk/historical imports for the f
3636
- [TSB](https://github.com/fintech-to-ynab/fintech-to-ynab/wiki/import:-Teller)
3737
- [Ulster Bank NI](https://github.com/fintech-to-ynab/fintech-to-ynab/wiki/import:-Teller)
3838
- [HSBC UK](https://github.com/fintech-to-ynab/fintech-to-ynab/wiki/import:-Teller)
39+
- [MBNA](https://github.com/fintech-to-ynab/fintech-to-ynab/wiki/Import:-CSV)
40+
- [Amex](https://github.com/fintech-to-ynab/fintech-to-ynab/wiki/Import:-CSV)
3941

4042
*To request a new Bank/Financial Institution, please comment [here](https://github.com/fintech-to-ynab/fintech-to-ynab/issues/73).*
4143

app/services/import/csv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Import::Csv
99
'default' => 'Import::Csv',
1010
'starling' => 'Import::Csv::StarlingBank',
1111
'mbna' => 'Import::Csv::MBNA',
12+
'amex' => 'Import::Csv::Amex',
1213
}
1314

1415
def initialize(path, ynab_account_id)

app/services/import/csv/amex.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'csv'
2+
3+
# @note This is used to import Amex CSV Statements
4+
# Export the statement CSV from within the web app
5+
6+
class Import::Csv::Amex
7+
def initialize(path, ynab_account_id = ENV['YNAB_AMEX_ACCOUNT_ID'])
8+
@path = path
9+
@ynab_account_id = ynab_account_id
10+
@import_id_creator = YNAB::ImportIdCreator.new
11+
end
12+
13+
def import
14+
transactions_to_create = []
15+
16+
::CSV.foreach(@path) do |transaction|
17+
amount = (transaction[1].to_f * 1000).to_i
18+
date = Date.parse(transaction[0])
19+
20+
transactions_to_create << {
21+
id: @import_id_creator.import_id(amount, date),
22+
amount: amount,
23+
payee_name: transaction[2],
24+
date: date,
25+
description: transaction[2]
26+
}
27+
end
28+
29+
YNAB::BulkTransactionCreator.new(transactions_to_create, account_id: @ynab_account_id).create
30+
end
31+
end

0 commit comments

Comments
 (0)