mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 18:34:30 -04:00
Search for stripe customers by email
This commit is contained in:
parent
7a9baae85b
commit
03ed1c3aea
@ -315,20 +315,36 @@ class StripePaymentDriver extends BaseDriver
|
||||
|
||||
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first();
|
||||
|
||||
//Search by customer reference
|
||||
if ($client_gateway_token && $client_gateway_token->gateway_customer_reference) {
|
||||
|
||||
$customer = Customer::retrieve($client_gateway_token->gateway_customer_reference, $this->stripe_connect_auth);
|
||||
} else {
|
||||
|
||||
$data['name'] = $this->client->present()->name();
|
||||
$data['phone'] = $this->client->present()->phone();
|
||||
|
||||
if (filter_var($this->client->present()->email(), FILTER_VALIDATE_EMAIL)) {
|
||||
$data['email'] = $this->client->present()->email();
|
||||
}
|
||||
if($customer)
|
||||
return $customer;
|
||||
|
||||
$customer = Customer::create($data, $this->stripe_connect_auth);
|
||||
}
|
||||
|
||||
//Search by email
|
||||
$searchResults = \Stripe\Customer::all([
|
||||
"email" => $this->client->present()->email(),
|
||||
"limit" => 2,
|
||||
"starting_after" => null
|
||||
],$this->stripe_connect_auth);
|
||||
|
||||
if(count($searchResults) == 1)
|
||||
return $searchResults->data[0];
|
||||
|
||||
//Else create a new record
|
||||
$data['name'] = $this->client->present()->name();
|
||||
$data['phone'] = $this->client->present()->phone();
|
||||
|
||||
if (filter_var($this->client->present()->email(), FILTER_VALIDATE_EMAIL)) {
|
||||
$data['email'] = $this->client->present()->email();
|
||||
}
|
||||
|
||||
$customer = Customer::create($data, $this->stripe_connect_auth);
|
||||
|
||||
if (!$customer) {
|
||||
throw new Exception('Unable to create gateway customer');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user