Skip to content

Instantly share code, notes, and snippets.

View andrewpthorp's full-sized avatar
🎯

Andrew Thorp andrewpthorp

🎯
View GitHub Profile
@andrewpthorp
andrewpthorp / index.html
Created January 9, 2014 22:04
Custom Checkout
<html>
<body>
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<form action="charge.php" method="POST">
<input type="hidden" name="stripeToken" class="token" />
<input type="hidden" name="stripeEmail" class="email" />
</form>
<form action="charge.php" method="POST" class="charge_form">
<div class="customButton">
<button>...</button>
<script>...</script>
</div>
</form>
cus = Stripe::Customer.retrieve('cus_id')
coupon = Stripe::Coupon.retrieve('coupon')
cus.coupon = coupon.id
cus.save
# times_redeemed = 1
cus.coupon = coupon.id
cus.save
var regex = /[^a-zA-Z ]+/;
if (name = "" || regex.test(name)){
// Invalid Name if you get here.
}
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<label><input type="radio" name="amount" value="2000" data-description="DESCRIBE $20 PRODUCT HERE">$20</label>
<label><input type="radio" name="amount" value="5000" data-description="DESCRIBE $50 PRODUCT HERE">$50</label>
<label><input type="radio" name="amount" value="10000" data-description="DESCRIBE $100 PRODUCT HERE">$100</label>
<script>
@andrewpthorp
andrewpthorp / metadata.php
Created December 9, 2013 06:02
Stripe: PHP Metadata
Stripe_Charge::create(array(
"amount" => 400,
"currency" => "usd",
"card" => "some_token_here", // obtained with Stripe.js,
"metadata" => array("key" => "value", "key2" => "value2")
));
@andrewpthorp
andrewpthorp / stripe_checkout.html
Created December 6, 2013 16:49
Sample Dynamic Emails in Stripe Checkout.
<html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="email" class="email-field" />
<button id="customButton">Purchase</button>
@andrewpthorp
andrewpthorp / invoices.rb
Created December 3, 2013 23:42
Invoice Items / Subscriptions
cus_invoices = Stripe::Invoice.all(:customer=>customer.id, :count=>1).data
cus_invoices.each do |invoices|
line_items = invoices.lines.data.each do |data|
if data.type == 'invoiceitem'
# Deal with InvoiceItem here.
elsif data.type == 'subscription'
# Deal with Subscription here.
<html>
<body>
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type="text" id="amount" />
<button id="customButton">Purchase</button>
<script>
@andrewpthorp
andrewpthorp / stripe.html
Created December 3, 2013 21:32
Stripe configuration for closed event.
<script>
var handler = StripeCheckout.configure({
key: 'pk_your_public_key',
token: function(token, args) {
// Use the token to create the charge with a server-side script.
},
closed: function(e) {
// The popup was closed.
}