You are right, you must write a naive loop with a cursor per the stripe docs:
starting_after
optional
A cursor for use in pagination.
starting_after
is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending withobj_foo
, your subsequent call can includestarting_after=obj_foo
in order to fetch the next page of the list.
Here's one in case anyone needs a quick copy-paste.
def self.all_stripe_customers
starting_after = nil
customers = []
loop do
results = Stripe::Customer.list(limit: 100, starting_after: starting_after)
break if results.data.length == 0
customers = customers + results.data
starting_after = results.data.last.id
end
return customers
end