Skip to content

Instantly share code, notes, and snippets.

View thorwebdev's full-sized avatar
🔨
building

Thor 雷神 Schaeff thorwebdev

🔨
building
View GitHub Profile
<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>
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)
<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>
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
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
<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"
@thorwebdev
thorwebdev / app.rb
Last active May 15, 2016 17:38
Advanced Stripe Integration Training: Customers + Subscriptions
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
@thorwebdev
thorwebdev / README.md
Last active May 15, 2016 16:45 — forked from caseywatts/Gemfile
Sinatra + Stripe on Cloud9

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)
@thorwebdev
thorwebdev / stripe_one_time_charge.php
Last active August 11, 2019 23:36
Best practice example for creating one time charges using Stripe.js and Stripe's PHP bindings without creating customer objects.
<!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>