mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #6542 from turbo124/v5-develop
Fixes for Stripe Import
This commit is contained in:
commit
62b1c386a2
@ -14,6 +14,7 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Jobs\Util\ImportStripeCustomers;
|
use App\Jobs\Util\ImportStripeCustomers;
|
||||||
use App\Jobs\Util\StripeUpdatePaymentMethods;
|
use App\Jobs\Util\StripeUpdatePaymentMethods;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
|
|
||||||
@ -60,6 +61,8 @@ class StripeController extends BaseController
|
|||||||
if(auth()->user()->isAdmin())
|
if(auth()->user()->isAdmin())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
MultiDB::findAndSetDbByCompanyKey(auth()->user()->company()->company_key);
|
||||||
|
|
||||||
$company_gateway = CompanyGateway::where('company_id', auth()->user()->company()->id)
|
$company_gateway = CompanyGateway::where('company_id', auth()->user()->company()->id)
|
||||||
->where('is_deleted',0)
|
->where('is_deleted',0)
|
||||||
->whereIn('gateway_key', $this->stripe_keys)
|
->whereIn('gateway_key', $this->stripe_keys)
|
||||||
|
@ -46,6 +46,7 @@ class RecurringInvoicesCron
|
|||||||
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
|
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('next_send_date')
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
|
->where('is_deleted', false)
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
->whereHas('client', function ($query) {
|
->whereHas('client', function ($query) {
|
||||||
@ -61,8 +62,14 @@ class RecurringInvoicesCron
|
|||||||
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
|
||||||
|
|
||||||
if (!$recurring_invoice->company->is_disabled) {
|
if (!$recurring_invoice->company->is_disabled) {
|
||||||
|
|
||||||
|
try{
|
||||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||||
}
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//multiDB environment, need to
|
//multiDB environment, need to
|
||||||
@ -72,6 +79,7 @@ class RecurringInvoicesCron
|
|||||||
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
|
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('next_send_date')
|
||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
|
->where('is_deleted', false)
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
->whereHas('client', function ($query) {
|
->whereHas('client', function ($query) {
|
||||||
@ -87,8 +95,14 @@ class RecurringInvoicesCron
|
|||||||
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date ." Recurring #id = ". $recurring_invoice->id);
|
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date ." Recurring #id = ". $recurring_invoice->id);
|
||||||
|
|
||||||
if (!$recurring_invoice->company->is_disabled) {
|
if (!$recurring_invoice->company->is_disabled) {
|
||||||
|
|
||||||
|
try{
|
||||||
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
|
||||||
}
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
nlog("Unable to sending recurring invoice {$recurring_invoice->id} on db {$db}");
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,14 @@ class ImportCustomers
|
|||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
if($existing_customer){
|
if($existing_customer){
|
||||||
nlog("Skipping - Customer exists: {$customer->email}");
|
nlog("Skipping - Customer exists: {$customer->email} just updating payment methods");
|
||||||
|
$this->update_payment_methods->updateMethods($customer, $contact->client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($customer->email && $contact = $this->stripe->company_gateway->company->client_contacts()->where('email', $customer->email)->first()){
|
||||||
|
nlog("Customer exists: {$customer->email} just updating payment methods");
|
||||||
|
$this->update_payment_methods->updateMethods($customer, $contact->client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,15 +99,15 @@ class ImportCustomers
|
|||||||
|
|
||||||
$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($customer->address)
|
||||||
{
|
{
|
||||||
$client->address1 = property_exists($customer->address, 'line1') ? $customer->address->line1 : '';
|
$client->address1 = $customer->address->line1 ? $customer->address->line1 : '';
|
||||||
$client->address2 = property_exists($customer->address, 'line2') ? $customer->address->line2 : '';
|
$client->address2 = $customer->address->line2 ? $customer->address->line2 : '';
|
||||||
$client->city = property_exists($customer->address, 'city') ? $customer->address->city : '';
|
$client->city = $customer->address->city ? $customer->address->city : '';
|
||||||
$client->state = property_exists($customer->address, 'state') ? $customer->address->state : '';
|
$client->state = $customer->address->state ? $customer->address->state : '';
|
||||||
$client->phone = property_exists($customer->address, 'phone') ? $customer->phone : '';
|
$client->phone = $customer->address->phone ? $customer->phone : '';
|
||||||
|
|
||||||
if(property_exists($customer->address, 'country')){
|
if($customer->address->country){
|
||||||
|
|
||||||
$country = Country::where('iso_3166_2', $customer->address->country)->first();
|
$country = Country::where('iso_3166_2', $customer->address->country)->first();
|
||||||
|
|
||||||
@ -124,7 +131,7 @@ class ImportCustomers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->name = property_exists($customer, 'name') ? $customer->name : $customer->email;
|
$client->name = $customer->name ? $customer->name : $customer->email;
|
||||||
|
|
||||||
if (!isset($client->number) || empty($client->number)) {
|
if (!isset($client->number) || empty($client->number)) {
|
||||||
$client->number = $this->getNextClientNumber($client);
|
$client->number = $this->getNextClientNumber($client);
|
||||||
|
Loading…
Reference in New Issue
Block a user