Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created August 17, 2016 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/f0174bcd7ded2cf8e114eaea0bdc21cc to your computer and use it in GitHub Desktop.
Save iloveitaly/f0174bcd7ded2cf8e114eaea0bdc21cc to your computer and use it in GitHub Desktop.
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