Skip to content

Instantly share code, notes, and snippets.

View adamjstevenson's full-sized avatar
🏄‍♂️

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@adamjstevenson
adamjstevenson / gist:373cb6cc730f9b20c70d
Last active October 6, 2015 16:49
Passing shipping information with a charge in PHP
<?
\Stripe\Charge::create(array(
"amount" => 400,
"currency" => "usd",
"source" => $_POST['stripeToken'], // obtained with Stripe.js.
"description" => "Charge for test@example.com",
"shipping" => array(
"name" => $_POST['stripeShippingName'],
"address" => array(
"line1" => $_POST['stripeShippingAddressLine1'],
@adamjstevenson
adamjstevenson / webhook_notification.php
Last active October 4, 2015 19:39
Notify subscription customers of failed payments
<?php
// Sends an email to customers if their payment fails
// If you're using Composer, use Composer's autoload
require_once('vendor/autoload.php');
// Be sure to replace this with your actual test API key
\Stripe\Stripe::setApiKey("sk_test_YourAPIKey");
// Retrieve the request's body and parse it as JSON
@adamjstevenson
adamjstevenson / iterate_charges.py
Last active October 6, 2015 14:12
Iterate through Stripe charges in Python
import stripe
# Be sure to use your API key - https://dashboard.stripe.com/account/apikeys
stripe.api_key = "sk_your_secret_key"
charges = stripe.Charge.all(limit=100)
for charge in charges.data:
print(charge.id)
@adamjstevenson
adamjstevenson / connect_sub.php
Created October 23, 2015 21:59
PHP Stripe Connect subscription flow
<?php
// Create a customer and subscribe them to a plan on a connected account -- should add some error handling
// Set your secret key -- generally this should be stored in a config file or ENV variable separate from this code
\Stripe\Stripe::setApiKey(PLATFORM_SECRET_KEY);
$token = $_POST['stripeToken'];
$acct = "acct_yourConnectedAcctID";
// Create a customer on the connected account
@adamjstevenson
adamjstevenson / upcoming_transfer.rb
Created November 3, 2015 23:02
Find the amount of an upcoming transfer
txns = Stripe::BalanceTransaction.all(:available_on => 1447113600)
amount = 0
txns.data.each do |txn|
amount += txn.net # return the net amount with fees removed
end
transfer_amt = '%.2f' % (amount/100.0)
require 'stripe'
Stripe.api_key = "sk_your_API_key"
customers = Stripe::Customer.all(:limit => 100)
customers.each do |customer|
puts customer.id
end
@adamjstevenson
adamjstevenson / paginate_charges.rb
Last active December 15, 2017 13:06
Paginate through all Stripe charges in Ruby
# require Stripe's Ruby bindings
require 'stripe'
# set your secret API key. You should generally store this in an evironment variable.
Stripe.api_key = "sk_your_key"
# grab the first 100 charges
charges = Stripe::Charge.list(limit: 100)
# print the charge ID for each
@adamjstevenson
adamjstevenson / paginate_customers_with_created_date.php
Last active June 8, 2021 19:09
Paginate Stripe customers created in the last month
<?php
// Load Stripe's PHP bindings and set your API key
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey('sk_your_api_key');
// Retrieve the first 100 customers created in the last month
$customers = \Stripe\Customer::all(array("limit" => 100, "created" => array("gte" => strtotime("-1 month"))));
// Iterate through the first 100 and output the customer ID and created date
@adamjstevenson
adamjstevenson / paginate_failed_charges.py
Created November 22, 2015 20:10
Paginate failed Stripe charges (Python)
import stripe
stripe.api_key = "sk_your_api_key"
charges = stripe.Charge.all(limit=100, paid='false', include=['total_count'])
print (str(charges.total_count) + ' charges failed.')
for charge in charges.data:
print(charge.id + ' failed. Failure code: '+charge.failure_code)
@adamjstevenson
adamjstevenson / paginate_events_by_type.js
Last active December 15, 2017 13:06
Paginate Stripe `invoice.payment_succeeded` events (Node)
var stripe = require('stripe')('sk_your_api_key');
stripe.events.list(
{ limit: 100, type: 'invoice.payment_succeeded' },
function(err, events) {
for (i = 0; i < events.data.length; i++){
console.log(events.data[i].id);
}
if (events.has_more) {
paginateEvents(events["data"][events["data"].length - 1].id);