Skip to content

Instantly share code, notes, and snippets.

@evanwhalen
Created February 4, 2014 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanwhalen/8813687 to your computer and use it in GitHub Desktop.
Save evanwhalen/8813687 to your computer and use it in GitHub Desktop.
# in template
<%= form_tag subscription_path, id: 'payment-form' %>
<script>
$(function() {
var handler = StripeCheckout.configure({
key: "<%= Rails.configuration.stripe[:publishable_key] %>",
token: function(token, args) {
var form = $("#payment-form");
form.append("<input type='hidden' name='stripe_token' value='" + JSON.stringify(token) + "'/>");
form.get(0).submit();
}
});
$('.paymentButton').click(function(e) {
// Open Checkout with further options
handler.open({
name: 'Subscription',
description: 'Starter Plan ($20.00)',
amount: 2000
});
e.preventDefault();
});
})
</script>
# in controller
Stripe::Customer.create(
card: JSON.parse(params[:stripe_token]),
plan: :starter,
email: current_user.email
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment