Skip to content

Instantly share code, notes, and snippets.

@adam-stripe
Created February 27, 2017 22:07
Show Gist options
  • Save adam-stripe/e8e55c085bd196f48bc731b466c3d348 to your computer and use it in GitHub Desktop.
Save adam-stripe/e8e55c085bd196f48bc731b466c3d348 to your computer and use it in GitHub Desktop.
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
balance = Stripe::Balance.retrieve(stripe_account: acct.id)
# Look for negative balances
if balance.available.first.amount < 0
# Output the account ID and negative amount
# In your app, you could send an email to notify the account
puts "#{acct.id} has a negative balance of #{balance.available.first.amount}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment