Created
August 17, 2016 00:43
-
-
Save iloveitaly/f0174bcd7ded2cf8e114eaea0bdc21cc to your computer and use it in GitHub Desktop.
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' | |
# replace this with your Stripe API key | |
Stripe.api_key = 'sk_live_' | |
start_date = DateTime.new(2016,5,1) | |
end_date = DateTime.new(2016,5,30) | |
# refund list API guarantees refunds are returned in date order | |
# this is important because the refund endpoint does not have any date filters | |
Stripe::Refund.list(limit: 100, expand: ['data.balance_transaction']).auto_paging_each do |refund| | |
if refund.created < start_date.to_i | |
break | |
end | |
if refund.created > end_date.to_i | |
next | |
end | |
refunds << refund | |
end | |
Stripe::Charge.list({ | |
limit: 100, | |
expand: ['data.balance_transaction'], | |
created: { gt: start_date.to_i, lt: end_date.to_i } | |
}, user.stripe_key).auto_paging_each do |charge| | |
charges << charge | |
end | |
Stripe::Dispute.list( | |
limit: 100, | |
expand: ['data.balance_transaction'], | |
created: { gt: start_date.to_i, lt: end_date.to_i } | |
).auto_paging_each do |dispute| | |
disputes << dispute | |
end | |
charges.each do |charge| | |
puts "#{charge.id}\t#{charge.invoice.id}\t#{charge.amount/100.0}\t#{Time.at(charge.created)}" | |
end | |
refunds.each do |refund| | |
puts "#{refund.id}\t#{refund.charge.id}\t-#{refund.amount/100.0}\t#{Time.at(refund.created)}" | |
end | |
# NOTE that disputes have multiple BalanceTransactions; calculating fees, etc requires inspecting each individual bt | |
disputes.each do |dispute| | |
puts "#{dispute.id}\t#{dispute.charge.id}\t-#{dispute.amount/100.0}\t#{Time.at(dispute.created)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment