Files
Chad Whitacre 715db59b5c Implement a mixpanel funnel; #686
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.
2013-04-08 21:54:16 -04:00

47 lines
1.5 KiB
JSON

"""Save a payment method token (balanced_account_uri) for a user.
When the user fills out the payment details form in the UI, we send the new
info to Balanced (using the balanced.js library). Balanced always gives us a
single-use token in return, provided that the credit card info validated. This
present script is called next. It takes the token and tries to associate it with
a Balanced account object (creating one as needed).
"""
from aspen import Response
from gittip import billing, mixpanel
#=========================================================================== ^L
if user.ANON:
raise Response(404)
request.allow('POST')
out = {}
if body.get('action') == 'delete':
billing.clear(u"credit card", user.username, user.balanced_account_uri)
elif body.get('action') == 'store-error':
billing.store_error(u"credit card", user.username, body['msg'])
else:
# Associate the single-use token representing the credit card details (we
# call it "card_uri" here because that's how Balanced refers to it).
# Possible error codes would be 409 (this card cannot be associated with
# this account in this case).
card_uri = body['card_uri']
error = billing.associate( u"credit card"
, user.username
, user.balanced_account_uri
, card_uri
)
if error:
out = {"problem": "Problem", "error": error}
else:
out = {"problem": ""}
out["first_time"] = user.last_bill_result is None
response.body = out