Skip to content

Instantly share code, notes, and snippets.

@adam-stripe
adam-stripe / list_negative_balances.rb
Created February 27, 2017 22:07
List Stripe accounts with a negative balance
# Load the Stripe library and set your secret key
require 'stripe'
Stripe.api_key = ENV['SECRET_KEY']
# List connected accounts
accounts = Stripe::Account.list(limit: 100)
# Paginate through the list of accounts
accounts.auto_paging_each do |acct|
# Retrieve the balance for this account
@adam-stripe
adam-stripe / email_receipt.rb
Last active February 24, 2017 17:18
Generic Stripe receipt webhook with Sinatra and Mailgun
# A simple text-based email receipt webhook, written for Sinatra. Sends email receipts for one-off charges.
# See https://github.com/adamjstevenson/stripe-ruby-webhook-receipts for more specifics
require 'sinatra'
require 'stripe'
require 'mailgun-ruby'
# Set your Stripe secret key as an environment variable: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = ENV['STRIPE_KEY']
@adam-stripe
adam-stripe / gist:72cadb71a60fdfbe7b416eec43944560
Created February 24, 2017 17:16
Generic Stripe receipt webhook with Sinatra and Mailgun
# A simple text-based email receipt webhook, written for Sinatra. Sends email receipts for one-off charges.
# See https://github.com/adamjstevenson/stripe-ruby-webhook-receipts for more specifics
require 'sinatra'
require 'stripe'
require 'mailgun-ruby'
# Set your Stripe secret key as an environment variable: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = ENV['STRIPE_KEY']
@adam-stripe
adam-stripe / sum_bts.rb
Created February 13, 2017 22:12
Sum all balance transactions
require 'stripe'
# Your platform's secret key
Stripe.api_key = "YOUR-SECRET-KEY"
# Get a timestamp for the beggining of the year
start = DateTime.rfc3339('2017-01-01T00:00:00Z').to_time.to_i
# Retrieve transactions - you could use the Stripe-Account header here to get the transactions on a connected account as well.
transactions = Stripe::BalanceTransaction.list(limit: 100, created: { gte: start })