Sample API access code Print

  • 0

Sample API access code:

 

<?php


define('ECOMMERCE_SUITE_URL', 'https://www.YOURDOMAIN.com'); //no trailing slash
define('JROX_AUTOMATION_API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('JROX_AUTOMATION_API_TOKEN', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx');

define('JROX_COMMISSION_TRACKING_KEY', 'xxxxxx');
define('JROX_CUSTOM_AFF_ID', 'custom_aff_id');
define('JROX_ENABLE_AUTO_CLIENT_ADD', true); //comment to disable
define('JROX_ENABLE_CLIENT_AUTO_LOGIN', true); //comment to disable
define('JROX_AFF_COOKIE', 'afftrackxxxxxxxxxxxxxxxxxx'); //set in your application/config/config.php file

$data = array(
	'firstname' => 'api',
	'lastname' => 'test',
	'email' => 'api6@YOURDOMAIN.com',
	'custom_id'     => ''
);

//echo jrox_api_client_add($data);


// ------------------------------------------------------------------------
function jrox_api_client_add($vars = '')
{
	if (defined('JROX_ENABLE_AUTO_CLIENT_ADD'))
	{
		$url = ECOMMERCE_SUITE_URL . '/api/post/members';

		$data = array(
			'api_command'   => 'create',
			'status'        => '1',
			'fname'         => $vars['firstname'],
			'lname'         => $vars['lastname'],
			'primary_email' => $vars['email'],
			'custom_id'     => $vars['userid'],
			'sponsor_id' => '4527',
		);

		if (!empty($_COOKIE[JROX_AFF_COOKIE]))
		{
		//	$data[JROX_AFF_COOKIE] = $_COOKIE[JROX_AFF_COOKIE];
		}

		return jrox_api_connect_curl($url, $data);

		//jrox_api_client_login(array('userid' => $vars['userid']));
	}
}

// ------------------------------------------------------------------------

function jrox_api_client_login($vars = '')
{
	if (defined('JROX_ENABLE_AUTO_CLIENT_LOGIN'))
	{
		$url = ECOMMERCE_SUITE_URL . '/api/session/login';

		$data = array(
			'api_command' => 'login',

			'key' => 'custom_id',
			'id'  => $vars['userid'],
		);

		$response = jrox_api_connect_curl($url, $data);

		$a = (json_decode($response));
		$name = $a->data->session_key;
		$value = $a->data->session_id;
		$expire = time() + (86400 * 30);
		$path = '/';
		$domain = '.'. DOMAIN_NAME;

		setcookie($name, $value, $expire, $path, $domain);
	}
}

// ------------------------------------------------------------------------

function jrox_api_generate_commission($vars = '')
{
	$cookie = '';
	if (!empty($_COOKIE[JROX_AFF_COOKIE]))
	{
		$cookie = $_COOKIE[JROX_AFF_COOKIE];
	}

	$data = array(JROX_AFF_COOKIE => $cookie,
	              'whmcs' => '1',

	);

	$url = ECOMMERCE_SUITE_URL . "/sale/generate/sub_total/1/trans_id/".$vars['invoiceid']."/key/" . JROX_COMMISSION_TRACKING_KEY;
	$url .= '?' . http_build_query($data);
	$JAMIntegrate = jrox_api_connect_curl($url, $data, false);
	//echo $url . '<br />';
	//die($JAMIntegrate);
}

// ------------------------------------------------------------------------

function jrox_api_connect_curl($url = '', $data = array(), $post = true)
{
	if ($post == true)
	{
		$data['api_key'] = JROX_AUTOMATION_API_KEY;
		$data['api_token'] = JROX_AUTOMATION_API_TOKEN;
	}

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);

	if ($post == true)
	{
		curl_setopt($ch, CURLOPT_POST, $post);
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
	}

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$response = curl_exec($ch);

	//$response .= '<br />' . $url . http_build_query($data);
	return $response;
}

Was this answer helpful?

« Back