Example #1
0
function zopimapi_api_sso_request($email)
{
    date_default_timezone_set('GMT');
    $date = date('D, d M Y H:i:s e');
    $api_token = zopimapi_get_option('zopim_api_key');
    $api_secret = zopimapi_get_option('zopim_api_secret');
    // Some paramters
    $method = 'POST';
    $host = 'reseller.zopim.com';
    $uri = '/api/sso/request';
    $content = json_encode(array('email' => $email));
    $md5_content = base64_encode(md5($content, true));
    $string_to_sign = $method . "\n" . $md5_content . "\n" . $date . "\n" . $uri;
    // Calculate HMAC with SHA1 and base64-encoding
    $signature = base64_encode(hash_hmac('sha1', utf8_encode($string_to_sign), $api_secret, TRUE));
    // Create request
    $request = 'https://' . $host . $uri;
    $headr = array();
    $headr[] = 'Authorization: Zopim-Reseller-API ' . $api_token . ':' . $signature;
    $headr[] = 'API-Date: ' . $date;
    // Do request
    $ch = curl_init($request);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}
Example #2
0
?>
" class="regular-text" />
			<span class="description"><?php 
_e('Ingresa el texto que se muestra cuando un usuario ya existe', 'zopimapi');
?>
</span>
		</td>
	</tr>
	<tr valing="top">
		<th scope="row"><label><?php 
_e('Link de redirección');
?>
</label></th>
		<td>
			<input type="text" name="zopim_api_user_exist_link" id="zopim_api_user_exist_link" value="<?php 
echo zopimapi_get_option('zopim_api_user_exist_link');
?>
" class="regular-text" />
			<span class="description"><?php 
_e('http://example.com/usuarioexiste', 'zopimapi');
?>
</span>
		</td>
	</tr>
</table>




<p class="submit">
	<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php 
Example #3
0
function zopimapi_addclient()
{
    global $zopimapi;
    extract($_POST);
    if (!isset($_POST) || $_POST['action'] != 'zopimapi_addclient') {
        die;
    }
    $error = array();
    if (empty($nombre)) {
        $error[] = 'nombre';
        $error['error'] = "empty";
    }
    if (empty($apellido)) {
        $error[] = 'apellido';
        $error['error'] = "empty";
    }
    if (empty($empresa)) {
        $error[] = 'empresa';
        $error['error'] = "empty";
    }
    if (empty($telefono)) {
        $error[] = 'telefono';
        $error['error'] = "empty";
    }
    if (empty($email)) {
        $error[] = 'email';
        $error['error'] = "empty";
    }
    if (empty($pass)) {
        $error[] = 'pass';
        $error['error'] = "empty";
    }
    if (!empty($error)) {
        $output = $error;
    } else {
        //$zopim_api_response = array();
        $zopim_api_response = zopimapi_api_addclient($_POST);
        //$zopim_api_response['status'] = 'active';
        //si la respuesta es active
        //continuamos
        if ($zopim_api_response['status'] == 'active') {
            // Si ZOPIM API creo el usuario
            $whmcs_api_addclient_response = zopimapi_whmcs_api_addclient($_POST);
            //Retorna un client_id
            //$whmcs_api_addclient_response['status'] == 'active'
            if ($whmcs_api_addclient_response['status'] == 'active') {
                $client_id = $whmcs_api_addclient_response['clientid'];
                $whmcs_api_addorder_response = zopimapi_whmcs_api_addorder($client_id);
                if ($whmcs_api_addorder_response['status'] = 'active') {
                    $order_id = $whmcs_api_addorder_response['orderid'];
                    $whmcs_api_acceptorder_response = zopimapi_whmcs_api_acceptorder($order_id);
                    if ($whmcs_api_acceptorder_response['status'] == 'active') {
                        $sso = zopimapi_api_sso_request($email);
                        // Single Sign On ZOPIM
                        $output = array('done' => 'success', 'redirect' => $sso['redirect_uri']);
                    } else {
                        // No se acepto la orden
                        $output = array('error' => "whmcs", "message" => $whmcs_api_acceptorder_response['error']);
                    }
                } else {
                    // No se creo la orden
                    $output = array('error' => "whmcs", "message" => $whmcs_api_addoorder_response['error']);
                }
            } else {
                // No se creo el usuario
                $output = array('error' => "whmcs", "message" => $whmcs_api_addclient_response['error']);
            }
        } else {
            // Si ZOPIM API NO creo el usuario
            if ($zopim_api_response["error"] == 'Validation Failed') {
                if (array_key_exists('email', $zopim_api_response)) {
                    $array_response = array("status" => 'error', "error" => "zopim", "message" => zopimapi_get_option('zopim_api_user_exist'), "link" => zopimapi_get_option('zopim_api_user_exist_link'), "elemento" => 'email');
                }
            }
            $output = $array_response;
        }
    }
    $output = json_encode($output);
    if (is_array($output)) {
        print_r($output);
    } else {
        echo $output;
    }
    die;
}
Example #4
0
function zopimapi_whmcs_api_acceptorder($order_id)
{
    $url = zopimapi_get_option('whmcs_url');
    # URL to WHMCS API file
    $username = zopimapi_get_option('admin_user');
    # Admin username goes here
    $password = zopimapi_get_option('admin_pass');
    # Admin password goes here
    $postfields["username"] = $username;
    $postfields["password"] = md5($password);
    $postfields["action"] = "acceptorder";
    #action performed by the [[API:Functions]]
    $postfields["orderid"] = $order_id;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    $data = curl_exec($ch);
    curl_close($ch);
    $data = explode(";", $data);
    $results = array();
    foreach ($data as $temp) {
        $temp = explode("=", $temp);
        $results[$temp[0]] = $temp[1];
    }
    if ($results["result"] == "success") {
        $response = array("status" => "active");
        return $response;
        exit;
    } else {
        $response = array("error" => $results["message"]);
        return $response;
        exit;
    }
}