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

Merge pull request #6542 from turbo124/v5-develop

Fixes for Stripe Import
This commit is contained in:
David Bomba 2021-09-02 12:08:46 +10:00 committed by GitHub
commit 62b1c386a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 12 deletions

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers;
use App\Jobs\Util\ImportStripeCustomers;
use App\Jobs\Util\StripeUpdatePaymentMethods;
use App\Libraries\MultiDB;
use App\Models\Client;
use App\Models\CompanyGateway;
@ -60,6 +61,8 @@ class StripeController extends BaseController
if(auth()->user()->isAdmin())
{
MultiDB::findAndSetDbByCompanyKey(auth()->user()->company()->company_key);
$company_gateway = CompanyGateway::where('company_id', auth()->user()->company()->id)
->where('is_deleted',0)
->whereIn('gateway_key', $this->stripe_keys)

View File

@ -46,6 +46,7 @@ class RecurringInvoicesCron
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date')
->whereNull('deleted_at')
->where('is_deleted', false)
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('remaining_cycles', '!=', '0')
->whereHas('client', function ($query) {
@ -61,7 +62,13 @@ class RecurringInvoicesCron
nlog("Current date = " . now()->format("Y-m-d") . " Recurring date = " .$recurring_invoice->next_send_date);
if (!$recurring_invoice->company->is_disabled) {
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
}
catch(\Exception $e){
nlog("Unable to sending recurring invoice {$recurring_invoice->id}");
}
}
});
} else {
@ -72,6 +79,7 @@ class RecurringInvoicesCron
$recurring_invoices = RecurringInvoice::where('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date')
->whereNull('deleted_at')
->where('is_deleted', false)
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->where('remaining_cycles', '!=', '0')
->whereHas('client', function ($query) {
@ -87,7 +95,13 @@ class RecurringInvoicesCron
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) {
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
try{
SendRecurring::dispatchNow($recurring_invoice, $recurring_invoice->company->db);
}
catch(\Exception $e){
nlog("Unable to sending recurring invoice {$recurring_invoice->id} on db {$db}");
}
}
});
}

View File

@ -52,7 +52,7 @@ class ImportCustomers
$this->update_payment_methods = new UpdatePaymentMethods($this->stripe);
if(strlen($this->stripe->company_gateway->getConfigField('account_id')) < 1)
throw new StripeConnectFailure('Stripe Connect has not been configured');
throw new StripeConnectFailure('Stripe Connect has not been configured');
$customers = Customer::all([], $this->stripe->stripe_connect_auth);
@ -83,7 +83,14 @@ class ImportCustomers
->exists();
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;
}
@ -92,15 +99,15 @@ class ImportCustomers
$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->address2 = property_exists($customer->address, 'line2') ? $customer->address->line2 : '';
$client->city = property_exists($customer->address, 'city') ? $customer->address->city : '';
$client->state = property_exists($customer->address, 'state') ? $customer->address->state : '';
$client->phone = property_exists($customer->address, 'phone') ? $customer->phone : '';
$client->address1 = $customer->address->line1 ? $customer->address->line1 : '';
$client->address2 = $customer->address->line2 ? $customer->address->line2 : '';
$client->city = $customer->address->city ? $customer->address->city : '';
$client->state = $customer->address->state ? $customer->address->state : '';
$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();
@ -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)) {
$client->number = $this->getNextClientNumber($client);