Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danilogco/da53c0b769d83b4bb442fb37d065ae88 to your computer and use it in GitHub Desktop.
Save danilogco/da53c0b769d83b4bb442fb37d065ae88 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