PHP SDK Samples - Currencies Operations
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\ResponseWrapper;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class GetCurrencies
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function getCurrencies()
{
$currenciesOperations = new CurrenciesOperations();
$response = $currenciesOperations->getCurrencies();
if($response != null)
{
echo("Status code : " . $response->getStatusCode() . "\n");
if(in_array($response->getStatusCode(), array(204, 304)))
{
echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");
return;
}
$responseHandler = $response->getObject();
if($responseHandler instanceof ResponseWrapper)
{
$responseWrapper = $responseHandler;
$currenciesList = $responseWrapper->getCurrencies();
foreach($currenciesList as $currency)
{
echo("Currency Symbol: " . $currency->getSymbol() . "\n");
echo("Currency CreatedTime: "); print_r($currency->getCreatedTime()); echo("\n");
echo("Currency IsActive: " . $currency->getIsActive() . "\n");
echo("Currency ExchangeRate: " . $currency->getExchangeRate() . "\n");
$format = $currency->getFormat();
if($format != null)
{
echo("Currency Format DecimalSeparator: " . $format->getDecimalSeparator()->getValue() . "\n");
echo("Currency Format ThousandSeparator: " . $format->getThousandSeparator()->getValue() . "\n");
echo("Currency Format DecimalPlaces: " . $format->getDecimalPlaces()->getValue() . "\n");
}
$createdBy = $currency->getCreatedBy();
if($createdBy != null)
{
echo("Currency CreatedBy User-Name: " . $createdBy->getName() . "\n");
echo("Currency CreatedBy User-ID: " . $createdBy->getId() . "\n");
}
echo("Currency PrefixSymbol: " . $currency->getPrefixSymbol() . "\n");
echo("Currency IsBase: " . $currency->getIsBase() . "\n");
echo("Currency ModifiedTime: "); print_r($currency->getModifiedTime()); echo("\n");
echo("Currency Name: " . $currency->getName() . "\n");
$modifiedBy = $currency->getModifiedBy();
if($modifiedBy != null)
{
echo("Currency ModifiedBy User-Name: " . $modifiedBy->getName() . "\n");
echo("Currency ModifiedBy User-ID: " . $modifiedBy->getId() . "\n");
}
echo("Currency Id: " . $currency->getId() . "\n");
echo("Currency IsoCode: " . $currency->getIsoCode() . "\n");
}
}
else if($responseHandler instanceof APIException)
{
$exception = $responseHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
GetCurrencies::initialize();
GetCurrencies::getCurrencies();
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\Format;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\currencies\ActionWrapper;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\SuccessResponse;
use com\zoho\crm\api\currencies\BodyWrapper;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class UpdateCurrencies
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function updateCurrencies()
{
$currenciesOperations = new CurrenciesOperations();
$bodyWrapper = new BodyWrapper();
$currencies = array();
$currencyClass = "com\zoho\crm\api\currencies\Currency";
$currency = new $currencyClass();
$currency->setPrefixSymbol(true);
$currency->setId("34770616040001");
$currency->setExchangeRate("5.00");
$currency->setIsActive(true);
$format = new Format();
$format->setDecimalSeparator(new Choice("Period"));
$format->setThousandSeparator(new Choice("Comma"));
$format->setDecimalPlaces(new Choice("2"));
$currency->setFormat($format);
array_push($currencies, $currency);
$bodyWrapper->setCurrencies($currencies);
$response = $currenciesOperations->updateCurrencies($bodyWrapper);
if($response != null)
{
echo("Status Code: " . $response->getStatusCode() . "\n");
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getCurrencies();
foreach($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
echo("Code: " . $successResponse->getCode()->getValue() . "\n");
echo("Details: " );
foreach($successResponse->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
}
else if($actionResponse instanceof APIException)
{
$exception = $actionResponse;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
else if($actionHandler instanceof APIException)
{
$exception = $actionHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
UpdateCurrencies::initialize();
UpdateCurrencies::updateCurrencies();
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\Format;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\SuccessResponse;
use com\zoho\crm\api\currencies\BaseCurrencyWrapper;
use com\zoho\crm\api\currencies\BaseCurrencyActionWrapper;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class EnableMultipleCurrencies
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function enableMultipleCurrencies()
{
$currenciesOperations = new CurrenciesOperations();
$bodyWrapper = new BaseCurrencyWrapper();
$currencyClass = "com\zoho\crm\api\currencies\Currency";
$currency = new $currencyClass();
$currency->setPrefixSymbol(true);
$currency->setName("Angolan Kwanza - AOA");
$currency->setIsoCode("AOA");
$currency->setSymbol("Kz");
$currency->setExchangeRate("1.00");
$currency->setIsActive(true);
$format = new Format();
$format->setDecimalSeparator(new Choice("Period"));
$format->setThousandSeparator(new Choice("Comma"));
$format->setDecimalPlaces(new Choice("2"));
$currency->setFormat($format);
$bodyWrapper->setBaseCurrency($currency);
$response = $currenciesOperations->enableMultipleCurrencies($bodyWrapper);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$baseCurrencyActionHandler = $response->getObject();
if($baseCurrencyActionHandler instanceof BaseCurrencyActionWrapper)
{
$baseCurrencyActionWrapper = $baseCurrencyActionHandler;
$actionResponse = $baseCurrencyActionWrapper->getBaseCurrency();
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
echo("Code: " . $successResponse->getCode()->getValue() . "\n");
echo("Details: " );
foreach($successResponse->getDetails() as $key => $value)
{
echo($key . ": " . $value);
}
echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
}
else if($actionResponse instanceof APIException)
{
$exception = $actionResponse;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value);
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
else if($baseCurrencyActionHandler instanceof APIException)
{
$exception = $baseCurrencyActionHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
EnableMultipleCurrencies::initialize();
EnableMultipleCurrencies::enableMultipleCurrencies();
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\Format;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\SuccessResponse;
use com\zoho\crm\api\currencies\BaseCurrencyWrapper;
use com\zoho\crm\api\currencies\BaseCurrencyActionWrapper;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class UpdateBaseCurrency
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function updateBaseCurrency()
{
$currenciesOperations = new CurrenciesOperations();
$bodyWrapper = new BaseCurrencyWrapper();
$currencyClass = "com\zoho\crm\api\currencies\Currency";
$currency = new $currencyClass();
$currency->setPrefixSymbol(true);
$currency->setSymbol("Af");
$currency->setExchangeRate("1.00");
$currency->setId("34770616008002");
$format = new Format();
$format->setDecimalSeparator(new Choice("Period"));
$format->setThousandSeparator(new Choice("Comma"));
$format->setDecimalPlaces(new Choice("2"));
$currency->setFormat($format);
$bodyWrapper->setBaseCurrency($currency);
$response = $currenciesOperations->updateBaseCurrency($bodyWrapper);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$baseCurrencyActionHandler = $response->getObject();
if($baseCurrencyActionHandler instanceof BaseCurrencyActionWrapper)
{
$baseCurrencyActionWrapper = $baseCurrencyActionHandler;
$actionResponse = $baseCurrencyActionWrapper->getBaseCurrency();
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
echo("Code: " . $successResponse->getCode()->getValue() . "\n");
echo("Details: " );
foreach($successResponse->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
}
else if($actionResponse instanceof APIException)
{
$exception = $actionResponse;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
else if($baseCurrencyActionHandler instanceof APIException)
{
$exception = $baseCurrencyActionHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
UpdateBaseCurrency::initialize();
UpdateBaseCurrency::updateBaseCurrency();
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\ResponseWrapper;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class GetCurrency
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function getCurrency(string $currencyId)
{
$currenciesOperations = new CurrenciesOperations();
$response = $currenciesOperations->getCurrency($currencyId);
if($response != null)
{
echo("Status code " . $response->getStatusCode() . "\n");
if(in_array($response->getStatusCode(), array(204, 304)))
{
echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");
return;
}
$responseHandler = $response->getObject();
if($responseHandler instanceof ResponseWrapper)
{
$responseWrapper = $responseHandler;
$currenciesList = $responseWrapper->getCurrencies();
foreach($currenciesList as $currency)
{
echo("Currency Symbol: " . $currency->getSymbol() . "\n");
echo("Currency CreatedTime: "); print_r($currency->getCreatedTime()); echo("\n");
echo("Currency IsActive: " . $currency->getIsActive() . "\n");
echo("Currency ExchangeRate: " . $currency->getExchangeRate() . "\n");
$format = $currency->getFormat();
if($format != null)
{
echo("Currency Format DecimalSeparator: " . $format->getDecimalSeparator()->getValue() . "\n");
echo("Currency Format ThousandSeparator: " . $format->getThousandSeparator()->getValue() . "\n");
echo("Currency Format DecimalPlaces: " . $format->getDecimalPlaces()->getValue() . "\n");
}
$createdBy = $currency->getCreatedBy();
if($createdBy != null)
{
echo("Currency CreatedBy User-Name: " . $createdBy->getName() . "\n");
echo("Currency CreatedBy User-ID: " . $createdBy->getId() . "\n");
}
echo("Currency PrefixSymbol: " . $currency->getPrefixSymbol() . "\n");
echo("Currency IsBase: " . $currency->getIsBase() . "\n");
echo("Currency ModifiedTime: "); print_r($currency->getModifiedTime()); echo("\n");
echo("Currency Name: " . $currency->getName() . "\n");
$modifiedBy = $currency->getModifiedBy();
if($modifiedBy != null)
{
echo("Currency ModifiedBy User-Name: " . $modifiedBy->getName() . "\n");
echo("Currency ModifiedBy User-ID: " . $modifiedBy->getId() . "\n");
}
echo("Currency Id: " . $currency->getId() . "\n");
echo("Currency IsoCode: " . $currency->getIsoCode() . "\n");
}
}
else if($responseHandler instanceof APIException)
{
$exception = $responseHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
GetCurrency::initialize();
$currencyId = "34770616011001";
GetCurrency::getCurrency($currencyId);
<?php
namespace samples\currencies;
use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\currencies\Format;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\currencies\ActionWrapper;
use com\zoho\crm\api\currencies\APIException;
use com\zoho\crm\api\currencies\SuccessResponse;
use com\zoho\crm\api\currencies\BodyWrapper;
use com\zoho\crm\api\currencies\CurrenciesOperations;
require_once "vendor/autoload.php";
class UpdateCurrency
{
public static function initialize()
{
$user = new UserSignature('myname@mydomain.com');
$environment = USDataCenter::PRODUCTION();
$token = (new OAuthBuilder())
->clientId("1000.xxxx")
->clientSecret("xxxxxx")
->refreshToken("1000.xxxxx.xxxxx")
->build();
(new InitializeBuilder())
->user($user)
->environment($environment)
->token($token)
->initialize();
}
public static function updateCurrency(string $currencyId)
{
$currenciesOperations = new CurrenciesOperations();
$bodyWrapper = new BodyWrapper();
$currencies = array();
$currencyClass = "com\zoho\crm\api\currencies\Currency";
$currency = new $currencyClass();
$currency->setPrefixSymbol(true);
$currency->setExchangeRate("5.00");
$currency->setIsActive(true);
$format = new Format();
$format->setDecimalSeparator(new Choice("Period"));
$format->setThousandSeparator(new Choice("Comma"));
$format->setDecimalPlaces(new Choice("2"));
$currency->setFormat($format);
array_push($currencies, $currency);
$bodyWrapper->setCurrencies($currencies);
$response = $currenciesOperations->updateCurrency($currencyId,$bodyWrapper);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getCurrencies();
foreach($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
echo("Code: " . $successResponse->getCode()->getValue() . "\n");
echo("Details: " );
foreach($successResponse->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
}
else if($actionResponse instanceof APIException)
{
$exception = $actionResponse;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
else if($actionHandler instanceof APIException)
{
$exception = $actionHandler;
echo("Status: " . $exception->getStatus()->getValue() . "\n");
echo("Code: " . $exception->getCode()->getValue() . "\n");
if($exception->getDetails() != null)
{
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
}
}
UpdateCurrency::initialize();
$currencyId = "34770616011001";
UpdateCurrency::updateCurrency($currencyId);