mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
refactor stripe js code to try to fix bug with missing token
This commit is contained in:
parent
51d65653e8
commit
ce0e9d422a
1 changed files with 24 additions and 33 deletions
|
@ -6,42 +6,33 @@
|
||||||
<script>
|
<script>
|
||||||
Stripe.setPublishableKey('<%= $config['stripe_publishable_key'] %>')
|
Stripe.setPublishableKey('<%= $config['stripe_publishable_key'] %>')
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
$('#upgradeForm').submit(function(event) {
|
$('#upgradeForm').submit(function(event) {
|
||||||
if($('#stripe_token').val() != '')
|
event.preventDefault();
|
||||||
return true
|
|
||||||
|
|
||||||
var signupform = $(event.target)
|
|
||||||
|
|
||||||
var planError = $('#plan_error')
|
|
||||||
planError.css('display', 'none')
|
|
||||||
signupform.find(':submit').prop('disabled', true)
|
|
||||||
|
|
||||||
|
if ($('#stripe_token').val() === '') {
|
||||||
Stripe.card.createToken({
|
Stripe.card.createToken({
|
||||||
number: $('[name="cc_number"]').val(),
|
number: $('[name="cc_number"]').val(),
|
||||||
cvc: $('[name="cc_cvc"]').val(),
|
cvc: $('[name="cc_cvc"]').val(),
|
||||||
exp_month: $('[name="cc_exp_month"]').val(),
|
exp_month: $('[name="cc_exp_month"]').val(),
|
||||||
exp_year: $('[name="cc_exp_year"]').val()
|
exp_year: $('[name="cc_exp_year"]').val()
|
||||||
}, function(status, response) {
|
}, stripeResponseHandler);
|
||||||
if(response.error) {
|
return false;
|
||||||
planError.text(response.error.message)
|
|
||||||
planError.css('display', 'block')
|
|
||||||
window.location = '#plan_error_link'
|
|
||||||
signupform.find(':submit').prop('disabled', false)
|
|
||||||
return false
|
|
||||||
} else {
|
} else {
|
||||||
$('.credit-card-input').text('Thank you!')
|
return true;
|
||||||
$('#stripe_token').val(response.id)
|
|
||||||
signupform.submit()
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
return false
|
function stripeResponseHandler(status, response) {
|
||||||
})
|
if (response.error) {
|
||||||
|
$('#plan_error').text(response.error.message).show();
|
||||||
$(function() {
|
} else {
|
||||||
$('#upgradeForm').find(':submit').prop('disabled', false)
|
var token = response.id;
|
||||||
})
|
$('#stripe_token').val(token);
|
||||||
|
$('#upgradeForm').off('submit').submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="/js/skeuocard.min.js"></script>
|
<script src="/js/skeuocard.min.js"></script>
|
Loading…
Add table
Reference in a new issue