diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 8377ba7c0f..e56afb8304 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -141,4 +141,36 @@ class ImportCustomers $this->update_payment_methods->updateMethods($customer, $client); } + + public function match() + { + + foreach($this->stripe->company_gateway->company->clients as $client) + { + + $searchResults = \Stripe\Customer::all([ + "email" => $client->present()->email(), + "limit" => 2, + "starting_after" => null + ],$this->stripe->stripe_connect_auth); + + // nlog(count($searchResults)); + + if(count($searchResults) == 1) + { + + $cgt = ClientGatewayToken::where('gateway_customer_reference', $searchResults->data[0]->id)->where('company_id', $this->company_gateway->company->id)->exists(); + + if(!$cgt) + { + nlog("customer ".$searchResults->data[0]->id. " does not exist."); + + $this->update_payment_methods->updateMethods($searchResults->data[0], $client); + + } + } + + } + + } } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 3124b6fbd7..0dce16d84d 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -83,7 +83,7 @@ class StripePaymentDriver extends BaseDriver * Initializes the Stripe API. * @return void */ - public function init(): void + public function init() { if($this->stripe_connect) { @@ -103,6 +103,8 @@ class StripePaymentDriver extends BaseDriver Stripe::setApiKey($this->company_gateway->getConfigField('apiKey')); } + + return $this; } public function setPaymentMethod($payment_method_id) @@ -543,6 +545,11 @@ class StripePaymentDriver extends BaseDriver } + public function importMatchedClients() + { + return (new ImportCustomers($this))->match(); + } + public function verifyConnect() { return (new Verify($this))->run();