PHP code example of chibka / ccloud
1. Go to this page and download the library: Download chibka/ccloud library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chibka / ccloud example snippets
use CurrencyCloud\CurrencyCloud;
use CurrencyCloud\Session;
ION,
'<user-id>',
'<api-key>'
);
$client = CurrencyCloud::createDefault($session);
//Authenticate
$client->authenticate()
->login();
//Get available currencies
$currencies =
$client->reference()
->availableCurrencies();
echo "Supproted currencies:\n";
foreach ($currencies as $currency) {
printf(
"Currency: %s; Code: %s; Decimal places: %d\n",
$currency->getName(),
$currency->getCode(),
$currency->getDecimalPlaces()
);
}
echo "Balances:\n";
//Find balances
$balances =
$client->balances()
->find();
foreach ($balances->getBalances() as $balance) {
printf(
"Balance ID: %s; Currency: %s; Amount: %s\n",
$balance->getId(),
$balance->getCurrency(),
$balance->getAmount()
);
}
//Close session
$client->authenticate()->close();
$client->onBehalfOf('c6ece846-6df1-461d-acaa-b42a6aa74045', function (CurrencyCloud $client) {
$balances =
$client->balances()
->find();
foreach ($balances->getBalances() as $balance) {
printf(
"Balance ID: %s; Currency: %s; Amount: %s\n",
$balance->getId(),
$balance->getCurrency(),
$balance->getAmount()
);
}
});