data = $data; $this->customer = $customer; $this->invoiceId = $invoiceId; } public function handle(): void { try { $attachment = app(InvoicePdfService::class)->attachment($this->invoiceId); $invoicePdf = $attachment['pdf'] ?? null; $invoicePdfFileName = $attachment['file_name'] ?? null; $email = new VmCredentials($this->data, $invoicePdf, $invoicePdfFileName); Mail::to($this->customer->email)->send($email); \App\Models\Mail::create([ 'template_id' => 2, 'subject' => $email->envelope()->subject, 'to' => $this->customer->email, 'customer_id' => $this->customer->id, 'message' => $email->render(), ]); } catch (\Throwable $exception) { throw new \Exception($exception->getMessage(), 0, $exception); } } public function failed(\Throwable $exception): void { Log::channel('Custom')->error("SendInformationVirtualMachine failed at " . Carbon::now() . ": " . $exception->getMessage()); try { app(Telegram::class)->SendErrorMessage([ 'job' => 'SendInformationVirtualMachine', 'email' => $this->customer->email ?? 'unknown', 'error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), ]); } catch (\Throwable $e) { Log::error('SendInformationVirtualMachine: could not send Telegram notification: ' . $e->getMessage()); } } }