mirror of
https://github.com/kennethreitz-archive/www.gittip.com.git
synced 2026-06-21 15:50:59 +00:00
28cb48c72a
I sort of did this one with the blast shield down. I haven't even run
the tests yet. The sorts of things I changed:
- SQL {elsewhere,exchanges}.participant_id => .participant
- SQL participants.id => .username
- ORM {user,participant,self}.id => .username
45 lines
1.5 KiB
JSON
45 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
|
|
|
|
#=========================================================================== ^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": ""}
|
|
|
|
response.body = out
|