-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement domain management functionality
- Loading branch information
1 parent
697ae16
commit 2f13003
Showing
5 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Services\Registrars\EnomClient; | ||
use App\Services\Registrars\ResellerClubClient; | ||
use App\Models\Subscription; | ||
use App\Models\HostingAccount; | ||
|
||
class DomainService | ||
{ | ||
protected $enomClient; | ||
protected $resellerClubClient; | ||
|
||
public function __construct(EnomClient $enomClient, ResellerClubClient $resellerClubClient) | ||
{ | ||
$this->enomClient = $enomClient; | ||
$this->resellerClubClient = $resellerClubClient; | ||
} | ||
|
||
public function registerDomain(Subscription $subscription, $domainName, $registrar = 'enom') | ||
{ | ||
$client = $this->getClientForRegistrar($registrar); | ||
$result = $client->registerDomain($domainName, $subscription->customer->id); | ||
|
||
if ($result) { | ||
$subscription->domain_name = $domainName; | ||
$subscription->domain_registrar = $registrar; | ||
$subscription->domain_expiration_date = $result['expiration_date']; | ||
$subscription->save(); | ||
|
||
// Update or create HostingAccount | ||
$hostingAccount = HostingAccount::updateOrCreate( | ||
['subscription_id' => $subscription->id], | ||
['domain' => $domainName] | ||
); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function renewDomain(Subscription $subscription, $period = 1) | ||
{ | ||
$client = $this->getClientForRegistrar($subscription->domain_registrar); | ||
$result = $client->renewDomain($subscription->domain_name, $period); | ||
|
||
if ($result) { | ||
$subscription->domain_expiration_date = $result['new_expiration_date']; | ||
$subscription->save(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function transferDomain(Subscription $subscription, $domainName, $authCode, $newRegistrar) | ||
{ | ||
$client = $this->getClientForRegistrar($newRegistrar); | ||
$result = $client->transferDomain($domainName, $authCode, $subscription->customer->id); | ||
|
||
if ($result) { | ||
$subscription->domain_name = $domainName; | ||
$subscription->domain_registrar = $newRegistrar; | ||
$subscription->domain_expiration_date = $result['expiration_date']; | ||
$subscription->save(); | ||
|
||
// Update HostingAccount | ||
$hostingAccount = HostingAccount::where('subscription_id', $subscription->id)->first(); | ||
if ($hostingAccount) { | ||
$hostingAccount->domain = $domainName; | ||
$hostingAccount->save(); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
protected function getClientForRegistrar($registrar) | ||
{ | ||
switch ($registrar) { | ||
case 'enom': | ||
return $this->enomClient; | ||
case 'resellerclub': | ||
return $this->resellerClubClient; | ||
default: | ||
throw new \Exception("Unsupported domain registrar: $registrar"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Services\Registrars; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class EnomClient | ||
{ | ||
protected $client; | ||
protected $apiUrl; | ||
protected $username; | ||
protected $password; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client(); | ||
$this->apiUrl = config('services.enom.api_url'); | ||
$this->username = config('services.enom.username'); | ||
$this->password = config('services.enom.password'); | ||
} | ||
|
||
public function registerDomain($domainName, $customerId) | ||
{ | ||
// Implement eNom API call to register domain | ||
// Return result with expiration date | ||
} | ||
|
||
public function renewDomain($domainName, $period) | ||
{ | ||
// Implement eNom API call to renew domain | ||
// Return result with new expiration date | ||
} | ||
|
||
public function transferDomain($domainName, $authCode, $customerId) | ||
{ | ||
// Implement eNom API call to transfer domain | ||
// Return result with expiration date | ||
} | ||
|
||
protected function makeApiCall($command, $params) | ||
{ | ||
$params = array_merge([ | ||
'command' => $command, | ||
'uid' => $this->username, | ||
'pw' => $this->password, | ||
'responsetype' => 'xml', | ||
], $params); | ||
|
||
$response = $this->client->get($this->apiUrl, [ | ||
'query' => $params, | ||
]); | ||
|
||
// Parse XML response and return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Services\Registrars; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class ResellerClubClient | ||
{ | ||
protected $client; | ||
protected $apiUrl; | ||
protected $authUserId; | ||
protected $apiKey; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client(); | ||
$this->apiUrl = config('services.resellerclub.api_url'); | ||
$this->authUserId = config('services.resellerclub.auth_userid'); | ||
$this->apiKey = config('services.resellerclub.api_key'); | ||
} | ||
|
||
public function registerDomain($domainName, $customerId) | ||
{ | ||
// Implement ResellerClub API call to register domain | ||
// Return result with expiration date | ||
} | ||
|
||
public function renewDomain($domainName, $period) | ||
{ | ||
// Implement ResellerClub API call to renew domain | ||
// Return result with new expiration date | ||
} | ||
|
||
public function transferDomain($domainName, $authCode, $customerId) | ||
{ | ||
// Implement ResellerClub API call to transfer domain | ||
// Return result with expiration date | ||
} | ||
|
||
protected function makeApiCall($action, $params) | ||
{ | ||
$params = array_merge([ | ||
'auth-userid' => $this->authUserId, | ||
'api-key' => $this->apiKey, | ||
], $params); | ||
|
||
$response = $this->client->post($this->apiUrl . $action, [ | ||
'form_params' => $params, | ||
]); | ||
|
||
// Parse JSON response and return result | ||
} | ||
} |