diff --git a/README.md b/README.md index e308f11..da3be48 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,22 @@ # ZOHO CRM PHP SDK +## Table Of Contents + +* [Overview](#overview) +* [Registering a Zoho Client](#registering-a-zoho-client) +* [Environmental Setup](#environmental-setup) +* [Including the SDK in your project](#including-the-sdk-in-your-project) +* [Persistence](#token-persistence) + * [DataBase Persistence](#database-persistence) + * [File Persistence](#file-persistence) + * [Custom Persistence](#custom-persistence) +* [Configuration](#configuration) +* [Initialization](#initializing-the-application) +* [Class Hierarchy](#class-hierarchy) +* [Responses And Exceptions](#responses-and-exceptions) +* [Multi-User support in the PHP SDK](#multi-user-support-in-the-php-sdk) +* [Sample Code](#sdk-sample-code) + ## Overview Zoho CRM PHP SDK offers a way to create client PHP applications that can be integrated with Zoho CRM. @@ -61,7 +78,7 @@ You can include the SDK to your project using: - Run the command below: ```sh - composer require zohocrm/php-sdk:3.0.0 + composer require zohocrm/php-sdk:3.0.1 ``` - The PHP SDK will be installed and a package named vendor will be created in the workspace of your client app. @@ -82,11 +99,12 @@ Token persistence refers to storing and utilizing the authentication tokens that ### Table of Contents -- DataBase Persistence +- [DataBase Persistence](#database-persistence) + +- [File Persistence](#file-persistence) -- File Persistence +- [Custom Persistence](#custom-persistence) -- Custom Persistence ### Implementing OAuth Persistence @@ -311,20 +329,27 @@ Before you get started with creating your PHP application, you need to register ```php /* - * autoRefreshFields + * autoRefreshFields (default value is false) * true - all the modules' fields will be auto-refreshed in the background, every hour. * false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com\zoho\crm\api\util\ModuleFieldsHandler) * - * pickListValidation + * pickListValidation (default value is true) * A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list. * true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error. * false - the SDK does not validate the input and makes the API request with the user’s input to the pick list + * + * enableSSLVerification (default value is true) + * A boolean field to enable or disable curl certificate verification + * true - the SDK verifies the authenticity of certificate + * false - the SDK skips the verification */ $autoRefreshFields = false; $pickListValidation = false; - $sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->build(); + $enableSSLVerification = true; + + $sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->setSSLVerification($enableSSLVerification)->build(); ``` - Create an instance of RequestProxy containing the proxy properties of the user. diff --git a/src/com/zoho/api/authenticator/OAuthToken.php b/src/com/zoho/api/authenticator/OAuthToken.php index fb36aa3..77171a4 100755 --- a/src/com/zoho/api/authenticator/OAuthToken.php +++ b/src/com/zoho/api/authenticator/OAuthToken.php @@ -311,6 +311,11 @@ public function getResponseFromServer($request_params) curl_setopt($curl_pointer, CURLOPT_CUSTOMREQUEST, Constants::REQUEST_METHOD_POST); + if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled()) + { + curl_setopt($curl_pointer, CURLOPT_SSL_VERIFYPEER, false); + } + $result = curl_exec($curl_pointer); curl_close($curl_pointer); diff --git a/src/com/zoho/crm/api/SDKConfigBuilder.php b/src/com/zoho/crm/api/SDKConfigBuilder.php index 35e6529..23e309c 100644 --- a/src/com/zoho/crm/api/SDKConfigBuilder.php +++ b/src/com/zoho/crm/api/SDKConfigBuilder.php @@ -10,16 +10,20 @@ class SDKConfigBuilder private $pickListValidation; + private $enableSSLVerification; + public function __Construct() { $this->autoRefreshFields = false; $this->pickListValidation = true; + + $this->enableSSLVerification = true; } /** * This is a setter method to set autoRefreshFields. - * @param autoRefreshFields + * @param autoRefreshFields */ public function setAutoRefreshFields(bool $autoRefreshFields) { @@ -39,13 +43,24 @@ public function setPickListValidation(bool $pickListValidation) return $this; } + /** + * This is a setter method to set enableSSLVerification. + * @param enableSSLVerification + */ + public function setSSLVerification(bool $enableSSLVerification) + { + $this->enableSSLVerification = $enableSSLVerification; + + return $this; + } + /** * The method to build the SDKConfig instance * @returns An instance of SDKConfig */ public function build() { - return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation); + return new \com\zoho\crm\api\sdkconfigbuilder\SDKConfig($this->autoRefreshFields, $this->pickListValidation, $this->enableSSLVerification); } } @@ -60,16 +75,21 @@ class SDKConfig private $pickListValidation; + private $enableSSLVerification; + /** * Creates an instance of SDKConfig with the given parameters * @param autoRefreshFields - A boolean representing autoRefreshFields * @param pickListValidation - A boolean representing pickListValidation + * @param enableSSLVerification - A boolean representing enableSSLVerification */ - public function __Construct(bool $autoRefreshFields, bool $pickListValidation) + public function __Construct(bool $autoRefreshFields, bool $pickListValidation, bool $enableSSLVerification) { $this->autoRefreshFields = $autoRefreshFields; $this->pickListValidation = $pickListValidation; + + $this->enableSSLVerification = $enableSSLVerification; } /** @@ -89,5 +109,14 @@ public function getPickListValidation() { return $this->pickListValidation; } + + /** + * This is a getter method to get enableSSLVerification. + * @return A boolean representing enableSSLVerification + */ + public function isSSLVerificationEnabled() + { + return $this->enableSSLVerification; + } } ?> \ No newline at end of file diff --git a/src/com/zoho/crm/api/util/APIHTTPConnector.php b/src/com/zoho/crm/api/util/APIHTTPConnector.php index f3866ab..22bc917 100755 --- a/src/com/zoho/crm/api/util/APIHTTPConnector.php +++ b/src/com/zoho/crm/api/util/APIHTTPConnector.php @@ -193,16 +193,21 @@ public function fireRequest($converterInstance) } $this->setQueryHeaders($curl_options); - + + if(!Initializer::getInitializer()->getSDKConfig()->isSSLVerificationEnabled()) + { + $curl_options[CURLOPT_SSL_VERIFYPEER] = false; + } + curl_setopt_array($curl_pointer, $curl_options); - + SDKLogger::info($this->toString()); $response = array(); $response[Constants::RESPONSE] = curl_exec($curl_pointer); - if (curl_errno($curl_pointer)) + if (curl_errno($curl_pointer)) { $response[Constants::ERROR] = curl_error($curl_pointer); } diff --git a/src/com/zoho/crm/api/util/CommonAPIHandler.php b/src/com/zoho/crm/api/util/CommonAPIHandler.php index 2d63058..1e55b6e 100755 --- a/src/com/zoho/crm/api/util/CommonAPIHandler.php +++ b/src/com/zoho/crm/api/util/CommonAPIHandler.php @@ -329,7 +329,7 @@ public function apiCall($className, $encodeType) } $converterInstance = $this->getConverterClassInstance(strtolower($responseContentType)); - + $returnObject = $converterInstance->getWrappedResponse($response[Constants::RESPONSE], $className); if ($returnObject !== null) @@ -393,25 +393,60 @@ private function isExpectedType(Model $model, string $className) */ public function getConverterClassInstance($encodeType) { - switch ($encodeType) + switch ($encodeType) { case "application/json": case "text/plain": + case "application/ld+json": return new JSONConverter($this); case "application/xml": case "text/xml": return new XMLConverter($this); case "multipart/form-data": return new FormDataConverter($this); - case "application/x-download": case "image/png": case "image/jpeg": - case "application/zip": case "image/gif": - case "text/csv": case "image/tiff": - case "application/octet-stream": + case "image/svg+xml": + case "image/bmp": + case "image/webp": + case "text/csv": case "text/html": + case "text/css": + case "text/javascript": + case "text/calendar": + case "application/x-download": + case "application/zip": + case "application/pdf": + case "application/java-archive": + case "application/javascript": + case "application/octet-stream": + case "application/xhtml+xml": + case "application/x-bzip": + case "application/msword": + case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + case "application/gzip": + case "application/x-httpd-php": + case "application/vnd.ms-powerpoint": + case "application/vnd.rar": + case "application/x-sh": + case "application/x-tar": + case "application/vnd.ms-excel": + case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + case "application/x-7z-compressed": + case "audio/mpeg": + case "audio/x-ms-wma": + case "audio/vnd.rn-realaudio": + case "audio/x-wav": + case "audio/3gpp": + case "audio/3gpp2": + case "video/mpeg": + case "video/mp4": + case "video/webm": + case "video/3gpp": + case "video/3gpp2": + case "font/ttf": return new Downloader($this); } diff --git a/src/com/zoho/crm/api/util/Constants.php b/src/com/zoho/crm/api/util/Constants.php index 6ccfc2b..79c595b 100755 --- a/src/com/zoho/crm/api/util/Constants.php +++ b/src/com/zoho/crm/api/util/Constants.php @@ -464,7 +464,7 @@ class Constants const FORM_REQUEST_EXCEPTION = "Exception in forming request body : "; - const SDK_VERSION = "3.0.0"; + const SDK_VERSION = "3.0.1"; const API_CALL_EXCEPTION = "Exception in current API call execution : "; diff --git a/src/com/zoho/crm/api/util/Downloader.php b/src/com/zoho/crm/api/util/Downloader.php index d54dee8..bf2359c 100644 --- a/src/com/zoho/crm/api/util/Downloader.php +++ b/src/com/zoho/crm/api/util/Downloader.php @@ -96,14 +96,19 @@ public function getResponse($response, $pack) $responseHeaders = $response[Constants::HEADERS]; $responseContent = $response[Constants::CONTENT]; - - $contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION]; - - if ($contentDisposition == null) + + $contentDisposition = ""; + + if(array_key_exists(Constants::CONTENT_DISPOSITION, $responseHeaders)) { - $contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1]; - } + $contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION]; + if ($contentDisposition == null) + { + $contentDisposition = $responseHeaders[Constants::CONTENT_DISPOSITION1]; + } + } + $fileName = substr($contentDisposition, strrpos($contentDisposition, "'") + 1, strlen($contentDisposition)); if (strpos($fileName, "=") !== false) diff --git a/src/com/zoho/crm/api/util/JSONConverter.php b/src/com/zoho/crm/api/util/JSONConverter.php index 82b32d0..448144d 100755 --- a/src/com/zoho/crm/api/util/JSONConverter.php +++ b/src/com/zoho/crm/api/util/JSONConverter.php @@ -1103,9 +1103,14 @@ public function buildName($memberName) $sdkName = lcfirst($name[0]); - for ($nameIndex = 1; $nameIndex < count($name); $nameIndex ++) + for ($nameIndex = 1; $nameIndex < count($name); $nameIndex ++) { - $firstLetterUppercase = ucfirst($name[$nameIndex]); + $firstLetterUppercase = ""; + + if(strlen(($name[$nameIndex])) > 0) + { + $firstLetterUppercase = ucfirst($name[$nameIndex]); + } $sdkName = $sdkName . $firstLetterUppercase; } diff --git a/src/com/zoho/crm/api/util/Utility.php b/src/com/zoho/crm/api/util/Utility.php index a9e18c7..e8fa6c1 100755 --- a/src/com/zoho/crm/api/util/Utility.php +++ b/src/com/zoho/crm/api/util/Utility.php @@ -843,13 +843,13 @@ public static function fillDataType() return; } - $fieldAPINamesString = ["textarea", "text", "website", "email", "phone", "mediumtext","multiselectlookup", "profileimage"]; + $fieldAPINamesString = ["textarea", "text", "website", "email", "phone", "mediumtext","multiselectlookup", "profileimage", "autonumber"]; $fieldAPINamesInteger = ["integer"]; $fieldAPINamesBoolean = ["boolean"]; - $fieldAPINamesLong = ["long", "bigint", "autonumber"]; + $fieldAPINamesLong = ["long", "bigint"]; $fieldAPINamesDouble = ["double", "percent", "lookup", "currency"];