- Go to
c9.io
and log in - Create a new workspace
- Workspace name =
hello-stripe
- Clone from Git or Mercurial URL = https://github.com/tschaeff/stripe_checkout_integration_training.git
- (everything else at defaults)
- Workspace name =
This file contains hidden or 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
<h1><%= @customer.email %> // <%= @customer.id %></h1> | |
<h2># Subscriptions: <%= @customer.subscriptions.total_count %></h2> | |
<ol> | |
<% @customer.subscriptions.each do |sub| %> | |
<li><%= sub.plan.name %></li> | |
<%end%> | |
</ol> |
This file contains hidden or 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
get '/customer/:cid' do | |
# Output params hash in bash | |
puts params.inspect | |
# Retrieve customer ID from params hash | |
cid = params[:cid] | |
# Retrieve customer object from Stripe API | |
# Store customer object in an instance variable | |
@customer = Stripe::Customer.retrieve(cid) |
This file contains hidden or 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
<table> | |
<% @c.each do |customer| %> | |
<tr> | |
<td><%= customer.id %><td> | |
<td><%= customer.email %></td> | |
<td><a href="../customer/<%= customer.id %>">Subscriptions [<%= customer.subscriptions.total_count %>] </a></td> | |
</tr> | |
<% end %> | |
</table> |
This file contains hidden or 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
get '/customers' do | |
# Get a list of ten customers | |
customers = Stripe::Customer.all(:limit => 10) | |
# Store customer list in an instance variable | |
@c = customers.data | |
#Output customers.erb template to user | |
erb :customers | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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
<form action="/charge" method="POST"> | |
<script | |
src="https://checkout.stripe.com/checkout.js" class="stripe-button" | |
data-key="pk_test_****" | |
data-amount="2000" | |
data-name="schaeffonline.de" | |
data-description="2 widgets" | |
data-image="https://cdn.shopify.com/s/files/1/0302/2969/products/great-cookie-m_and_m-cookie-03_1024x1024.jpg" | |
data-locale="auto" | |
data-zip-code="true" |
This file contains hidden or 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 'sinatra/reloader' if development? | |
require "stripe" | |
Stripe.api_key = "sk_test_***" | |
get '/' do | |
# Output index.erb template to user | |
erb :index | |
end |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>One Time Charge</title> | |
<script type="text/javascript" src="https://js.stripe.com/v2/"></script> | |
</head> | |
<body> |
NewerOlder