Skip to content

Instantly share code, notes, and snippets.

@thorwebdev
Created May 15, 2016 17:21
Show Gist options
  • Save thorwebdev/7930c0528d2e961d5759a4b3287744e7 to your computer and use it in GitHub Desktop.
Save thorwebdev/7930c0528d2e961d5759a4b3287744e7 to your computer and use it in GitHub Desktop.
post '/charge' do
# Output the params hash with the values from Checkout in the bash
puts params.inspect
# Store Stripe Token and Customer Email Address in local variables
token = params[:stripeToken]
email = params[:stripeEmail]
# Create a new Customer
# Store the Response in a local variable
customer = Stripe::Customer.create(
:source => token,
:email => email,
:description => "Ruby customer"
)
# Charge the Customer instead of the card
Stripe::Charge.create(
:amount => 2000, # in cents
:currency => "eur",
:customer => customer.id
)
# Output the Customer ID to the user
"Successfully created customer with ID: #{customer.id}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment