This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathpayment-instruction.json.spt
65 lines (51 loc) · 2.06 KB
/
payment-instruction.json.spt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Get or change the authenticated user's payment instruction for this team.
"""
from decimal import InvalidOperation
from aspen import Response
from babel.numbers import NumberFormatError
from gratipay.exceptions import BadAmount
[-----------------------------------------------------------------------------]
if user.ANON:
raise Response(403, _("Please sign in first"))
else:
out = {}
# Get team.
# =========
team = request.path['team']
if team.is_closed or not team.is_approved:
raise Response(400, "unapproved team")
# Get and maybe set amount.
# =========================
if request.method == 'POST' and 'amount' in request.body:
try:
out = user.participant.set_payment_instruction(team, parse_decimal(request.body['amount']))
except (InvalidOperation, ValueError, BadAmount, NumberFormatError):
raise Response(400, "bad amount")
else:
out = user.participant.get_payment_instruction(team)
amount = out['amount']
total_giving = user.participant.giving
total_taking = user.participant.taking
out["amount"] = str(amount)
out["amount_l"] = format_currency(amount, 'USD')
if amount > 0:
out["msg"] = _("Payment changed to {0} per week. ", out["amount_l"])
out["msg"] += _("Thank you so much for supporting {0}!", team.name)
else:
out["msg"] = _("You have canceled your payment to {0}.", team.name)
out["nreceiving_from"] = team.nreceiving_from
out["team_id"] = team.id
out["total_giving"] = str(total_giving)
out["total_giving_l"] = format_currency(total_giving, 'USD')
out["total_taking"] = str(total_taking)
out["total_taking_l"] = format_currency(total_taking, 'USD')
total_receiving = team.receiving
out["total_receiving"] = str(total_receiving)
out["total_receiving_l"] = format_currency(total_receiving, 'USD')
if 'ctime' in out:
out["ctime"] = str(out['ctime'])
out["mtime"] = str(out['mtime'])
else:
out["ctime"] = out["mtime"] = None
[---] application/json via json_dump
out