diff --git a/csv2ofx/mappings/payoneer.py b/csv2ofx/mappings/payoneer.py new file mode 100644 index 0000000..d101273 --- /dev/null +++ b/csv2ofx/mappings/payoneer.py @@ -0,0 +1,52 @@ +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", +} diff --git a/data/converted/payoneer.ofx b/data/converted/payoneer.ofx new file mode 100644 index 0000000..b06519c --- /dev/null +++ b/data/converted/payoneer.ofx @@ -0,0 +1,55 @@ +DATA:OFXSGML +ENCODING:UTF-8 + + + + + 0 + INFO + + 20161031112908 + ENG + + + + + + + 0 + INFO + + + USD + + 123 + 59e711d152de7bec7304a8c2ecaf9f0f + CHECKING + + + 19700101 + 20220905 + + DEBIT + 20210503123146 + -100.00 + 123 + payee + Transaction description + + + CREDIT + 20210503120831 + 120.00 + 1234 + payee + Transaction description + + + + 200.00 + 20210503123146 + + + + + diff --git a/data/test/payoneer.csv b/data/test/payoneer.csv new file mode 100644 index 0000000..95f215d --- /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/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..70ebe18 100755 --- a/tests/test.py +++ b/tests/test.py @@ -204,6 +204,11 @@ 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