diff --git a/bin/masspay.py b/bin/masspay.py index 849cc6e69a..228e719de5 100755 --- a/bin/masspay.py +++ b/bin/masspay.py @@ -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): @@ -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)): @@ -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: diff --git a/www/~/%username/history/record-an-exchange.spt b/www/~/%username/history/record-an-exchange.spt index 9f708b7e87..cb25ee56bf 100644 --- a/www/~/%username/history/record-an-exchange.spt +++ b/www/~/%username/history/record-an-exchange.spt @@ -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. @@ -96,6 +100,7 @@ if request.method == 'POST':
+

Route

{% for route in routes %}