Created
August 31, 2017 00:10
-
-
Save aligajani/0342c6a57c520d05c2b1ee795c649ab2 to your computer and use it in GitHub Desktop.
Retrieve Stripe Customers via email
This file contains hidden or 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 | |
$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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using this will return every object related to this email, it's better to restrict the search by object type
customer
so the URL:
$httpResource = 'https://api.stripe.com/v1/search?query=is:customer email:'.$email.'&prefix=false';