From 4a77465d0a100611c74ec65f7246838056db25ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dyego=20Aur=C3=A9lio?= Date: Sat, 4 May 2024 18:58:32 -0300 Subject: [PATCH 1/4] add payoneer mapping --- csv2ofx/mappings/payoneer.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 csv2ofx/mappings/payoneer.py diff --git a/csv2ofx/mappings/payoneer.py b/csv2ofx/mappings/payoneer.py new file mode 100644 index 0000000..bbc5163 --- /dev/null +++ b/csv2ofx/mappings/payoneer.py @@ -0,0 +1,49 @@ +import os +from operator import itemgetter +from datetime import datetime + +def is_credit(row): + try: + return (row.get("Debit Amount") or None) is None + except ValueError: + return True + + +def get_amount(row): + if is_credit(row): + return row.get("Credit Amount") + + return f'-{row.get("Debit Amount")}' + +def payoneer_filter(transaction): + try: + float(transaction.get("Credit Amount") or transaction.get("Debit Amount")) + return True + except ValueError: + return False + + +def get_date(row): + date_str = f'{row.get("Transaction Date")} {row.get("Transaction Time")}' + + return datetime.strptime(date_str, "%m/%d/%Y %H:%M:%S").strftime("%Y%m%d%H%M%S") + +mapping = { + "has_header": True, + "filter": payoneer_filter, + "is_split": False, + "bank": "Payoneer Global Inc", + "bank_id": "123", + "currency": itemgetter("Currency"), + "delimiter": ",", + "account": os.environ.get("PAYONEER_ACCOUNT", "1000001"), + "date": get_date, + "parse_fmt": "%Y%m%d%H%M%S", + "date_fmt": "%Y%m%d%H%M%S", + "amount": get_amount, + "desc": itemgetter("Description"), + "payee": itemgetter("Target"), + "balance": itemgetter("Running Balance"), + "id": itemgetter("Transaction ID"), + "type": lambda tr: "credit" if is_credit(tr) else "debit", +} \ No newline at end of file From 23f7f0cc818becfe127b77ddc00a26e851d5639a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dyego=20Aur=C3=A9lio?= Date: Sat, 4 May 2024 19:09:29 -0300 Subject: [PATCH 2/4] adding payoneer sample data --- data/converted/payoneer.ofx | 55 +++++++++++++++++++++++++++++++++++++ data/test/payoneer.csv | 3 ++ 2 files changed, 58 insertions(+) create mode 100644 data/converted/payoneer.ofx create mode 100644 data/test/payoneer.csv diff --git a/data/converted/payoneer.ofx b/data/converted/payoneer.ofx new file mode 100644 index 0000000..05952c3 --- /dev/null +++ b/data/converted/payoneer.ofx @@ -0,0 +1,55 @@ +DATA:OFXSGML +ENCODING:UTF-8 + + + + + 0 + INFO + + 20240504190856 + ENG + + + + + + + 0 + INFO + + + USD + + 123 + 59e711d152de7bec7304a8c2ecaf9f0f + CHECKING + + + 19700101 + 20240504 + + DEBIT + 20240503123146 + -100.00 + 123 + payee + Transaction description + + + CREDIT + 20240503120831 + 120.00 + 1234 + payee + Transaction description + + + + 200.00 + 20240503123146 + + + + + diff --git a/data/test/payoneer.csv b/data/test/payoneer.csv new file mode 100644 index 0000000..765718f --- /dev/null +++ b/data/test/payoneer.csv @@ -0,0 +1,3 @@ +Transaction Date,Transaction Time,Time Zone,Transaction ID,Description,Credit Amount,Debit Amount,Currency,Transfer Amount,Transfer Amount Currency,Status,Running Balance,Additional Description,Store Name,Source,Target,Reference ID +05/03/2024,12:31:46,UTC,123,Transaction description,,100,USD,,,Completed,200,Payoneer additional description,,payer,payee, +05/03/2024,12:08:31,UTC,1234,Transaction description,120,,USD,,,Completed,300,Payoneer additional description,,payer,payee, From 784ef3379331f7dd1390758f4a2d702f307f6e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dyego=20Aur=C3=A9lio?= Date: Sat, 4 May 2024 19:30:45 -0300 Subject: [PATCH 3/4] adding test --- data/converted/payoneer.ofx | 10 +++++----- data/test/payoneer.csv | 4 ++-- tests/test.py | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/data/converted/payoneer.ofx b/data/converted/payoneer.ofx index 05952c3..b06519c 100644 --- a/data/converted/payoneer.ofx +++ b/data/converted/payoneer.ofx @@ -7,7 +7,7 @@ ENCODING:UTF-8 0 INFO - 20240504190856 + 20161031112908 ENG @@ -27,10 +27,10 @@ ENCODING:UTF-8 19700101 - 20240504 + 20220905 DEBIT - 20240503123146 + 20210503123146 -100.00 123 payee @@ -38,7 +38,7 @@ ENCODING:UTF-8 CREDIT - 20240503120831 + 20210503120831 120.00 1234 payee @@ -47,7 +47,7 @@ ENCODING:UTF-8 200.00 - 20240503123146 + 20210503123146 diff --git a/data/test/payoneer.csv b/data/test/payoneer.csv index 765718f..95f215d 100644 --- a/data/test/payoneer.csv +++ b/data/test/payoneer.csv @@ -1,3 +1,3 @@ Transaction Date,Transaction Time,Time Zone,Transaction ID,Description,Credit Amount,Debit Amount,Currency,Transfer Amount,Transfer Amount Currency,Status,Running Balance,Additional Description,Store Name,Source,Target,Reference ID -05/03/2024,12:31:46,UTC,123,Transaction description,,100,USD,,,Completed,200,Payoneer additional description,,payer,payee, -05/03/2024,12:08:31,UTC,1234,Transaction description,120,,USD,,,Completed,300,Payoneer additional description,,payer,payee, +05/03/2021,12:31:46,UTC,123,Transaction description,,100,USD,,,Completed,200,Payoneer additional description,,payer,payee, +05/03/2021,12:08:31,UTC,1234,Transaction description,120,,USD,,,Completed,300,Payoneer additional description,,payer,payee, diff --git a/tests/test.py b/tests/test.py index 18c0f87..5818647 100755 --- a/tests/test.py +++ b/tests/test.py @@ -204,6 +204,12 @@ def gen_test(raw): "schwab-checking-baltest-case7.ofx", ), (["-o", "-m amazon", "-e 20230604", SERVER_DATE], "amazon.csv", "amazon.ofx",), + + ( + ["-o", "-m payoneer", "-e 20220905", SERVER_DATE], + "payoneer.csv", + "payoneer.ofx", + ), ] # for Amazon import; excludes transaction 3/3 From 24951433b22a9c75c7174530c1899ada314447ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dyego=20Aur=C3=A9lio?= Date: Sat, 4 May 2024 19:33:40 -0300 Subject: [PATCH 4/4] linting --- csv2ofx/mappings/payoneer.py | 5 ++++- tests/test.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/csv2ofx/mappings/payoneer.py b/csv2ofx/mappings/payoneer.py index bbc5163..d101273 100644 --- a/csv2ofx/mappings/payoneer.py +++ b/csv2ofx/mappings/payoneer.py @@ -2,6 +2,7 @@ from operator import itemgetter from datetime import datetime + def is_credit(row): try: return (row.get("Debit Amount") or None) is None @@ -15,6 +16,7 @@ def get_amount(row): return f'-{row.get("Debit Amount")}' + def payoneer_filter(transaction): try: float(transaction.get("Credit Amount") or transaction.get("Debit Amount")) @@ -28,6 +30,7 @@ def get_date(row): return datetime.strptime(date_str, "%m/%d/%Y %H:%M:%S").strftime("%Y%m%d%H%M%S") + mapping = { "has_header": True, "filter": payoneer_filter, @@ -46,4 +49,4 @@ def get_date(row): "balance": itemgetter("Running Balance"), "id": itemgetter("Transaction ID"), "type": lambda tr: "credit" if is_credit(tr) else "debit", -} \ No newline at end of file +} diff --git a/tests/test.py b/tests/test.py index 5818647..70ebe18 100755 --- a/tests/test.py +++ b/tests/test.py @@ -204,7 +204,6 @@ def gen_test(raw): "schwab-checking-baltest-case7.ofx", ), (["-o", "-m amazon", "-e 20230604", SERVER_DATE], "amazon.csv", "amazon.ofx",), - ( ["-o", "-m payoneer", "-e 20220905", SERVER_DATE], "payoneer.csv",