Created
February 4, 2014 22:30
-
-
Save vanwhale/8813687 to your computer and use it in GitHub Desktop.
This file contains 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
# 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