Skip to content

Instantly share code, notes, and snippets.

@adamjstevenson
Created October 13, 2016 04:06
Show Gist options
  • Save adamjstevenson/4de54bd08fe5f97eade10c1300c0ebd1 to your computer and use it in GitHub Desktop.
Save adamjstevenson/4de54bd08fe5f97eade10c1300c0ebd1 to your computer and use it in GitHub Desktop.
List balance transactions for a specific transfer
require 'stripe'
# Your API key
Stripe.api_key = 'YOUR-API-KEY'
# Retrieve the balance transactions associated with a specific transfer
txns = Stripe::BalanceTransaction.list({ transfer: 'tr_18V4GALrKpFcM2405wrIONb9', limit: 100 })
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment