From a46a074a019745e2f4e8f76756cb7de52b05ecb3 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Tue, 24 Jul 2012 11:11:15 -0400 Subject: [PATCH] Barely start payouts branch (#22) --- www/bank-account.html | 195 ++++++++++++++++++++++++++++++++++++++++++ www/bank-account.json | 42 +++++++++ 2 files changed, 237 insertions(+) create mode 100644 www/bank-account.html create mode 100644 www/bank-account.json diff --git a/www/bank-account.html b/www/bank-account.html new file mode 100644 index 0000000000..40a8bd3b6e --- /dev/null +++ b/www/bank-account.html @@ -0,0 +1,195 @@ +import traceback + +import balanced +from aspen import json, log, Response +from gittip import billing +from gittip.networks import github + +# ========================================================================== ^L + +if not user.ANON: + balanced_account_uri = user.balanced_account_uri + + status = "missing" + if balanced_account_uri: + working = not bool(user.last_bill_result) + status = "working" if working else "failing" + + if balanced_account_uri: + try: + card = billing.BalancedCard(balanced_account_uri) + except: # balanced is unavailable (or balanced_account_uri is bad?) + log(traceback.format_exc()) + payments_down = True + else: + assert balanced_account_uri == card['id'] + payments_down = False + + username = user.id +# ========================================================================== ^L +{% extends templates/base.html %} + + +{% block body %} +{% if user.ANON %} +
+

Credit Card

+ +

Sign in with +GitHub, and then you’ll be able to add or change your credit card. +Thanks! :-)

+ +
+ +{% else %} + + +
+ +

You are {{ user.id }}.

+

Your credit card is {{ status }}.

+ + {% if payments_down %} + +

We had a problem contacting our payment + processor. Could I ask if you’d be willing to try again + later? Thanksorry. :-(

+ + {% else %} + +

When you don’t have enough in your Gittip account to cover your + tips, we {% if balanced_account_uri %}will{% else %}can{% end %} pull money + in using {% if balanced_account_uri %}this{% else %}a{% end %} credit card. + If your credit card is missing or fails then your tips won’t go + through for that week.

+ + {% if not balanced_account_uri %} +

We are currently migrating your credit card information from one + processor, Stripe, to another, Balanced. Feel free to make + changes in the mean time.

+ {% else %} +

Credit card information is stored and processed by Balanced.

+ {% end %} + + {% if balanced_account_uri %} + +

Your current card is {{ card['last4'] }}.

+ +

Change your card on file.

+ {% elif stripe_customer_id %} + +

Your current card is {{ card['last4'] }}.

+ +

Change your card on file.

+ {% end %} + +
+
{% if user.last_bill_result %} +

Failure

+
+

{{ user.last_bill_result }}

+
+ {% end %}
+ + +

Required

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +

Optional

+ + + + +
+ + + + + + + + +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ {% end %} +
+ +
+

Delete credit card.

+ +

Your credit card details will immediately be completely purged from + Gittip.

+ +
+ + +
+
+ +
+{% end %} +{% end %} diff --git a/www/bank-account.json b/www/bank-account.json new file mode 100644 index 0000000000..ae36c9a7fd --- /dev/null +++ b/www/bank-account.json @@ -0,0 +1,42 @@ +"""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(user.id, user.balanced_account_uri) +elif body.get('action') == 'store-error': + billing.store_error(user.id, 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.get('card_uri') + if card_uri is None: + raise Response(400) + + error = billing.associate(user.id, user.balanced_account_uri, card_uri) + if error: + out = {"problem": "Problem", "error": error} + else: + out = {"problem": ""} + +response.body = out