Skip to content

Instantly share code, notes, and snippets.

@leoken
Forked from elricstorm/_head.mobile.erb
Created May 13, 2012 21:30
Show Gist options
  • Save leoken/2690273 to your computer and use it in GitHub Desktop.
Save leoken/2690273 to your computer and use it in GitHub Desktop.
<%= stylesheet_link_tag 'mobile/jquery.mobile-1.0.1.min', 'mobile/mobile' %>
<%= javascript_include_tag 'mobile/respond.min' %>
<%= javascript_include_tag 'mobile/jquery', 'mobile/jquery_ujs', "https://js.stripe.com/v1/", 'orders' %>
<%= javascript_include_tag 'mobile/jquery.mobile-1.0.1.min' %>
<%= csrf_meta_tag %>
<%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %>
(function () {
var order;
jQuery(function () {
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'));
return order.setupForm();
});
order = {
setupForm:function () {
return $('#new_order').submit(function () {
$('input[type=submit]').attr('disabled', true);
if ($('#card_number').length) {
order.processCard();
return false;
} else {
return true;
}
});
},
processCard:function () {
var card = {
number: $('#card_number').val(),
cvc: $('#card_code').val(),
expMonth: $('#card_month').val(),
expYear: $('#card_year').val()
};
//evalMsg(card);
return Stripe.createToken(card, order.handleStripeResponse);
},
handleStripeResponse:function (status, response) {
if (status === 200) {
$('#order_stripe_card_token').val(response.id);
return $('#new_order')[0].submit();
} else {
$('#stripe_error').text(response.error.message);
return $('input[type=submit]').attr('disabled', false);
}
}
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment