Skip to content

Instantly share code, notes, and snippets.

@michaelvillar
Created October 24, 2013 23:07
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaelvillar/7146708 to your computer and use it in GitHub Desktop.
Save michaelvillar/7146708 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'stripe'
set :publishable_key, ENV['PUBLISHABLE_KEY']
set :secret_key, ENV['SECRET_KEY']
Stripe.api_key = settings.secret_key
get '/' do
erb :index
end
post '/charge' do
@amount = 500
customer = Stripe::Customer.create(
:email => 'customer@example.com',
:card => params[:stripeToken]
)
charge = Stripe::Charge.create(
:amount => @amount,
:description => 'Sinatra Charge',
:currency => 'usd',
:customer => customer
)
erb :charge
end
__END__
@@ layout
<!DOCTYPE html>
<html>
<head></head>
<body>
<%= yield %>
</body>
</html>
@@index
<form action="/charge" method="post">
<article>
<label class="amount">
<span>Amount: $5.00</span>
</label>
</article>
<script src="https://checkout.stripe.com/v3/checkout.js" class="stripe-button" data-key="<%= settings.publishable_key %>"></script>
</form>
@@charge
<h2>Thanks, you paid <strong>$5.00</strong>!</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment