Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3580 from gratipay/prune-bank-accounts-from-UI
Browse files Browse the repository at this point in the history
prune bank accounts from UI
  • Loading branch information
rohitpaulk committed Jun 23, 2015
2 parents a2f88e5 + b1113a7 commit 504e1cc
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 269 deletions.
59 changes: 0 additions & 59 deletions js/gratipay/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,65 +62,6 @@ Gratipay.routes.associate = function (network, address) {
};


// Bank Accounts
// =============

Gratipay.routes.ba = {};

Gratipay.routes.ba.init = function() {
Gratipay.routes.init();

// Lazily depend on Balanced.
Gratipay.routes.lazyLoad("https://js.balancedpayments.com/1.1/balanced.min.js")

$('form#bank-account').submit(Gratipay.routes.ba.submit);
};

Gratipay.routes.ba.submit = function (e) {
e.preventDefault();

$('button#save').prop('disabled', true);
Gratipay.forms.clearInvalid($(this));

var bankAccount = {
name: $('#account_name').val(),
account_number: $('#account_number').val(),
account_type: $('#account_type').val(),
routing_number: $('#routing_number').val()
};

// Validate routing number.
if (bankAccount.routing_number) {
if (!balanced.bankAccount.validateRoutingNumber(bankAccount.routing_number)) {
Gratipay.forms.setInvalid($('#routing_number'));
Gratipay.forms.focusInvalid($(this));
$('button#save').prop('disabled', false);
return false
}
}

// Okay, send the data to Balanced.
balanced.bankAccount.create(bankAccount, function (response) {
if (response.status_code !== 201) {
return Gratipay.routes.ba.onError(response);
}

/* The request to tokenize the thing succeeded. Now we need to associate it
* to the Customer on Balanced and to the participant in our DB.
*/
Gratipay.routes.associate('balanced-ba', response.bank_accounts[0].href);
});
};

Gratipay.routes.ba.onError = function(response) {
$('button#save').prop('disabled', false);
var msg = response.status_code + ": " +
$.map(response.errors, function(obj) { return obj.description }).join(', ');
Gratipay.notification(msg, 'error', -1);
return msg;
};


// Credit Cards
// ============

Expand Down
3 changes: 1 addition & 2 deletions templates/profile-subnav.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
{% set u = participant.username %}
{% set pages = [ ('/', _('Dashboard'), True, False)
, ('/~'+u+'/', _('Profile'), True, show_profile)
, ('/~'+u+'/subscriptions/', _('Subscriptions'), True, False)
, ('/~'+u+'/subscriptions/', _('Subscriptions'), True, False)
, ('/~'+u+'/history/', _('History'), True, False)
, ('/~'+u+'/widgets/', _('Widgets'), True, False)
, ('/~'+u+'/identity', _('Identity'), True, False)
, ('/~'+u+'/settings/', _('Settings'), True, False)
, ('/~'+u+'/events/', _('Events'), False, False)
] %}
Expand Down
4 changes: 0 additions & 4 deletions tests/py/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,3 @@ def test_team_slug__not__redirected_from_tilde(self):
self.make_team(is_approved=True)
assert self.client.GET("/TheATeam/").code == 200
assert self.client.GxT("/~TheATeam/").code == 404

def test_anon_bank_acc_page(self):
body = self.client.GET("/~alice/routes/bank-account.html").body
assert "<h1>Bank Account</h1>" in body
49 changes: 0 additions & 49 deletions tests/py/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,6 @@ def test_associate_invalid_card(self):
self.hit('roman', 'associate', 'braintree-cc', 'an-invalid-nonce', expected=400)
assert self.roman.get_credit_card_error() is None

def test_associate_and_delete_bank_account_valid(self):
bank_account = balanced.BankAccount( name='Alice G. Krebs'
, routing_number='321174851'
, account_number='9900000001'
, account_type='checking'
).save()
customer = self.david.get_balanced_account()
customer.merchant_status = 'underwritten'
with mock.patch.object(Participant, 'get_balanced_account') as gba:
gba.return_value = customer
self.hit('david', 'associate', 'balanced-ba', bank_account.href)

