mirror of
https://github.com/kennethreitz-archive/www.gittip.com.git
synced 2026-06-21 15:50:59 +00:00
715db59b5c
This funnel has three events: Opt In, Explicitly Tip, and Add Credit Card. The first is fired server-side immediately after an alias is performed (see comments inline). The other two are fired client-side, and any new events should be fired client-side as well.
43 lines
1.0 KiB
JSON
43 lines
1.0 KiB
JSON
"""Get or change the authenticated user's tip to this person.
|
|
"""
|
|
from decimal import InvalidOperation
|
|
|
|
from aspen import Response
|
|
|
|
# ========================================================================== ^L
|
|
|
|
out = {}
|
|
if not user.ANON:
|
|
|
|
# Get tipper and tippee.
|
|
# ======================
|
|
# XXX We could/should enforce that tips cannot be pledged at all to locked
|
|
# accounts.
|
|
|
|
tipper = user.username
|
|
tippee = path['username']
|
|
|
|
|
|
# Get and maybe set amount.
|
|
# =========================
|
|
|
|
if tippee == tipper:
|
|
amount = None
|
|
elif POST and 'amount' in body:
|
|
try:
|
|
amount, first_time_tipper = user.set_tip_to(tippee, body['amount'])
|
|
except (InvalidOperation, ValueError):
|
|
raise Response(400, "bad amount")
|
|
else:
|
|
amount = user.get_tip_to(tippee)
|
|
|
|
total_giving = user.get_dollars_giving()
|
|
|
|
out = { "amount": str(amount)
|
|
, "total_giving": str(total_giving)
|
|
, "first_time": first_time_tipper
|
|
}
|
|
|
|
|
|
response.body = out
|