diff --git a/app/Factory/ClientFactory.php b/app/Factory/ClientFactory.php index 1c278b547706..365bb89cd3f8 100644 --- a/app/Factory/ClientFactory.php +++ b/app/Factory/ClientFactory.php @@ -33,9 +33,6 @@ class ClientFactory $client->client_hash = Str::random(40); $client->settings = ClientSettings::defaults(); - // $client_contact = ClientContactFactory::create($company_id, $user_id); - // $client->contacts->add($client_contact); - return $client; } } diff --git a/app/Mail/DownloadBackup.php b/app/Mail/DownloadBackup.php index 6f74ae419f55..146a42bce3ca 100644 --- a/app/Mail/DownloadBackup.php +++ b/app/Mail/DownloadBackup.php @@ -3,13 +3,16 @@ namespace App\Mail; use App\Models\Company; +use App\Utils\Traits\MakesInvoiceHtml; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\File; class DownloadBackup extends Mailable { // use Queueable, SerializesModels; + use MakesInvoiceHtml; public $file_path; @@ -27,19 +30,20 @@ class DownloadBackup extends Mailable */ public function build() { + $template = File::get(resource_path('views/email/admin/download_files.blade.php')); + $company = Company::where('company_key', $this->company->company_key)->first(); + $view = $this->renderView($template, [ + 'url' => $this->file_path, + 'logo' => $company->present()->logo, + 'whitelabel' => $company->account->isPaid() ? true : false, + 'settings' => $company->settings, + 'greeting' => $company->present()->name(), + ]); + return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject(ctrans('texts.download_backup_subject', ['company' => $company->present()->name()])) - ->markdown( - 'email.admin.download_files', - [ - 'url' => $this->file_path, - 'logo' => $company->present()->logo, - 'whitelabel' => $company->account->isPaid() ? true : false, - 'settings' => $company->settings, - 'greeting' => $company->present()->name(), - ] - ); + ->html($view); } } diff --git a/app/PaymentDrivers/Stripe/ImportCustomers.php b/app/PaymentDrivers/Stripe/ImportCustomers.php index 720b4a5cc65d..6b6d32973081 100644 --- a/app/PaymentDrivers/Stripe/ImportCustomers.php +++ b/app/PaymentDrivers/Stripe/ImportCustomers.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers\Stripe; use App\Factory\ClientContactFactory; +use App\Factory\ClientFactory; use App\Factory\ClientGatewayTokenFactory; use App\Models\Client; use App\Models\ClientGatewayToken; @@ -55,31 +56,37 @@ class ImportCustomers private function addCustomer(Customer $customer) { + + $account = $this->stripe->company_gateway->company->account; - $account = $this->company_gateway->company->account; - - $existing_customer = $this->company_gateway + $existing_customer = $this->stripe + ->company_gateway ->client_gateway_tokens() ->where('gateway_customer_reference', $customer->id) ->exists(); if($existing_customer) - return + return; - $client = ClientFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id); - $client->address1 = $customer->address->line1 ?: ''; - $client->address2 = $customer->address->line2 ?: ''; - $client->city = $customer->address->city ?: ''; - $client->state = $customer->address->state ?: ''; + $client = ClientFactory::create($this->stripe->company_gateway->company_id, $this->stripe->company_gateway->user_id); - if($customer->address->country){ + if(property_exists($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 : ''; - $country = Country::where('iso_3166_2', $customer->address->country)->first() + if(property_exists($customer->address, 'country')){ - if($country) - $client->country_id = $country->id; + $country = Country::where('iso_3166_2', $customer->address->country)->first(); + if($country) + $client->country_id = $country->id; + + } } if($customer->currency) { @@ -96,12 +103,11 @@ class ImportCustomers } - $client->phone = $customer->phone ?: ''; - $client->name = $customer->name ?: ''; + $client->name = property_exists($customer, 'name') ? $customer->name : ''; - if(!$account->isPaidHostedClient() && Client::where('company_id', $this->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')){ - $client->save() + $client->save(); $contact = ClientContactFactory::create($client->company_id, $client->user_id); $contact->client_id = $client->id; diff --git a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php index 360b5f451441..1e1745476a73 100644 --- a/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php +++ b/app/PaymentDrivers/Stripe/UpdatePaymentMethods.php @@ -104,7 +104,7 @@ class UpdatePaymentMethods $cgt->token = $bank_account->id; $cgt->gateway_customer_reference = $token->gateway_customer_reference; $cgt->company_gateway_id = $token->company_gateway_id; - $cgt->gateway_type_id = GatewayType::BANK_TRANSFER + $cgt->gateway_type_id = GatewayType::BANK_TRANSFER; $cgt->meta = new \stdClass; $cgt->routing_number = $bank_account->routing_number; $cgt->save();