Skip to content

Instantly share code, notes, and snippets.

@ArunGupta25
Created July 2, 2012 21:17
Show Gist options
  • Save ArunGupta25/3035749 to your computer and use it in GitHub Desktop.
Save ArunGupta25/3035749 to your computer and use it in GitHub Desktop.
$(".saved-cc-button").click(function () {
$("#savedpayer").hide();
$("#paying").show();
$.ajax({
type: 'POST',
url: '/stripe',
data: { loggedinid : <%= current_user.id %> },
headers: {
'X-Transaction': 'POST Example',
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
success: function(msg) {
//$("#paying").hide();
//console.log(msg);
alert("payment recieved");
},
error: function(a, b, c) {
console.log(a, b, c);
}
});
});
#POST '/stripe'
def stripe
# remember to change secret key to live key
Stripe.api_key = "M3t0pd80EUGG0ocyWtpoFqKBZsVyNsmE"
puts "HELLO@!!"
puts params
puts current_user
puts session
puts "HELLO!!!"
if params[:stripeToken]
# get the credit card details submitted by the form
token = params[:stripeToken]
# create a customer
customer = Stripe::Customer.create(
:card => token,
:description => current_user.id
)
# save the stripe_id to the user model
current_user.stripe_id = customer.id
current_user.save
end
# create the charge on Stripe's servers - this will charge the user's card
charge = Stripe::Charge.create(
:amount => 100, #amount in cents, again
:currency => "usd",
:customer => current_user.stripe_id
)
render :js => "alert(OK!);"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment