Created
September 15, 2016 18:11
-
-
Save adamjstevenson/3f888d3454a41fb84309629ab38d3fc8 to your computer and use it in GitHub Desktop.
List balance transactions for each transfer on a connected account
This file contains hidden or 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 API key | |
| Stripe.api_key = "YOUR-API-KEY" | |
| # The ID of the connected account | |
| account = "acct_YourConnectedAccountID" | |
| # Retrieve the last 10 transfers on the connected account | |
| transfers = Stripe::Transfer.list({limit:10},{stripe_account: account}) | |
| # Iterate through transfers on the connected account | |
| transfers.each do | tr | | |
| # Output the transfer ID | |
| puts tr.id | |
| # Retrieve the balance transactions associated with this transfer | |
| txns = Stripe::BalanceTransaction.list({transfer: tr.id, limit: 100},{stripe_account: account}) | |
| # Iterate through and list each balance transaction | |
| txns.auto_paging_each do | txn | | |
| # Don't include the transfer balance transaction | |
| unless txn.type.eql?("transfer") | |
| # Format the date nicely | |
| formatted_date = Time.at(txn.created).getutc.strftime("%m/%d/%Y") | |
| # Output the type (charge, refund, adjustment, etc.), ID, amount, and created date | |
| puts "#{txn.type},#{txn.source},#{txn.amount},#{formatted_date}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment