Last active
June 8, 2021 19:09
-
-
Save adamjstevenson/1832de416338e0fe579a to your computer and use it in GitHub Desktop.
Paginate Stripe customers created in the last month
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
<?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