Skip to content

Instantly share code, notes, and snippets.

@chastep
Created September 10, 2019 04:35
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 chastep/bbfe54606559c5c0d05503e9e94695a3 to your computer and use it in GitHub Desktop.
Save chastep/bbfe54606559c5c0d05503e9e94695a3 to your computer and use it in GitHub Desktop.
Collect more than 100 charges from Stripe::Charge.list
def gather_all_stripe_charges
all_charges = []
has_more = true
last_charge_id = nil
while has_more
charges = Stripe::Charge.list({ limit: 100, starting_after: last_charge_id})
all_charges += initial_charges['data'].map { |charge| {id: charge['id'], amount: charge['amount']} }
has_more = false unless charges['has_more']
last_charge_id = all_charges.last.id
end
all_charges
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment