Skip to content

Commit

Permalink
Merge 2e8df2d into 0f6eb06
Browse files Browse the repository at this point in the history
  • Loading branch information
jdungan committed Apr 18, 2017
2 parents 0f6eb06 + 2e8df2d commit 85816a6
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 140 deletions.
3 changes: 0 additions & 3 deletions auctions/templates/claim_status.html
Expand Up @@ -49,6 +49,3 @@ <h4><i class="fi-link"></i> <a target="_blank" href='{{ claim.evidence }}'>{{ cl
</div>

{% endblock %}

{% block scripts %}
{% endblock %}
2 changes: 1 addition & 1 deletion auctions/templates/includes/vote_form.html
Expand Up @@ -9,7 +9,7 @@ <h3>Do you approve this claim?</h3>
</form>
</div>
<div class="medium-6 columns">
<form id="codesy_reject" class="ajaxSubmit" action="{% url 'vote-list' %}" data-method="POST">
<form id="codesy_reject" class="vote-submit" action="{% url 'vote-list' %}" data-method="POST">
{% csrf_token %}
<input type="hidden" name="claim" value="{{claim.id}}">
<input type="hidden" name="approved" value="False">
Expand Down
4 changes: 0 additions & 4 deletions codesy/templates/account/account_inactive.html
Expand Up @@ -16,7 +16,3 @@ <h4>Thanks for signing up!</h4>
</div>

{% endblock %}

{% block scripts %}
<script type="text/javascript" src="{% static "js/share.js" %}"></script>
{% endblock %}
5 changes: 4 additions & 1 deletion codesy/templates/base.html
Expand Up @@ -89,9 +89,12 @@

<script src="https://cdn.jsdelivr.net/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/foundation/6.1.2/foundation.min.js"></script>
<script src="{% static "js/home-app.js" %}" ></script>
<script src="{% static "js/codesy-app.js" %}" ></script>
<script src="{% static "js/analytics.js" %}" ></script>
{% block scripts %}
{% if request.user.is_authenticated %}
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
{% endif %}
{% endblock %}
</body>
</html>
7 changes: 0 additions & 7 deletions codesy/templates/home.html
Expand Up @@ -44,10 +44,3 @@
{% include "includes/get_started.html" %}
</div>
{% endblock %}

{% block scripts %}
{% if request.user.is_authenticated %}
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript" src="{% static 'js/stripe-app.js' %}" ></script>
{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion payments/templates/bank_account_page.html
@@ -1,4 +1,4 @@
{% extends "stripe_base.html" %}
{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
Expand Down
5 changes: 4 additions & 1 deletion payments/templates/credit_card_page.html
@@ -1,4 +1,4 @@
{% extends "stripe_base.html" %}
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div class="row">
Expand All @@ -7,7 +7,9 @@
We saved your <b> {{request.user.card_brand}}</b> card ending in <b> {{ request.user.card_last4}} </b> with Stripe.

<div class="reveal" id="credit_card_form" data-reveal>

{% include "credit_card_form.html" %}

<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
Expand All @@ -18,6 +20,7 @@
{% else %}
You need to register a credit card to be able to make offers.
We use Stripe to handle this information and it is never stored in codesy's database.

{% include "credit_card_form.html" %}

{% endif %}
Expand Down
12 changes: 0 additions & 12 deletions payments/templates/stripe_base.html

This file was deleted.

4 changes: 2 additions & 2 deletions payments/templates/verify_identity.html
@@ -1,4 +1,4 @@
{% extends "stripe_base.html" %}
{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
Expand Down Expand Up @@ -79,7 +79,7 @@
{% endif %}

<button
id="codesy-submit"
id="codesy-submit-identity"
class="button success track-btn"
data-category="Stripe"
data-label="Authorize">Send to Stripe
Expand Down
2 changes: 2 additions & 0 deletions static/js/analytics.js
@@ -1,3 +1,5 @@


var ga_id = $('#codesy-html').data('ga_id');
var ga_filename = $('#codesy-html').data('ga_filename');

Expand Down
114 changes: 114 additions & 0 deletions static/js/codesy-app.js
@@ -0,0 +1,114 @@
function response_div(message){
$div= $(`<div id="stripe-response" class="callout warning expanded" data-closable>
<button class="close-button" data-close>&times;</button>
<p class="alert alert-error"></p>
</div>`)
$div.find('p').text(message)
return $div
}

// remove any notification divs when any modal form closes
$(window).on('closed.zf.reveal', ()=>$('#stripe-response').remove());

function make_codesy_submitter (account_type){
switch (account_type) {
case 'card':
return ({ id, card: {last4, brand} }) => ({stripe_card: id, card_last4: last4, card_brand: brand});
break;
case 'bankAccount':
return ({id}) => ({stripe_bank_account: id});
break;
default:
return ()=>{}
};
}


function make_submit_form (csrf_token){
return function (e) {
e.preventDefault();
form = $(this)
$.ajax( {
url: form.attr('action'),
method: form.data("method"),
data: form.serialize(),
processData: false,
headers: {'X-CSRFToken': csrf_token},
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success: (data, textStatus, jqXHR) => window.location.reload(),
error: console.error
}
);
}
}


function stripeResponse (csrf_token, type) {
const codesy_data = make_codesy_submitter(type)
return function (status, response) {
if (response.error) {
console.error(`Stripe failed to tokenize: ${response.error.message}`);
response_message = response.error.message
} else {
response_message = "Account information successfully submitted"
$.ajax({
method: "PATCH",
url: "/users/update/",
beforeSend: (xhr, settings) => xhr.setRequestHeader('X-CSRFToken', csrf_token),
data: codesy_data(response),
success: (data, status, jqXHR) => console.log("Updated user."),
error: console.error
});
}
$('#stripe-response').remove()
$('#stripe-form').prepend(response_div(response_message))
$('#stripe-submit').text('Submit Account Information');
}
}

function set_holder_type($element) {
const holder_type = $("input[name=form_holder_type]:checked").val()
if (holder_type) $element.val(holder_type)
}

// create codesy object for ga analytics
window.codesy = {};



$(window).load(function () {
// start foundation js
$(document).foundation();

const csrf_token_value = $('form input[name="csrfmiddlewaretoken"]').val()



// form loads
const $stripe_form = $('#stripe-form')
$($stripe_form ).ready(()=>{
Stripe.setPublishableKey($('#codesy-html').data('stripe_key'));
const stripe_account_type = $stripe_form .attr('stripe-account-type')
const handleResponse = new stripeResponse(csrf_token_value, stripe_account_type)

$('#stripe-submit').click(function (e) {
e.preventDefault();
set_holder_type($('#account_holder_type'))
$('#stripe-submit').text('Submitting ... ');
Stripe[stripe_account_type].createToken($stripe_form, handleResponse);
});
})


// events
$('.popup').click(function(e) {
var url = this.href;
window.open(url, 'Share', 'status=1,left=0,top=0,width=575,height=400');
return false;
});

$('form.vote-submit').load( () => make_submit_form(csrf_token_value) );

$('#codesy-submit-identity').click( (e)=> set_holder_type($('#type')) );

})
29 changes: 0 additions & 29 deletions static/js/home-app.js

This file was deleted.

5 changes: 0 additions & 5 deletions static/js/share.js

This file was deleted.

74 changes: 0 additions & 74 deletions static/js/stripe-app.js

This file was deleted.

0 comments on commit 85816a6

Please sign in to comment.