0;
if($tableExist){
$pdo = Capsule::connection()->getPdo();
$pdo->beginTransaction();
}
else{
Capsule::schema()->create(
'zoho_crm',
function ($table) {
$table->string('authtoken');
$table->string('domain');
$table->string('zoid');
$table->string('superAdmin');
$table->string('isverified');
$table->string('url');
}
);
}
} catch (Exception $e) {
logModuleCall(
'zoho_crm',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
}
return array(
'DisplayName' => 'Zoho CRM',
'APIVersion' => '1.1',
'RequiresServer' => true,
'DefaultNonSSLPort' => '1111',
'DefaultSSLPort' => '1112',
'ServiceSingleSignOnLabel' => 'Login to Panel as User',
'AdminSingleSignOnLabel' => 'Login to Panel as Admin',
);
}
function zoho_crm_ConfigOptions()
{
$config = array (
'Domain' => array('Type' => 'dropdown', 'Options' => 'com,eu', 'Description' => '
Domain Region'),
);
return $config;
}
/*function zoho_crm_createAccount(array $params) {
$curl = curl_init();
$arrClient = $params['clientsdetails'];
$bodyArr = array (
'JSONString' => array(
"serviceid" => 1,
"email" => $arrClient['email'],
"customer" => array(
"companyname" => $arrClient['companyname'],
"street" => $arrClient['address1'],
"city" => $arrClient['city'],
"state" => $arrClient['state'],
"country" => $arrClient['countryname'],
"zipcode" => $arrClient['postcode'],
"phone" => $arrClient['phonenumber']
),
"subscription" => array(
"plan" => "9314",
"addons" => array(
"id" => "126",
"count" => 1
),
"payperiod" => "YEAR"
),
),
);
$authtoken = array(
"authtoken" => "f6d12862690c14a95576fd8d60b10458"
);
$partnerkey = array (
"partnerkey" => "1d8f135ac08a1134009a1d348dc510bef83ce09843f596669a0b5ec84090750f"
);
$bodyJson = json_encode($bodyArr);
$curlOrg = curl_init();
$urlOrg = 'https://payments.localzoho.'.$params['configoption1'].'/restapi/partner/v1/json/subscription';
curl_setopt_array($curlOrg, array(
CURLOPT_URL => $urlOrg,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $bodyArr, $authtoken, $partnerkey
));
$responseOrg = curl_exec($curlOrg);
return array ('success' => $bodyJson);
}
*/
// {"JSONString":{"serviceid":1,"email":"test@gmail.com","customer":{"companyname":"zoho","street":"21, nehru street","city":"chennai","state":"Tamil Nadu","country":"India","zipcode":"614601","phone":"9876543211"},"subscription":{"plan":"9314","addons":{"id":"126","count":1},"payperiod":"YEAR"}}}
function zoho_crm_createAccount(array $params) {
$urlChildPanel;
try {
//$cli = Capsule::table('zoho_crm')->where('domain',$params['domain'])->first();
//$authtoken = $cli->authtoken;
$curl = curl_init();
$arrClient = $params['clientsdetails'];
$bodyArr = array(
//'JSONString' => array(
"serviceid" => 2,
"email" => $arrClient['email'],
"customid" => "97",
"customer" => array(
"companyname" => $arrClient['companyname'],
"street" => $arrClient['address1'],
"city" => $arrClient['city'],
"state" => $arrClient['state'],
"country" => $arrClient['countryname'],
"zipcode" => $arrClient['postcode'],
"phone" => $arrClient['phonenumber']
),
"subscription" => array(
"plan" => 14817,
"addons" => array(
array(
"id" => 14927,
"count" => 1
)
),
"payperiod" => "YEAR",
"currency" => "1",
"addprofile" => "true"
),
//),
);
$authtoken = array(
"authtoken" => "f6d12862690c14a95576fd8d60b10458"
);
$partnerkey = array (
"partnerkey" => "1d8f135ac08a1134009a1d348dc510bef83ce09843f596669a0b5ec84090750f"
);
$bodyJson = json_encode(array('JSONString' => $bodyArr));
//$bodyJson = json_encode($bodyArr);
$curlOrg = curl_init();
$urlOrg = 'https://payments.localzoho.'.$params['configoption1'].'/restapi/partner/v1/json/subscription';
curl_setopt_array($curlOrg, array(
CURLOPT_URL => $urlOrg,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $bodyArr&$authtoken&$partnerkey
));
$responseOrg = curl_exec($curlOrg);
return array ('success' => $responseOrg);
$respOrgJson = json_decode($responseOrg);
$getInfo = curl_getinfo($curlOrg,CURLINFO_HTTP_CODE);
curl_close($curlOrg);
if ( $getInfo == '200')
{
//if(Capsule::schema()->hasTable('zoho_crm')){
//if(exists:zoho_crm){
/*$result = mysql_query("SHOW TABLES LIKE 'zoho_crm'");
$tableExist = mysql_num_rows($result) > 0;
if($tableExist){
$pdo = Capsule::connection()->getPdo();
$pdo->beginTransaction();
*/
try {
$statement = $pdo->prepare(
'insert into zoho_crm (authtoken,domain,zoid,isverified,superAdmin,url) values (:authtoken, :domain, :zoid, :isverified, :superAdmin, :url)'
);
$statement->execute(
[
':authtoken' => "f6d12862690c14a95576fd8d60b10458",
':domain' => $respOrgJson->data->domainName,
':zoid' => $respOrgJson->data->zoid,
':isverified' => ($respOrgJson->data->isVerified)?'true':'false',
':superAdmin' => $respOrgJson->data->superAdmin,
':url' => $urlChildPanel
]
);
$pdo->commit();
} catch (\Exception $e) {
return "Uh oh! {$e->getMessage()}".$urlChildPanel;
$pdo->rollBack();
}
return array ('success' => 'CRM Org has been created.');
/*}
else{
echo "Table not exists";
}*/
}
else if ($getInfo == '400') {
$updatedUserCount = Capsule::table('tblproducts')
->where('servertype','zoho_crm')
->update(
[
'configoption2' => '',
]
);
}
else
{
return 'Failed -->Description: '.$respOrgJson->status->description.' --->More Information:'.$respOrgJson->data->moreInfo.'--------------'.$getInfo;
}
return 'failed'.$response;
} catch (Exception $e) {
logModuleCall(
'zoho_crm',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
return $e->getMessage();
}
}
function zoho_crm_TestConnection(array $params)
{
try {
// Call the service's connection test function.
$success = true;
$errorMsg = '';
} catch (Exception $e) {
// Record the error in WHMCS's module log.
logModuleCall(
'zoho_crm',
__FUNCTION__,
$params,
$e->getMessage(),
$e->getTraceAsString()
);
$success = false;
$errorMsg = $e->getMessage();
}
return array(
'success' => $success,
'error' => $errorMsg,
);
}
function zoho_crm_AdminServicesTabFields(array $params)
{
try{
$url = 'https://accounts.localzoho.'.$params['configoption1'].'/apiauthtoken/create?SCOPE=ZohoPayments/partnerkey';
$cli = Capsule::table('zoho_crm')->where('domain',$params['domain'])->first();
$authtoken = "f6d12862690c14a95576fd8d60b10458";
if(!$authtoken == '') {
$authtoken = '