Skip to content

Instantly share code, notes, and snippets.

Thorsten Schaeff tschaeff

Block or report user

Report or block tschaeff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View README.md
View customer.erb
<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>
View app.rb
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)
View customers.erb
<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>
View app.rb
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
View app.rb
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
View index.erb
<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"
@tschaeff
tschaeff / app.rb
Last active May 15, 2016
Advanced Stripe Integration Training: Customers + Subscriptions
View app.rb
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
@tschaeff
tschaeff / README.md
Last active May 15, 2016 — forked from caseywatts/Gemfile
Sinatra + Stripe on Cloud9
View README.md

Cloud 9 - Sinatra + Stripe

Setting Up Cloud9

  • Go to c9.io and log in
  • Create a new workspace
    • Workspace name = hello-stripe
    • Clone from Git or Mercurial URL = https://gist.github.com/f71ef966f488ab8fd984e0791cf96c07.git
    • (everything else at defaults)
@tschaeff
tschaeff / stripe_one_time_charge.php
Last active Apr 10, 2019
Best practice example for creating one time charges using Stripe.js and Stripe's PHP bindings without creating customer objects.
View stripe_one_time_charge.php
<!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>
You can’t perform that action at this time.