Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adamjstevenson/1832de416338e0fe579a to your computer and use it in GitHub Desktop.
Save adamjstevenson/1832de416338e0fe579a to your computer and use it in GitHub Desktop.
Paginate Stripe customers created in the last month
<?php
// Load Stripe's PHP bindings and set your API key
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey('sk_your_api_key');
// Retrieve the first 100 customers created in the last month
$customers = \Stripe\Customer::all(array("limit" => 100, "created" => array("gte" => strtotime("-1 month"))));
// Iterate through the first 100 and output the customer ID and created date
foreach ($customers->data as $customer){
echo $customer->id . " created " . date("m-d-y", $customer->created) . "<br>";
}
// While we have more results, iterate through them
while ($customers->has_more){
// Add the `starting_after` parameter to reflect the last customer ID
$customers = \Stripe\Customer::all(array("limit" => 100,"created" => array("gte" => strtotime("-1 month")), "starting_after" => $customer->id));
foreach ($customers->data as $customer){
echo $customer->id . " created " . date("m-d-y", $customer->created) . "<br>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment