mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5750 from turbo124/v5-develop
Fixes for importing customers into Stripe.
This commit is contained in:
commit
9e5726c1a2
@ -22,8 +22,8 @@ class StripeController extends BaseController
|
|||||||
{
|
{
|
||||||
if(auth()->user()->isAdmin())
|
if(auth()->user()->isAdmin())
|
||||||
{
|
{
|
||||||
|
|
||||||
StripeUpdatePaymentMethods::dispatch(auth()->user()->getCompany());
|
StripeUpdatePaymentMethods::dispatch(auth()->user()->company());
|
||||||
|
|
||||||
return response()->json(['message' => 'Processing'], 200);
|
return response()->json(['message' => 'Processing'], 200);
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class StripeController extends BaseController
|
|||||||
if(auth()->user()->isAdmin())
|
if(auth()->user()->isAdmin())
|
||||||
{
|
{
|
||||||
|
|
||||||
ImportStripeCustomers::dispatch(auth()->user()->getCompany());
|
ImportStripeCustomers::dispatch(auth()->user()->company());
|
||||||
|
|
||||||
return response()->json(['message' => 'Processing'], 200);
|
return response()->json(['message' => 'Processing'], 200);
|
||||||
|
|
||||||
|
@ -169,15 +169,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function getCompany()
|
public function getCompany()
|
||||||
{
|
{
|
||||||
if ($this->company) {
|
|
||||||
return $this->company;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request()->header('X-API-TOKEN')) {
|
if (request()->header('X-API-TOKEN')) {
|
||||||
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
|
$company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first();
|
||||||
|
|
||||||
return $company_token->company;
|
return $company_token->company;
|
||||||
}
|
}
|
||||||
|
elseif ($this->company){
|
||||||
|
|
||||||
|
return $this->company;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// return false;
|
// return false;
|
||||||
throw new \Exception('No Company Found');
|
throw new \Exception('No Company Found');
|
||||||
|
@ -42,7 +42,7 @@ class ImportCustomers
|
|||||||
|
|
||||||
$this->stripe->init();
|
$this->stripe->init();
|
||||||
|
|
||||||
$customers = Customer::all();
|
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
|
||||||
|
|
||||||
foreach($customers as $customer)
|
foreach($customers as $customer)
|
||||||
{
|
{
|
||||||
@ -62,7 +62,7 @@ class ImportCustomers
|
|||||||
if(!$account->isPaidHostedClient() && Client::where('company_id', $this->stripe->company_gateway->company_id)->count() > config('ninja.quotas.free.clients'))
|
if(!$account->isPaidHostedClient() && Client::where('company_id', $this->stripe->company_gateway->company_id)->count() > config('ninja.quotas.free.clients'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nlog("search Stripe for {$custom->id}");
|
nlog("search Stripe for {$customer->id}");
|
||||||
|
|
||||||
$existing_customer = $this->stripe
|
$existing_customer = $this->stripe
|
||||||
->company_gateway
|
->company_gateway
|
||||||
@ -70,9 +70,14 @@ class ImportCustomers
|
|||||||
->where('gateway_customer_reference', $customer->id)
|
->where('gateway_customer_reference', $customer->id)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
if($existing_customer)
|
if($existing_customer){
|
||||||
|
nlog("Skipping - Customer exists: {$customer->email}");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlog("inserting a customer");
|
||||||
|
nlog($customer);
|
||||||
|
|
||||||
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
$client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id);
|
||||||
|
|
||||||
if(property_exists($customer, 'address'))
|
if(property_exists($customer, 'address'))
|
||||||
@ -107,16 +112,16 @@ class ImportCustomers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->name = property_exists($customer, 'name') ? $customer->name : '';
|
$client->name = property_exists($customer, 'name') ? $customer->name : $customer->email;
|
||||||
|
|
||||||
$client->save();
|
$client->save();
|
||||||
|
|
||||||
$contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
$contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||||
$contact->client_id = $client->id;
|
$contact->client_id = $client->id;
|
||||||
$contact->first_name = $client->name ?: '';
|
$contact->first_name = $client->name ?: '';
|
||||||
$contact->phone = $client->phone ?: '';
|
$contact->phone = $client->phone ?: '';
|
||||||
$contact->email = $client->email ?: '';
|
$contact->email = $customer->email ?: '';
|
||||||
$contact->save();
|
$contact->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user