Add a domain registrar
A registrar is one PHP class in library/Registrar/Adapter/ of the ClientFence directory. The file
name and the class name match: ExampleRegistrar.php holds Registrar_Adapter_ExampleRegistrar,
which extends Registrar_AdapterAbstract. Use a name no built-in registrar uses, so updates never
replace your file.
A module can also carry the file in its own Registrar/Adapter/ folder; it is
then available while the module is active.
The adapter
Section titled “The adapter”getConfig() builds the registrar’s settings form; the values reach the constructor. Each other
method gets a Registrar_Domain with the name, the period, the nameservers and the contact.
Throw a Registrar_Exception when the registrar refuses: staff and clients see its message.
declare(strict_types=1);
class Registrar_Adapter_ExampleRegistrar extends Registrar_AdapterAbstract{ public function __construct(private array $options) { if (empty($this->options['api_key'])) { throw new Registrar_Exception('Enter the API key of Example Registrar.'); } }
public static function getConfig(): array { return [ 'label' => 'Registers domains through Example Registrar.', 'form' => [ 'api_key' => ['password', ['label' => 'API key', 'required' => true]], ], ]; }
public function isDomainAvailable(Registrar_Domain $domain): bool { return $this->call('GET', 'domains/' . $domain->getName() . '/availability')['available']; }
public function isDomaincanBeTransferred(Registrar_Domain $domain): bool { return $this->call('GET', 'domains/' . $domain->getName() . '/transferable')['transferable']; }
public function registerDomain(Registrar_Domain $domain): bool { $this->call('POST', 'domains', [ 'name' => $domain->getName(), 'years' => $domain->getRegistrationPeriod(), 'nameservers' => array_values(array_filter([$domain->getNs1(), $domain->getNs2(), $domain->getNs3(), $domain->getNs4()])), 'contact' => $domain->getContactRegistrar()->getEmail(), ]);
return true; }
public function transferDomain(Registrar_Domain $domain): bool { $this->call('POST', 'transfers', ['name' => $domain->getName(), 'auth_code' => $domain->getEpp()]);
return true; }
public function renewDomain(Registrar_Domain $domain): bool { $this->call('POST', 'domains/' . $domain->getName() . '/renew', ['years' => $domain->getRegistrationPeriod()]);
return true; }
public function getDomainDetails(Registrar_Domain $domain): Registrar_Domain { $details = $this->call('GET', 'domains/' . $domain->getName()); $domain->setExpirationTime(strtotime($details['expires_at']));
return $domain; }
public function modifyNs(Registrar_Domain $domain): bool { $this->call('PUT', 'domains/' . $domain->getName() . '/nameservers', [ 'nameservers' => array_values(array_filter([$domain->getNs1(), $domain->getNs2(), $domain->getNs3(), $domain->getNs4()])), ]);
return true; }
public function getEpp(Registrar_Domain $domain): string { return $this->call('GET', 'domains/' . $domain->getName() . '/auth-code')['auth_code']; }
// Actions this registrar does not offer: the admin area shows the message. public function modifyContact(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
public function deleteDomain(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
public function enablePrivacyProtection(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
public function disablePrivacyProtection(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
public function lock(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
public function unlock(Registrar_Domain $domain): bool { throw new Registrar_Exception('Example Registrar does not support this action.'); }
private function call(string $method, string $path, array $body = []): array { $response = $this->getHttpClient()->request($method, 'https://api.example-registrar.com/v1/' . $path, [ 'auth_bearer' => $this->options['api_key'], 'json' => $method === 'GET' ? null : $body, ]); if ($response->getStatusCode() >= 400) { throw new Registrar_Exception('Example Registrar: ' . $response->getContent(false)); }
return $response->toArray(); }}getHttpClient() and getLog() come from Registrar_AdapterAbstract.
Price list and transfer status (optional)
Section titled “Price list and transfer status (optional)”Two optional interfaces add the price import and transfer tracking. Without them the registrar works as before.
class Registrar_Adapter_ExampleRegistrar extends Registrar_AdapterAbstract implements Registrar_TldPrices, Registrar_TransferStatus{ // One year's cost per action in the registrar's currency; null = not offered. public function getTldPrices(array $tlds = []): array { return [ 'currency' => 'USD', 'prices' => ['.com' => ['register' => 10.50, 'renew' => 12.00, 'transfer' => 10.50]], 'remaining' => [], // TLDs not priced in this call, asked for again in the next one ]; }
public function getTransferStatus(Registrar_Domain $domain): array { $status = $this->call('GET', 'transfers/' . $domain->getName())['status'];
return [ 'status' => match ($status) { 'done' => Registrar_TransferStatus::COMPLETED, 'rejected', 'cancelled' => Registrar_TransferStatus::FAILED, default => Registrar_TransferStatus::PENDING, }, 'message' => $status, ]; }}$tlds is empty for the whole list, or names the TLDs to price (with the leading dot). Throw a
Registrar_Exception when the registrar cannot be asked: the check runs again later. A transfer counts as
completed only once getDomainDetails() also works for the domain.
Ask for registrant details
Section titled “Ask for registrant details”When a registry needs more than the contact, such as the .us nexus, declare the questions in
getDomainFields(). The order forms show them for that extension, ClientFence checks the required
ones, and your methods read the answers with $domain->getFields(). $action is register or
transfer. Each value in options is what your registrar receives.
public static function getDomainFields(string $tld, string $action = 'register'): array{ if (strtolower($tld) !== '.example') { return []; }
return [ 'registrant_type' => ['label' => 'Registrant type', 'required' => true, 'options' => ['P' => 'Person', 'C' => 'Company']], 'company_number' => ['label' => 'Company number'], ];}For the .us questions, return self::usNexusFields().
Install it
Section titled “Install it”- Copy the file to
library/Registrar/Adapter/and make the web server user its owner. - Go to System → Domain Registration, open the Registrars tab, select New Domain Registrar and install ExampleRegistrar under Available Registrars.
- Open it, enter its settings and select Update. Then choose it for your domain extensions (see Set up domain sales).
For complete examples, read Namecheap.php, Dynadot.php and Enom.php in the same folder.

