Example #1
0
/**
 * Checks the status of any domain marked as pending transfer, if the transfer is completed then domain is marked
 * as active and placed in the correct status, if the domain is marked as transfer cancelled then the domain is marked
 * as such in the WHMCS database
 * @param $params
 * @return array
 */
function domainbox_TransferSync($params)
{
    // Get the domainbox domain ID
    $table = "mod_domainbox";
    $fields = "domainboxDomainID";
    $where = array("whmcsDomainID" => $params['domainid']);
    $result = select_query($table, $fields, $where);
    $data = mysql_fetch_array($result);
    $domainID = $data['domainboxDomainID'];
    // API configuration
    $authParameters = getAuthParameters($params);
    $apiEndpoint = $params["TestMode"] ? "https://sandbox.domainbox.net/?WSDL" : "https://live.domainbox.net/?WSDL";
    // Command parameters
    $queryTransferParameters = new QueryTransferParameters();
    $queryTransferParameters->DomainName = $params["sld"] . '.' . $params["tld"];
    $queryTransferParameters->DomainId = $domainID;
    try {
        $parameters = array('AuthenticationParameters' => $authParameters, 'CommandParameters' => $queryTransferParameters);
        $client = new SoapClient($apiEndpoint, array('soap_version' => SOAP_1_2));
        $result = $client->QueryTransfer($parameters);
        $result = $result->QueryTransferResult;
        if ($result->ResultCode == 100) {
            switch ($result->TransferStatus) {
                case 3:
                    // Transfer Completed
                    // Need to get the correct expiry date for the domain
                    $queryDomainResult = domainbox_Sync($params);
                    $values['expirydate'] = $queryDomainResult['expirydate'];
                    break;
                case 4:
                    // Transfer Cancelled
                    $values['error'] = "Transfer Cancelled for domain " . $queryTransferParameters->DomainName;
                    // Mark domain as cancelled in the database
                    $table = "tbldomains";
                    $update = array("status" => "Cancelled");
                    $where = array("id" => $params['domainid']);
                    update_query($table, $update, $where);
                    break;
            }
            // Only mark as active if the transfer is completed
            $values["active"] = $result->TransferStatus == 3;
            //TODO: Check if the domain is expired post transfer (possible for UK domains).
            $values["expired"] = false;
        } else {
            // If the code is not 100 then return the Domainbox error
            $values["error"] = $result->ResultMsg;
        }
    } catch (Exception $e) {
        $values["error"] = "There was an error communicating with Domainbox";
    }
    return $values;
}