Last active
December 15, 2017 13:06
-
-
Save adamjstevenson/8eef9a2ef0499cec715c to your computer and use it in GitHub Desktop.
Paginate through all Stripe charges in Ruby
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's Ruby bindings | |
require 'stripe' | |
# set your secret API key. You should generally store this in an evironment variable. | |
Stripe.api_key = "sk_your_key" | |
# grab the first 100 charges | |
charges = Stripe::Charge.list(limit: 100) | |
# print the charge ID for each | |
charges.each do |charge| | |
puts charge.id | |
end | |
# if there are more than 100 charges, paginate through each set of 100 | |
while charges.has_more do | |
charges = Stripe::Charge.list(limit: 100, starting_after: charges.data.last.id) | |
charges.each do |charge| | |
puts charge.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment