mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Improve Stripe customer importationg
This commit is contained in:
parent
92e2c7c614
commit
65565f01fc
@ -52,7 +52,19 @@ class Verify
|
||||
if($this->stripe->stripe_connect && strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1)
|
||||
throw new StripeConnectFailure('Stripe Connect has not been configured');
|
||||
|
||||
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
|
||||
$total_stripe_customers = 0;
|
||||
|
||||
$starting_after = null;
|
||||
|
||||
do {
|
||||
|
||||
$customers = Customer::all(['limit' => 100, 'starting_after' => $starting_after], $this->stripe->stripe_connect_auth);
|
||||
|
||||
$total_stripe_customers += count($customers->data);
|
||||
$starting_after = end($customers->data)['id'];
|
||||
|
||||
} while($customers->has_more);
|
||||
|
||||
|
||||
$stripe_customers = $this->stripe->company_gateway->client_gateway_tokens->map(function ($cgt){
|
||||
|
||||
@ -66,7 +78,7 @@ class Verify
|
||||
});
|
||||
|
||||
$data = [
|
||||
'stripe_customer_count' => count($customers),
|
||||
'stripe_customer_count' => $total_stripe_customers,
|
||||
'stripe_customers' => $stripe_customers,
|
||||
];
|
||||
|
||||
|
@ -55,13 +55,20 @@ class ImportCustomers
|
||||
if(Ninja::isHosted() && strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1)
|
||||
throw new StripeConnectFailure('Stripe Connect has not been configured');
|
||||
|
||||
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
|
||||
$starting_after = null;
|
||||
|
||||
foreach($customers as $customer)
|
||||
{
|
||||
$this->addCustomer($customer);
|
||||
}
|
||||
do {
|
||||
|
||||
$customers = Customer::all(['limit' => 100, 'starting_after' => $starting_after], $this->stripe->stripe_connect_auth);
|
||||
|
||||
foreach($customers as $customer)
|
||||
{
|
||||
$this->addCustomer($customer);
|
||||
}
|
||||
|
||||
$starting_after = end($customers->data)['id'];
|
||||
|
||||
} while($customers->has_more);
|
||||
}
|
||||
|
||||
private function addCustomer(Customer $customer)
|
||||
@ -72,7 +79,7 @@ class ImportCustomers
|
||||
if(!$account->isPaidHostedClient() && Client::where('company_id', $this->stripe->company_gateway->company_id)->count() > config('ninja.quotas.free.clients'))
|
||||
return;
|
||||
|
||||
nlog("search Stripe for {$customer->id}");
|
||||
// nlog("search Stripe for {$customer->id}");
|
||||
|
||||
$existing_customer_token = $this->stripe
|
||||
->company_gateway
|
||||
@ -97,7 +104,7 @@ class ImportCustomers
|
||||
return;
|
||||
}
|
||||
|
||||
nlog("inserting a customer");
|
||||
// nlog("inserting a customer");
|
||||
//nlog($customer);
|
||||
|
||||
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
||||
|
@ -264,8 +264,6 @@ class Helpers
|
||||
|
||||
$x = str_replace(["\n", "<br>"], ["\r", "<br>"], $value);
|
||||
|
||||
nlog($x);
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user