Created
September 10, 2019 04:35
-
-
Save chastep/bbfe54606559c5c0d05503e9e94695a3 to your computer and use it in GitHub Desktop.
Collect more than 100 charges from Stripe::Charge.list
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
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