Created
October 24, 2013 23:07
-
-
Save michaelvillar/7146708 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
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 => '[email protected]', | |
: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