template_id = $template; $this->code = $code; $this->email = $email; $this->customer = $customer; $this->telegram = new Telegram(); } /** * Execute the job. */ public function handle() { // Log job start Log::channel('Custom')->info("Starting CustomerPayment job for email: {$this->email}"); // Notify via Telegram that job is starting $this->telegram->SendJobRunInfo('CustomerPayment', 'Started', [ 'email' => $this->email, 'customer_id' => $this->customer ]); $hash = SignRSA::EncryptFunc(base64_encode($this->code)); $setting = Setting::where('key', 'setting')->first(); $parsed = json_decode($setting->value); $data = [ 'company_name' => $parsed->company, 'company_logo' => $parsed->logo, ]; try { // Send email $email = new \App\Mail\Customer\CustomerPayment($this->template_id, $data); Mail::to($this->email)->send($email); // Log email in database \App\Models\Mail::create([ 'template_id' => 3, 'subject' => $email->envelope()->subject, 'to' => $this->email, 'customer_id' => $this->customer, 'message' => $email->render() ]); // Send Telegram notification about new user registration $this->telegram->SendNewUserRegistration($this->email, $this->code, $verificationLink); // Log job completion Log::channel('Custom')->info("CustomerPayment job completed successfully for email: {$this->email}"); // Notify via Telegram that job completed successfully $this->telegram->SendJobRunInfo('CustomerPayment', 'Completed', [ 'email' => $this->email, 'status' => 'success' ]); } catch (\Exception $exception) { // Log error Log::channel('Custom')->error("CustomerPayment job failed for email: {$this->email}. Error: {$exception->getMessage()}"); // Notify via Telegram that job failed $this->telegram->SendJobRunInfo('CustomerPayment', 'Failed', [ 'email' => $this->email, 'error' => $exception->getMessage() ]); throw new \Exception($exception->getMessage()); } } /** * Handle job failure. * * @param \Throwable $exception * @return void */ public function failed(\Throwable $exception) { $timestamp = Carbon::now()->format('Y-m-d H:i:s'); Log::channel('Custom')->info("================================="); Log::channel('Custom')->info("Thông báo lỗi lúc: " . $timestamp); Log::channel('Custom')->info("Notification Send Email Register for Customer: {$this->email}"); Log::channel('Custom')->info("========"); Log::channel('Custom')->info($exception->getMessage()); Log::channel('Custom')->info("================================="); // Send error message to Telegram $errorData = [ 'timestamp' => $timestamp, 'email' => $this->email, 'customer_id' => $this->customer, 'error' => $exception->getMessage() ]; $this->telegram->SendErrorMessage(json_encode($errorData)); } }