Skip to content

Instantly share code, notes, and snippets.

@adam-stripe
Created February 13, 2017 22:12
Show Gist options
  • Save adam-stripe/29c22a4a8649c19fc709008e71397f37 to your computer and use it in GitHub Desktop.
Save adam-stripe/29c22a4a8649c19fc709008e71397f37 to your computer and use it in GitHub Desktop.
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 })
total = 0
# Iterate through transactions and sum values for each available_on date
transactions.auto_paging_each do |txn|
total += txn.net
end
# Output the net since the beginning of the year
puts total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment