/**
 * @param $conn eppConnection
 * @param $domainname string
 * @param $registrant string
 * @param $admincontact string
 * @param $techcontact string
 * @param $billingcontact string
 * @param $nameservers array
 * @return bool
 */
function createdomain($conn, $domainname, $registrant, $admincontact, $techcontact, $billingcontact, $nameservers)
{
    $domain = new eppDomain($domainname, $registrant);
    $domain->setRegistrant(new eppContactHandle($registrant));
    $domain->addContact(new eppContactHandle($admincontact, eppContactHandle::CONTACT_TYPE_ADMIN));
    $domain->addContact(new eppContactHandle($techcontact, eppContactHandle::CONTACT_TYPE_TECH));
    $domain->addContact(new eppContactHandle($billingcontact, eppContactHandle::CONTACT_TYPE_BILLING));
    $domain->setAuthorisationCode($domain->generateRandomString(12));
    if (is_array($nameservers)) {
        foreach ($nameservers as $nameserver) {
            $domain->addHost(new eppHost($nameserver));
        }
    }
    $create = new eppLaunchCreateDomainRequest($domain);
    $create->setLaunchPhase('claims', 'application');
    if ($response = $conn->request($create)) {
        /* @var Metaregistrar\EPP\eppLaunchCreateDomainResponse $response */
        echo "Domain " . $response->getDomainName() . " created on " . $response->getDomainCreateDate() . ", expiration date is " . $response->getDomainExpirationDate() . "\n";
        echo "Registration phase: " . $response->getLaunchPhase() . " and Application ID: " . $response->getLaunchApplicationID() . "\n";
    }
    return null;
}
/**
 * @param eppConnection $conn
 * @param string $domainname
 * @param array $claim
 * @param string $registrant
 * @param string $admincontact
 * @param string $techcontact
 * @param string $billingcontact
 * @param array $nameservers
 */
function createclaimeddomain($conn, $domainname, $claim, $registrant, $admincontact, $techcontact, $billingcontact, $nameservers)
{
    $domain = new eppDomain($domainname, $registrant);
    $domain->setPeriod(1);
    $reg = new eppContactHandle($registrant);
    $domain->setRegistrant($reg);
    if ($admincontact) {
        $admin = new eppContactHandle($admincontact, eppContactHandle::CONTACT_TYPE_ADMIN);
        $domain->addContact($admin);
    }
    if ($techcontact) {
        $tech = new eppContactHandle($techcontact, eppContactHandle::CONTACT_TYPE_TECH);
        $domain->addContact($tech);
    }
    if ($billingcontact) {
        $billing = new eppContactHandle($billingcontact, eppContactHandle::CONTACT_TYPE_BILLING);
        $domain->addContact($billing);
    }
    $domain->setAuthorisationCode($domain->generateRandomString(8));
    if (is_array($nameservers)) {
        foreach ($nameservers as $nameserver) {
            $host = new eppHost($nameserver);
            $domain->addHost($host);
        }
    }
    $create = new eppLaunchCreateDomainRequest($domain);
    $create->setLaunchPhase('claims');
    //$create->setLaunchCodeMark($domainname.';'.base64_encode(hash('sha512',$domainname.'MetaregistrarRocks!',true)),'Metaregistrar');
    $create->addLaunchClaim('tmch', $claim['noticeid'], $claim['notafter'], $claim['confirmed']);
    //echo $create->saveXML();
    if ($response = $conn->request($create)) {
        /* @var Metaregistrar\EPP\eppLaunchCreateDomainResponse $response */
        //echo $response->saveXML();
        echo "Domain " . $response->getDomainName() . " created on " . $response->getDomainCreateDate() . ", expiration date is " . $response->getDomainExpirationDate() . "\n";
        //echo "Registration phase: ".$response->getLaunchPhase()." and Application ID: ".$response->getLaunchApplicationID()."\n";
    }
}