Skip to content

Commit

Permalink
add return url to views and forms fix #488, fix #463
Browse files Browse the repository at this point in the history
  • Loading branch information
jdungan committed Jun 10, 2017
1 parent 1f26ccb commit 030addc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
3 changes: 1 addition & 2 deletions auctions/templates/includes/payout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ <h3>Your claim was approved!</h3>
{% else %}

<h3>You need to tell us where to send your payout.</h3>

<li><a class="success button expanded" href="{% url 'bank' %}">Register a bank account</a></li>
<li><a class="success button expanded" href="{% url 'bank' %}?return_url={{ return_url }}">Register a bank account</a></li>

{% endif %}

Expand Down
1 change: 1 addition & 0 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def get_context_data(self, **kwargs):
except:
pass
context = dict({
'return_url' : self.request.path,
'claim': claim,
'vote': vote,
'aggregate_payout': total_payout
Expand Down
3 changes: 3 additions & 0 deletions payments/templates/bank_account_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<legend>Bank Account Information</legend>
<form id="stripe-form" stripe-account-type="bankAccount" role="form" class="form-horizontal">
{% csrf_token %}
{%if return_url %}
<input type="hidden" id="return_url" value="{{return_url}}">
{% endif %}
<input type="hidden" data-stripe="country" value="US">
<input type="hidden" data-stripe="currency" value="USD">
<input type="hidden" id="account_holder_type" data-stripe="account_holder_type" value="individual">
Expand Down
3 changes: 3 additions & 0 deletions payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BankAccountView(BankAccountTestsMixin, TemplateView):

def get_context_data(self, **kwargs):
ctx = super(BankAccountView, self).get_context_data(**kwargs)
ctx['return_url'] = self.request.GET.get('return_url','')
ctx['STRIPE_DEBUG'] = stripe_debug_values()
return ctx

Expand Down Expand Up @@ -164,6 +165,8 @@ def post(self, *args, **kwargs):

stripe_acct.save()



return redirect('bank')


Expand Down
45 changes: 34 additions & 11 deletions static/js/codesy-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,47 @@ $(window).load(function () {
}

function stripeResponse (csrf_token, response_filter) {
return function (status, response) {
let message = "Account information successfully submitted"
redirect = (url) => {window.location = url};
const return_url = $('#return_url').val()

function complete_submit (message) {
$('#stripe-response').remove();
$('#stripe-form').prepend(response_div(message));
$('#stripe-submit').text('Submit Account Information');
}

function ajax_before (xhr, settings) {
xhr.setRequestHeader('X-CSRFToken', csrf_token)
}

function ajax_success (data, status, jqXHR) {
console.log("Updated user.");
if ( return_url ) {
redirect(return_url)
} else {
complete_submit("Account information successfully submitted")
};
}

function ajax_error (jqXHR, textStatus, errorThrown){
console.error(errorThrown, textStatus)
complete_submit(textStatus)
}

return function (status, response){
if (response.error) {
message = response.error.message;
console.error(`Stripe failed to tokenize: ${message}`);
console.error(`Stripe failed to tokenize: ${response.error.message}`);
complete_submit(response.error.message)
} else {
$.ajax({
method: "PATCH",
url: "/users/update/",
beforeSend: (xhr, settings) => xhr.setRequestHeader('X-CSRFToken', csrf_token),
beforeSend: ajax_before,
data: response_filter(response),
success: (data, status, jqXHR) => console.log("Updated user."),
error: ()=>console.error("nope")
});
success: ajax_success,
error: ajax_error
})
}
$('#stripe-response').remove()
$('#stripe-form').prepend(response_div(message))
$('#stripe-submit').text('Submit Account Information');
}
}

Expand Down

0 comments on commit 030addc

Please sign in to comment.