Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Start recording ref when recording an exchange in masspay
Browse files Browse the repository at this point in the history
  • Loading branch information
kaguillera committed Jun 16, 2017
1 parent 460a422 commit 8c52955
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 14 additions & 5 deletions bin/masspay.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,21 @@ def compute_output_csvs():
print("{:>64} {:>7} {:>7}".format(total_gross, total_fees, total_net))


def load_statuses():
def load_statuses_and_refs():
_status_map = { 'Completed': 'succeeded'
, 'Unclaimed': 'pending'
, 'Denied': 'failed'
} # PayPal -> Gratipay
statuses = {}
refs = {}
fp = open(REPORT_CSV)
for line in fp:
if line.startswith('Transaction ID,Recipient'):
break
for rec in csv.reader(fp):
statuses[rec[1]] = _status_map[rec[5]]
return statuses
refs[rec[1]] = rec[0]
return statuses, refs


def post_back_to_gratipay(force=False):
Expand All @@ -200,7 +202,7 @@ def post_back_to_gratipay(force=False):
"did, then rerun with -f.")
return

statuses = load_statuses()
statuses, refs = load_statuses_and_refs()

nposts = 0
for username, route_id, email, gross, fee, net, additional_note in csv.reader(open(GRATIPAY_CSV)):
Expand All @@ -210,8 +212,15 @@ def post_back_to_gratipay(force=False):
note += " " + additional_note
print(note)
status = statuses[email]

data = {'amount': '-' + net, 'fee': fee, 'note': note, 'status': status, 'route_id': route_id}
ref = refs[email]

data = {'amount': '-' + net
, 'fee': fee
, 'note': note
, 'status': status
, 'ref': ref
, 'route_id': route_id
}
try:
response = requests.post(url, auth=(gratipay_api_key, ''), data=data)
except IncompleteRead:
Expand Down
11 changes: 8 additions & 3 deletions www/~/%username/history/record-an-exchange.spt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ if request.method == 'POST':
route = ExchangeRoute.from_id(route_id)
if not route or route.participant.id != participant.id:
raise Response(400, "Route doesn't exist")

ref = request.body['ref']
if not ref:
ref = ""

with website.db.get_cursor() as cursor:
cursor.run("""
INSERT INTO exchanges
(amount, fee, route, participant, recorder, note, status)
VALUES (%s, %s, %s, %s, %s, %s, %s)
""", (amount, fee, route_id, participant.username, user.participant.username, note, status))
(amount, fee, route, participant, recorder, note, status, ref)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
""", (amount, fee, route_id, participant.username, user.participant.username, note, status, ref))

if amount < 0:
# For payouts, we need to take the fee out of their Gratipay balance.
Expand Down Expand Up @@ -96,6 +100,7 @@ if request.method == 'POST':
</select>
<br>
<input name="note" placeholder="note" style="width: 420px" />
<input name="ref" placeholder="ref" />
<h2>Route</h2>
{% for route in routes %}
<input type="radio" name="route_id" value="{{ route.id }}">
Expand Down

0 comments on commit 8c52955

Please sign in to comment.