Skip to content

Instantly share code, notes, and snippets.

@hassanjamal
Last active August 29, 2015 14:19
Show Gist options
  • Save hassanjamal/70fcfc54afbce9f5788d to your computer and use it in GitHub Desktop.
Save hassanjamal/70fcfc54afbce9f5788d to your computer and use it in GitHub Desktop.
StripeJs javacript code
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
(function(){
var StripeBilling = {
init: function(){
this.form = $('#checkout-wizard');
this.submitButton = this.form.find('input[type=submit]');
var StripeKey = $('meta[name="stripe-publishable-key"]').attr('content');
Stripe.setPublishableKey(StripeKey);
this.bindEvents();
},
bindEvents: function(){
this.form.on('submit', $.proxy(this.sendToken,this));
},
sendToken: function(e){
e.preventDefault();
this.submitButton.val('Checking !!');
this.submitButton.prop('disabled', true);
Stripe.card.createToken(this.form, $.proxy(this.stripeResponseHandler ,this));
return false;
},
stripeResponseHandler: function(status, response){
if(response.error){
this.submitButton.val('Try Again !!');
this.form.find('#card-error').show();
this.form.find('.payment-error').text(response.error.message);
return this.submitButton.prop('disabled', false);
}
var token = response.id;
// Insert the token into the form so it gets submitted to the server
this.form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and submit
this.form.get(0).submit();
}
};
StripeBilling.init();
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment