1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Stripe import algo

This commit is contained in:
David Bomba 2021-08-18 10:15:11 +10:00
parent 5b35a2c458
commit 45a8d2066e
2 changed files with 40 additions and 1 deletions

View File

@ -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);
}
}
}
}
}

View File

@ -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();