Skip to content

Instantly share code, notes, and snippets.

@adamjstevenson
Last active December 15, 2017 13:06
Show Gist options
  • Save adamjstevenson/e7ebf64a44cc88e8c0ec to your computer and use it in GitHub Desktop.
Save adamjstevenson/e7ebf64a44cc88e8c0ec to your computer and use it in GitHub Desktop.
Paginate Stripe `invoice.payment_succeeded` events (Node)
var stripe = require('stripe')('sk_your_api_key');
stripe.events.list(
{ limit: 100, type: 'invoice.payment_succeeded' },
function(err, events) {
for (i = 0; i < events.data.length; i++){
console.log(events.data[i].id);
}
if (events.has_more) {
paginateEvents(events["data"][events["data"].length - 1].id);
}
}
)
function paginateEvents(starting_after) {
stripe.events.list(
{ limit: 100, type: 'invoice.payment_succeeded', starting_after: starting_after },
function(err, events) {
for (i = 0; i < events.data.length; i++){
console.log(events.data[i].id);
}
if (events.has_more) {
paginateEvents(events["data"][events["data"].length - 1].id);
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment