refactor stripe js code to try to fix bug with missing token

This commit is contained in:
Kyle Drake 2024-02-03 23:31:54 -06:00
parent 51d65653e8
commit ce0e9d422a

View file

@ -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>