Skip to content

Instantly share code, notes, and snippets.

@adamjstevenson
Last active December 15, 2017 13:06
Show Gist options
  • Save adamjstevenson/8eef9a2ef0499cec715c to your computer and use it in GitHub Desktop.
Save adamjstevenson/8eef9a2ef0499cec715c to your computer and use it in GitHub Desktop.
Paginate through all Stripe charges in Ruby
# 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