Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapping for payoneer #119

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions csv2ofx/mappings/payoneer.py
Original file line number Diff line number Diff line change
@@ -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",
}
55 changes: 55 additions & 0 deletions data/converted/payoneer.ofx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
DATA:OFXSGML
ENCODING:UTF-8
<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<DTSERVER>20161031112908</DTSERVER>
<LANGUAGE>ENG</LANGUAGE>
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID></TRNUID>
<STATUS>
<CODE>0</CODE>
<SEVERITY>INFO</SEVERITY>
</STATUS>
<STMTRS>
<CURDEF>USD</CURDEF>
<BANKACCTFROM>
<BANKID>123</BANKID>
<ACCTID>59e711d152de7bec7304a8c2ecaf9f0f</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>19700101</DTSTART>
<DTEND>20220905</DTEND>
<STMTTRN>
<TRNTYPE>DEBIT</TRNTYPE>
<DTPOSTED>20210503123146</DTPOSTED>
<TRNAMT>-100.00</TRNAMT>
<FITID>123</FITID>
<NAME>payee</NAME>
<MEMO>Transaction description</MEMO>
</STMTTRN>
<STMTTRN>
<TRNTYPE>CREDIT</TRNTYPE>
<DTPOSTED>20210503120831</DTPOSTED>
<TRNAMT>120.00</TRNAMT>
<FITID>1234</FITID>
<NAME>payee</NAME>
<MEMO>Transaction description</MEMO>
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>200.00</BALAMT>
<DTASOF>20210503123146</DTASOF>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>
3 changes: 3 additions & 0 deletions data/test/payoneer.csv
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 5 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down