Created
August 21, 2015 15:06
-
-
Save cryptixcoder/d1ae5e72075647d9918d to your computer and use it in GitHub Desktop.
Stripe Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.checkout').submit(function(e){ | |
e.preventDefault(); | |
var stripeKey = $('meta[name=stripe-publishable-key]').attr('content'); | |
var form = $(this); | |
form.find('button').prop('disabled', true); | |
var number = form.find('#ccnumber').val(); | |
var securitycode = form.find('#securitycode').val(); | |
var exp = form.find('#expdate').val().split; | |
Stripe.setPublishableKey(stripeKey); | |
Stripe.card.createToken({ | |
number: number, | |
cvc: securitycode, | |
exp_month: exp[0], | |
exp_year: exp[1] | |
}, function(status, response){ | |
if(response.error){ | |
$('.message-wrapper').addClass('alert alert-danger').text(response.error.message); | |
form.find('button').prop('disabled', false); | |
} | |
else{ | |
var token = response.id; | |
form.append($("<input type='hidden' name='stripeToken'/>").val(token)); | |
$.ajax({ | |
url: form.attr('action'), | |
type: 'POST', | |
data: form.serialize(), | |
success: function(response){ | |
if(response.error){ | |
$('.message-wrapper').addClass('alert alert-danger').text(response.error); | |
form.find('button').prop('disabled', false); | |
} | |
else{ | |
//Do thankyou | |
} | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment