product = $product; $this->server = new Hosting; $this->push = new PusherNotification; $this->telegram = new Telegram; } /** * Execute the job. * * @return void */ public function handle() { $product = ModuleHosting::with([ "Customer", "Server" ])->find($this->product); if (! $product) { throw new \Exception("Can't find product"); } if (! $product->Server) { throw new \Exception('Invalid request.'); } $this->server->url = $product->Server->name; if ($product->Server->apikey) { $this->server->apiKey = $product->Server->apikey; } $ClientUser = $this->server->CheckUserClient($product->Customer); if ($ClientUser === "Login_Again") { $this->server->username = $product->Server->user; $this->server->password = SignRSA::DecryptFunc($product->Server->password); $AuthLogin = $this->server->LoginServer(); if ($AuthLogin['error']) { throw new \Exception("You have entered incorrect username or password."); } $this->server->apiKey = $AuthLogin['data']['key']; ModuleHostingServer::where('id',$product->Server->id)->update(['apikey' => $AuthLogin['data']['key']]); $ClientUser = $this->server->CheckUserClient($product->Customer); } $PasswordHosting = Helper::general_password(); if ($ClientUser['error'] === true) { $ClientUser = $this->server->CreateNewClient($product,$PasswordHosting); } if ($ClientUser['error'] === true) { throw new \Exception(json_encode($ClientUser['data'])); } $pleskUser = []; if (array_key_exists(0,$ClientUser['data'])) { $pleskUser = $ClientUser['data'][0]; $pleskUser['password'] = $ClientUser['data']['password']; } else { $pleskUser = $ClientUser['data']; } $ExitsDomain = $this->server->CheckDomainExit($pleskUser['id'],$product->name); if ($ExitsDomain['error']) { throw new \Exception(json_encode($ExitsDomain['data'])); } $CreatedDomain = $this->server->CreateNewDomain($product,$product->name,$pleskUser,$PasswordHosting); if ($CreatedDomain['error'] === true) { throw new \Exception(json_encode($CreatedDomain['data'])); } $CreateDateExp = $this->server->CreateExpirationForDomain($product->name,Carbon::parse($product->next_due_date)->format("Y-m-d")); if ($CreateDateExp['error'] === true) { throw new \Exception(json_encode($CreateDateExp['data'])); } $product->update([ 'username' => $product->Customer->email, 'password' => SignRSA::EncryptFunc($pleskUser['password']), 'status' => 1, 'server_domain_id' => $CreatedDomain['data']['id'] ]); ModuleHostingServer::where('id',$product->Server->id) ->update(['counter' => $product->Server->counter + 1]); $setting = Setting::where('key','setting')->first(); $data = [ 'company_name' => json_decode($setting->value)->company, 'company_logo' => json_decode($setting->value)->logo, 'client_name' => (string) $product->Customer->fullname, 'product_name' => $product->GetInvoiceItem()->GetItemProduct()->name, 'product_billing' => Helper::BillingCycle($product->GetInvoiceItem()->billing), 'product_price' => number_format($product->GetInvoiceItem()->amount,0,',','.'), 'service_host' => $product->Server->name, 'service_username' => $product->Customer->email, 'service_password' => $pleskUser['password'], 'service_due_exp' => Carbon::parse($product->next_due_date)->format('d/m/Y'), 'ftp_password' => $pleskUser['password'], 'ftp_account' => $product->name, ]; $mail = new SendInformationHosting($data,$product->Customer); dispatch($mail)->delay(now()->addSeconds(5)); Event(new NotificationStatus("Created new Domain For Server #". $product->Server->name . " success",true)); } public function failed(\Throwable $exception): void { Event(new NotificationStatus("Notification: " .$exception->getMessage() ,false)); $this->telegram->SendErrorMessage($exception->getMessage()); } }