[deliver #36743191] move stripe implementation UI back to stripe.js
parent
1ab2383fec
commit
8bd7a5eb65
|
@ -8,8 +8,53 @@
|
|||
<link type="text/css" rel="stylesheet" href="/static/css/pledge.css" />
|
||||
<link href="/static/stripe/tag.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<script type="text/javascript" src="/static/stripe/tag.js"></script>
|
||||
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
Stripe.setPublishableKey('{{STRIPE_PK}}');
|
||||
</script>
|
||||
|
||||
<script type="application/x-javascript">
|
||||
|
||||
var $j = jQuery.noConflict();
|
||||
|
||||
|
||||
function stripeResponseHandler(status, response) {
|
||||
if (response.error) {
|
||||
// re-enable the submit button
|
||||
$j('.submit-button').removeAttr("disabled");
|
||||
// show the errors on the form
|
||||
$j(".payment-errors").html(response.error.message);
|
||||
} else {
|
||||
var form$ = $j("#payment-form");
|
||||
// token contains id, last4, and card type
|
||||
var token = response['id'];
|
||||
|
||||
// insert the token into the form so it gets submitted to the server
|
||||
form$.append("<input type='hidden' name='stripe_token' value='" + token + "' />");
|
||||
// and submit
|
||||
form$.get(0).submit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$j().ready(function() {
|
||||
$j("#payment-form").submit(function(event) {
|
||||
// disable the submit button to prevent repeated clicks
|
||||
$j('.submit-button').attr("disabled", "disabled");
|
||||
|
||||
Stripe.createToken({
|
||||
number: $j('.card-number').val(),
|
||||
cvc: $j('.card-cvc').val(),
|
||||
exp_month: $j('.card-expiry-month').val(),
|
||||
exp_year: $j('.card-expiry-year').val()
|
||||
}, stripeResponseHandler);
|
||||
|
||||
// prevent the form from submitting with the default action
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
@ -55,30 +100,31 @@
|
|||
</p>
|
||||
{% if request.user.credit.available %}<p>Although you have ${{request.user.credit.available}} in donation credits, you can't support a campaign with a mixture of credit card pledges and donations.{% endif %}
|
||||
<div id="cc_pledge">
|
||||
<span class="payment-errors"></span>
|
||||
<form action="" method="post" id="payment-form">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors }}
|
||||
{{ form.as_p }}
|
||||
<payment key="{{STRIPE_PK}}"></payment>
|
||||
<input name="cc_submit" type="submit" value="Verify Credit Card" id="cc_submit" />
|
||||
</form>
|
||||
<span class="payment-errors"></span>
|
||||
<form action="" method="POST" id="payment-form">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors }}
|
||||
{{ form.as_p }}
|
||||
<div class="form-row">
|
||||
<label>Card Number</label>
|
||||
<input id="card_Number" type="text" size="20" autocomplete="off" class="card-number"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>CVC</label>
|
||||
<input id="card_CVC" type="text" size="4" autocomplete="off" class="card-cvc"/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>Expiration (MM/YYYY)</label>
|
||||
<input id="card_ExpiryMonth" type="text" size="2" class="card-expiry-month"/>
|
||||
<span> / </span>
|
||||
<input id="card_ExpiryYear" type="text" size="4" class="card-expiry-year"/>
|
||||
</div>
|
||||
<input id="cc_submit" type="submit" class="submit-button" value="Verify Credit Card" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="application/x-javascript">
|
||||
|
||||
var $j = jQuery.noConflict();
|
||||
console.debug('setting up handlers in stripe.html');
|
||||
|
||||
$j('payment').bind('success.payment', function () {
|
||||
console.debug('success.payment ev');
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
|
|
@ -770,13 +770,18 @@ class FundPledgeView(FormView):
|
|||
|
||||
stripe_token = form.cleaned_data["stripe_token"]
|
||||
preapproval_amount = form.cleaned_data["preapproval_amount"]
|
||||
|
||||
logger.info('stripe_token:{0}, preapproval_amount:{1}'.format(stripe_token, preapproval_amount))
|
||||
|
||||
p = PaymentManager()
|
||||
|
||||
# if we get a stripe_token, create a new stripe account
|
||||
|
||||
account = p.make_account(transaction.user, stripe_token, host=transaction.host)
|
||||
logger.info('account.id: {0}'.format(account.id))
|
||||
try:
|
||||
account = p.make_account(transaction.user, stripe_token, host=transaction.host)
|
||||
logger.info('account.id: {0}'.format(account.id))
|
||||
except Exception, e:
|
||||
raise e
|
||||
|
||||
# GOAL: deactivate any older accounts associated with user
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
{% block extra_extra_head %}
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/campaign.css" />
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/pledge.css" />
|
||||
<link href="/static/stripe/tag.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
|
||||
|
||||
|
@ -31,7 +32,7 @@ function stripeResponseHandler(status, response) {
|
|||
// token contains id, last4, and card type
|
||||
var token = response['id'];
|
||||
// insert the token into the form so it gets submitted to the server
|
||||
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
|
||||
form$.append("<input type='hidden' name='stripe_token' value='" + token + "' />");
|
||||
// and submit
|
||||
form$.get(0).submit();
|
||||
}
|
||||
|
|
|
@ -227,10 +227,10 @@ def test_relaunch(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=True,
|
|||
|
||||
# now fill out the credit card
|
||||
|
||||
sel.execute_script("""document.getElementById("paymentNumber").value="4242424242424242";""")
|
||||
sel.execute_script("""document.getElementById("paymentExpiryMonth").value="01";""")
|
||||
sel.execute_script("""document.getElementById("paymentExpiryYear").value="14";""")
|
||||
sel.execute_script("""document.getElementById("paymentCVC").value="123";""")
|
||||
sel.execute_script("""document.getElementById("card_Number").value="4242424242424242";""")
|
||||
sel.execute_script("""document.getElementById("card_ExpiryMonth").value="01";""")
|
||||
sel.execute_script("""document.getElementById("card_ExpiryYear").value="14";""")
|
||||
sel.execute_script("""document.getElementById("card_CVC").value="123";""")
|
||||
|
||||
verify_cc_button = WebDriverWait(sel,10).until(lambda d: d.find_element_by_css_selector("input[value*='Verify Credit Card']"))
|
||||
verify_cc_button.click()
|
||||
|
|
Loading…
Reference in New Issue