Search for stripe customers by email

This commit is contained in:
David Bomba 2021-09-01 08:22:24 +10:00
parent 7a9baae85b
commit 03ed1c3aea

View File

@ -315,10 +315,27 @@ 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 {
$customer = Customer::retrieve($client_gateway_token->gateway_customer_reference, $this->stripe_connect_auth);
if($customer)
return $customer;
}
//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();
@ -327,7 +344,6 @@ class StripePaymentDriver extends BaseDriver
}
$customer = Customer::create($data, $this->stripe_connect_auth);
}
if (!$customer) {
throw new Exception('Unable to create gateway customer');