payment = $payment; $this->contact = $contact; $this->company = $company; $this->settings = $payment->client->getMergedSettings(); } /** * Execute the job. * * * @return void */ public function handle() { if($this->company->is_disabled) return true; if ($this->contact->email) { MultiDB::setDb($this->company->db); //if we need to set an email driver do it now $this->setMailDriver(); $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); try{ $mail = Mail::to($this->contact->email, $this->contact->present()->name()); $mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client)); }catch(\Exception $e) { info("mailing failed with message " . $e->getMessage()); event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); return $this->logMailError($e->getMessage(), $this->payment->client); } // if (count(Mail::failures()) > 0) { // info("logging mail failures"); // info(print_r(Mail::failures(),1)); // } event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars())); } } public function failed($exception = null) { info('the job failed'); $job_failure = new EmailInvoiceFailure(); $job_failure->string_metric5 = 'payment'; $job_failure->string_metric6 = $exception->getMessage(); LightLogs::create($job_failure) ->batch(); } }