Retrieve Stripe Customers via email

1 min read Original article ↗
<?php
$email = "your_email_query_here";
try {
$client = $client = new \GuzzleHttp\Client();
$client->setDefaultOption('verify', true);
$httpResource = 'https://api.stripe.com/v1/search?query="'.$email.'"&prefix=false';
$request = $client->get($httpResource, [
'headers' => ["Content-Type" => "application/x-www-form-urlencoded", "Authorization" => "Bearer ".$stripeApiKey]
]);
$response = json_decode($request->getBody());
if ($response->count > 0) {
foreach ($response->data as $customer) {
if (strlen($customer->id) == 18) {
echo $customer->id . PHP_EOL;
}
}
} else {
return 'No match found';
}
} catch (ClientException $e) {
if ($e->hasResponse()) {
Log::info('ClientException: RequestService::get() =>' .print_r($email, true) . '=>' . $e->getMessage());
return;
}
} catch (TransferException $e) {
Log::info('TransferException: RequestService::get() =>' .print_r($email, true) . '=>' . $e->getMessage());
return;
}