Skip to content

Instantly share code, notes, and snippets.

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

Adam Stevenson adamjstevenson

🏄‍♂️
View GitHub Profile
@adamjstevenson
adamjstevenson / list_connected_balance_transactions_for_transfer.rb
Created September 15, 2016 18:11
List balance transactions for each transfer on a connected account
require 'stripe'
# Your platform API key
Stripe.api_key = "YOUR-API-KEY"
# The ID of the connected account
account = "acct_YourConnectedAccountID"
# Retrieve the last 10 transfers on the connected account
transfers = Stripe::Transfer.list({limit:10},{stripe_account: account})
@adamjstevenson
adamjstevenson / list_connected_upcoming_transfers.rb
Created September 15, 2016 16:52
List upcoming created transfers on a connected account
require 'stripe'
# Your platform's secret key
Stripe.api_key = "YOUR-API-KEY"
# List `transfer.created` events on the connected account
events = Stripe::Event.list({type: "transfer.created", limit: 100},{stripe_account: "acct_YourConnectedAccountID"})
# Iterate through each event
events.each do | event |
@adamjstevenson
adamjstevenson / list_connected_transfers_balance.rb
Created September 13, 2016 21:30
List Connected Account Transfers and Balance
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
account = "acct_YourConnectedAccountID"
# Retrieve available balance for the connected account
balance = Stripe::Balance.retrieve(stripe_account: account)
puts "Available balance: #{balance.available[0].amount}"
puts "Pending balance: #{balance.pending[0].amount}"
@adamjstevenson
adamjstevenson / connect_account_volume.rb
Last active November 3, 2023 13:31
Calculate gross and net transaction volume on a connected account
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
# Authenticate as the connected account and retrieve the first 100 transactions
transactions = Stripe::BalanceTransaction.list({limit: 100},{stripe_account: "acct_YourConnectedAcctID"})
total_volume = 0
net_volume = 0
# Iterate through transactions using auto-pagination
@adamjstevenson
adamjstevenson / list_connected_charges.rb
Last active December 15, 2017 13:03
List charges on a connected account
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
# Authenticate as the connected account and retrieve the first 100 charges
charges = Stripe::Charge.all({limit: 100},{stripe_account: "acct_YourConnectedAccountID"})
# Iterate through charges using auto-pagination
charges.auto_paging_each do |charge|
# Output the charge ID, amount, currency, refund, and dispute status
@adamjstevenson
adamjstevenson / update_payment_method.php
Last active September 3, 2016 14:59
Update default payment method for a customer with PHP
<?php
// Check for a POSTed stripeToken
if (isset($_POST['stripeToken'])){
// Retrieve the customer id from your database/app, e.g.
// $customer_id = $user->customer_id;
try {
$customer = \Stripe\Customer::retrieve($customer_id);
$customer->source = $_POST['stripeToken']; // The token submitted from Stripe.js
$customer->save();
@adamjstevenson
adamjstevenson / create_account.php
Last active August 27, 2016 20:46
Basic Stripe managed account creation with PHP
<?php
// Not using composer
require_once('stripe-php/init.php');
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
try {
$account = \Stripe\Account::create(array(
"managed" => true,
"country" => "US",
"email" => "[email protected]",
@adamjstevenson
adamjstevenson / cancel_sub_test_simple.php
Last active August 5, 2016 22:13
Simple Stripe subscription cancel test
<?php
// Require the Stripe library and set your API key
// Newer versions can use https://stripe.com/docs/api/php#cancel_subscription
try {
$token = \Stripe\Token::create(array(
"card" => array(
"number" => "4242424242424242",
"exp_month" => "12",
"exp_year" => "2020"
@adamjstevenson
adamjstevenson / paginate.js
Created July 14, 2016 15:00
[Node] Paginate charges
var stripe = require('stripe')('YOUR_TEST_KEY');
stripe.charges.list(
{ limit: 100, include: ["total_count"] },
function(err, charges) {
for (i = 0; i < charges.data.length; i++){
console.log(charges.data[i].id);
}
if (charges.has_more) {
paginate(charges["data"][charges["data"].length - 1].id);
@adamjstevenson
adamjstevenson / managed_account_identity_verification_webhook.rb
Last active December 15, 2017 13:04
Handling Identity Verification Notifications
require 'sinatra'
require 'stripe'
require 'mailgun'
set :secret_key, ENV['STRIPE_KEY']
Stripe.api_key = settings.secret_key
set :mailgun_key, ENV['MAILGUN_KEY']
mg_client = Mailgun::Client.new settings.mailgun_key