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) {
event.preventDefault();
$('#upgradeForm').submit(function(event) { if ($('#stripe_token').val() === '') {
if($('#stripe_token').val() != '') Stripe.card.createToken({
return true number: $('[name="cc_number"]').val(),
cvc: $('[name="cc_cvc"]').val(),
var signupform = $(event.target) exp_month: $('[name="cc_exp_month"]').val(),
exp_year: $('[name="cc_exp_year"]').val()
var planError = $('#plan_error') }, stripeResponseHandler);
planError.css('display', 'none') return false;
signupform.find(':submit').prop('disabled', true)
Stripe.card.createToken({
number: $('[name="cc_number"]').val(),
cvc: $('[name="cc_cvc"]').val(),
exp_month: $('[name="cc_exp_month"]').val(),
exp_year: $('[name="cc_exp_year"]').val()
}, function(status, response) {
if(response.error) {
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>