bank_accounts = customer.bank_accounts.all()
assert len(bank_accounts) == 1
assert bank_accounts[0].href == bank_account.href

assert self.david.get_bank_account_error() == ''
assert self.david.has_payout_route

self.hit('david', 'delete', 'balanced-ba', bank_account.href)

david = Participant.from_username('david')
route = ExchangeRoute.from_address(david, 'balanced-ba', bank_account.href)
assert route.error == david.get_bank_account_error() == 'invalidated'
assert david.balanced_customer_href

# Check that update_error doesn't update an invalidated route
route.update_error('some error')
assert route.error == david.get_bank_account_error() == 'invalidated'
assert not self.david.has_payout_route

@mock.patch.object(Participant, 'get_balanced_account')
def test_associate_bank_account_invalid(self, gba):
gba.return_value.merchant_status = 'underwritten'
self.hit('david', 'associate', 'balanced-ba', '/bank_accounts/BA123123123', expected=400)
assert self.david.get_bank_account_error() is None
assert not self.david.has_payout_route

@mock.patch.object(Participant, 'send_email')
def test_associate_paypal(self, mailer):
mailer.return_value = 1 # Email successfully sent
Expand All @@ -103,17 +65,6 @@ def test_associate_bitcoin_invalid(self):
self.hit('david', 'associate', 'bitcoin', '12345', expected=400)
assert not ExchangeRoute.from_network(self.david, 'bitcoin')

def test_bank_account_page(self):
expected = "add or change your bank account"
actual = self.client.GET('/~alice/routes/bank-account.html').body
assert expected in actual

def test_bank_account_page_auth(self):
self.make_participant('alice', claimed_time='now')
expected = '<em id="status">not connected</em>'
actual = self.client.GET('/~alice/routes/bank-account.html', auth_as='alice').body
assert expected in actual

def test_credit_card_page(self):
self.make_participant('alice', claimed_time='now')
expected = "add or change your credit card"
Expand Down
8 changes: 1 addition & 7 deletions www/about/stats.spt
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,7 @@ def out():
<p><b><a href="/about/me/routes/credit-card.html" class="highlight">Click
here to set up a credit card</a></b>.{% endif %}</p>

<p><b>${{ commaize(escrow, 2) }}</b> is escrowed within Gratipay.
{{ nach }} people have connected a bank account</a> for withdrawals.
{% if not user.ANON and user.participant.get_bank_account_error() == '' %}You're one of them.
{% elif not user.ANON %}You're not one of them.</p>

<p><b><a href="/about/me/routes/bank-account.html" class="highlight">Click
here to connect a bank account</a></b>.{% endif %}</p>
<p><b>${{ commaize(escrow, 2) }}</b> is escrowed within Gratipay.</p>

<p><b>${{ commaize(transfer_volume, 2) }}</b> changed hands
<b>{{ last_thursday }}</b>.</p>
Expand Down
129 changes: 0 additions & 129 deletions www/~/%username/routes/bank-account.html.spt

This file was deleted.

19 changes: 0 additions & 19 deletions www/~/%username/settings/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,6 @@ emails = participant.get_emails()
{% endif %}
</h2>
<table class="accounts">
<tr>
{% set ba_error = participant.get_bank_account_error() %}
<td class="account-type">
<img src="{{ website.asset('bank_account_icon.jpg') }}" />
</td>
<td class="account-details">
<div class="account-type">{{ _("Bank Account") }}</div>
{% if ba_error == "" %}
{{ _("Your bank account is {0}working{1}", "", "") }}
{% elif ba_error %}
{{ _("Your bank account is {0}failing{1}", "<b>"|safe, "</b>"|safe) }}
{% endif %}
</td>
<td class="account-action">
<a class="button auth-button" href="../routes/bank-account.html">{{
_("+ Add") if ba_error is none else _("Edit")
}}</a>
</td>
</tr>
<tr>
{% set paypal = ExchangeRoute.from_network(participant, 'paypal') %}
<td class="account-type">
Expand Down

0 comments on commit 504e1cc

Please sign in to comment.