public function intlDomain(Request $request)
 {
     $data = $request->all();
     $contacts = (object) $data['contacts'];
     //Registrant Contact Array
     $registrant = ['Firstname' => $contacts->Registrant_FirstName, 'Lastname' => $contacts->Registrant_LastName, 'Organization' => 'My Company', 'CountryCode' => $contacts->Registrant_CountryCode, 'City' => $contacts->Registrant_City, 'Email' => $contacts->Registrant_Email, 'Street' => $contacts->Registrant_Street, 'PostalCode' => $contacts->Registrant_PostalCode, 'PhoneNumber' => $this->intlphoneNumber($contacts->Registrant_PhoneNumber, $contacts->Registrant_CountryCode)];
     // Admin Contact Array
     $admin = ['Firstname' => $contacts->Admin_FirstName, 'Lastname' => $contacts->Admin_LastName, 'Organization' => 'My Company', 'CountryCode' => $contacts->Admin_CountryCode, 'City' => $contacts->Admin_City, 'Email' => $contacts->Admin_Email, 'Street' => $contacts->Admin_Street, 'PostalCode' => $contacts->Admin_PostalCode, 'PhoneNumber' => $this->intlphoneNumber($contacts->Registrant_PhoneNumber, $contacts->Registrant_CountryCode)];
     $c = array('Registrant' => $registrant, 'Admin' => $admin, 'Technical' => $admin, 'Billing' => $admin);
     $nameservers = ['Ns_list' => implode(',', $data['name_servers'])];
     try {
         InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz');
         if (Domain::find($data['domain_id'])->domain_status == 0) {
             $response = (object) json_decode(InternetBS::api()->domainCreate($data['domain_name'], $c, 1, $nameservers));
             if ($response->product[0]->status == 'SUCCESS') {
                 $domain = Domain::find($data->domain_id);
                 $domain->domain_status = 1;
                 $domain->save();
                 // Send an email of confirmation and do a redirection automatically
                 return redirect('admin/dashboard');
             } else {
                 // Redict to error page
                 return redirect('admin/errors');
             }
         } else {
             // Update Domain Name //
             InternetBS::api()->domainAssignNS($data['domain_name'], $data['name_servers']);
             $updates = InternetBS::api()->domainUpdate($data['domain_name'], $c);
             return ['response' => $updates];
         }
     } catch (Exception $e) {
         return ['response' => 'error detected', 'error_msg' => $e->getMessage()];
     }
 }
 public function check(Request $request)
 {
     // Check if Domain Name is available via API
     $domain = Domains::cleanURL(strtolower($request->input('domain')));
     // International Domain Names//
     if (Domains::isDomainIntl($domain)) {
         InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz');
         $status = InternetBS::api()->domainCheck($domain);
         if ($status) {
             $message = 'Domain Name is available';
         }
         $message = 'Domain Name is not available';
         return ['message' => $message, 'status' => $status];
     }
     // Rwandan Domain Names
     if (Domains::isDomainRW($domain)) {
         $params = ['form_params' => ['search' => $domain], 'verify' => false];
         $data = Domains::post('https://whois.ricta.org.rw/whois.jsp', $params);
         if (preg_match_all('/<tr><th>(?:[a-zA-Z\\s]+)<\\/th><td><a href=\'(.+)\'>(?:[a-zA-Z\\.]+)<\\/a>/im', $data, $matches)) {
             $status = false;
             $message = 'Domain Name is not available';
         } else {
             $message = 'Domain Name is available';
             $status = true;
         }
         return ['message' => $message, 'status' => $status];
     }
     // Ugandan Domain Names
     if (Domains::isDomainUG($domain)) {
         $xml = (string) Domains::post('https://new.registry.co.ug:8006/api', ['body' => Domains::UG_Whois_Command($domain)]);
         $reader = new Reader();
         $reader->xml($xml);
         $parsedXML = $reader->parse();
         $data = $parsedXML['value'];
         $status = (int) $parsedXML['attributes']['status'];
         if ($status) {
             $status = false;
             $message = 'Domain Name is Not available';
         } else {
             $message = 'Domain Name is available';
             $status = true;
         }
         return ['message' => $message, 'status' => $status];
     }
 }
 public function search(Request $request)
 {
     $domain = strtolower($request->input('domain'));
     $response = [];
     $response['domain'] = $domain;
     $response['country'] = null;
     $response['status'] = false;
     $response['domain_details'] = Domains::getDomainDetails($domain);
     if (Domains::isDomainUG($domain)) {
         $response['country'] = "UGANDA";
         $xml = (string) Domains::post('https://new.registry.co.ug:8006/api', ['body' => Domains::UG_Whois_Command($domain)]);
         $reader = new Reader();
         $reader->xml($xml);
         $parsedXML = $reader->parse();
         $data = $parsedXML['value'];
         $status = (int) $parsedXML['attributes']['status'];
         if ($status) {
             $response['status'] = true;
             Session::flash('errordomain', $domain . ' domain is not available');
             $response['data']['domain'] = $data[1]['attributes'];
             $response['data']['registrant'] = $data[2]['value'][0]['attributes'];
             $response['data']['admin'] = $data[2]['value'][1]['attributes'];
             $response['data']['billing'] = $data[2]['value'][2]['attributes'];
             $response['data']['tech'] = $data[2]['value'][3]['attributes'];
             $response['data']['nameservers'] = ["ns1" => $data[3]['value'][0]['value'], "ns2" => $data[3]['value'][1]['value'], "ns3" => $data[3]['value'][2]['value'], "ns4" => $data[3]['value'][3]['value']];
         } else {
             Session::flash('successdomain', $domain . ' domain is available');
         }
     } elseif (Domains::isDomainRW($domain)) {
         $response['country'] = "RWANDA";
         $response['status'] = true;
         $response['data'] = [];
         $domain = Domains::cleanURL($domain);
         $params = ['form_params' => ['search' => $domain], 'verify' => false];
         $data = Domains::post('https://whois.ricta.org.rw/whois.jsp', $params);
         if (preg_match_all('/<tr><th>(?:[a-zA-Z\\s]+)<\\/th><td><a href=\'(.+)\'>(?:[a-zA-Z\\.]+)<\\/a>/im', $data, $matches)) {
             Session::flash('errordomain', $domain . ' domain is not available');
         } else {
             Session::flash('successdomain', $domain . ' domain is available');
         }
     } else {
         $domain = Domains::cleanURL($domain);
         if (!empty($domain)) {
             $response['country'] = "INTERNATIONAL";
             try {
                 InternetBS::init('X1A7S0D7X8N0U0U0I6S2', 'Toto197500cxz');
                 if (InternetBS::api()->domainCheck($domain)) {
                     Session::flash('successdomain', $domain . ' domain is available');
                 } else {
                     Session::flash('errordomain', $domain . ' domain is not available');
                 }
             } catch (Exception $e) {
                 Session::flash('errordomain', ' Incorrect input domain. please type correctly');
             }
         } else {
             Session::flash('errordomain', ' Incorrect input domain. please type correctly');
         }
     }
     return view('domain.search', compact('response', $response));
 }