Created
February 13, 2017 22:12
-
-
Save adam-stripe/29c22a4a8649c19fc709008e71397f37 to your computer and use it in GitHub Desktop.
Sum all balance transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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