Esempio n. 1
0
 public function test__set_customfieldvalue__returnSuccess()
 {
     $result = Domenus::set_customfieldvalue('domenus_registrant', 'client', 140, 'foobar145');
     $this->assertEquals($result, true);
 }
Esempio n. 2
0
/**
 *  Register domain in WHMCS
 *  @params Array $params containing Domain and User info
 *  @return String $success
 * */
function domenus_RegisterDomain($params)
{
    $return_data = [];
    $registered = null;
    // making sure that we got domain name in hand.
    if (!empty($params['domainname'])) {
        $domain = $params['domainname'];
    } else {
        //find via tbldomains
        $res = full_query("SELECT domain FROM tbldomains WHERE id='{$params['domainid']}'");
        $record = mysql_fetch_assoc($res);
        $domain = $record['domain'];
    }
    // do preliminary check for domain registry with inclusive OR.
    $check_flag = Domenus::DOMAIN_IS_FREE | Domenus::DOMAIN_IS_VALID | Domenus::DOMAIN_FOR_REGISTER;
    $checked = Domenus::call('domain/check', ['domain' => $domain, 'flag' => $check_flag]);
    logModuleCall('domenus_registrar', __FUNCTION__ . ':domain/check', print_r(['domain' => $domain, 'flag' => $check_flag], 1), print_r($checked, 1));
    die("No registration avaiable. Remove die flag if you're sure");
    if ($checked['status'] == true) {
        $domain_registrant = Domenus::get_customfieldvalue('domenus_registrant', 'client', $params['userid']);
        // we know that registrant exists on WHMCS, we also need to
        // check if it exists on the side of the registrar.
        if (!empty($domain_registrant)) {
            $existing_user = Domenus::call('contact/info', ['registrant' => $domain_registrant]);
            logModuleCall('domenus_registrar', __FUNCTION__ . ':contact/info', print_r(['registrant' => $domain_registrant], 1), print_r($existing_user, 1));
        }
        // the info is verified, and we can proceed with registering domain
        if ($existing_user['status'] == true && !empty($domain_registrant)) {
            $data = array('domain' => $domain, 'registrant' => $domain_registrant, 'nserver' => prepare_ns_servers($params));
            $registered = Domenus::call('domain/register', $data);
            logModuleCall('domenus_registrar', __FUNCTION__ . ':domain/register', print_r($data, 1), print_r($registered, 1));
            unset($data);
            // to avoid var overwrites
        } else {
            //we have to register the user at first
            $prepared_data = prepare_contact_fields($params);
            $prepared_data['contact_type'] = 'person';
            if (!isset($prepared_data['errors']) || empty($prepared_data['errors'])) {
                $saved_user = Domenus::call('contact/register', $prepared_data);
                logModuleCall('domenus_registrar', __FUNCTION__ . ':contat/register', print_r($prepared_data, 1), print_r($saved_user, 1));
                if ($saved_user['status'] == true) {
                    $domain_registrant = $saved_user['content']['data']['registrant'];
                    $saved = Domenus::set_customfieldvalue('domenus_registrant', 'client', $params['userid'], $domain_registrant);
                    if ($saved) {
                        $data = array('domain' => $domain, 'registrant' => $domain_registrant, 'nserver' => prepare_ns_servers($params));
                        $registered = Domenus::call('domain/register', $data);
                        logModuleCall('domenus_registrar', __FUNCTION__ . ':domain/register', print_r($data, 1), print_r($registered, 1));
                    }
                }
            } else {
                $return_data['error'] = join('. ', $prepared_data['errors']);
            }
        }
        // if everything's okay, we should store orderId of the registered domain,
        // for future use.
        if (!is_null($registered) && $registered['status'] == true) {
            $order_id = $registered['content']['data']['orderId'];
            $saved_order = Domenus::set_domainadditionalfield($params['domainid'], 'orderId', $order_id);
            if ($saved_order) {
                $return_data['success'] = true;
            }
        } else {
            $return_data['error'] = "Couldn't receive domain registration orderId. Check logs";
        }
    } else {
        $return_data['error'] = "Couldn't check the domain before registration: " . join('. ', $checked['errors']);
    }
    return $return_data;
}