PHP code example of onchainpay / php-api
1. Go to this page and download the library: Download onchainpay/php-api 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/ */
onchainpay / php-api example snippets
$onChainPayApi = new OnChainPay\Api('__PUBLIC_KEY__', '__PRIVATE_KEY__');
$checkSignature = false;
try {
$checkSignature = $onChainPayApi->verifySignature();
} catch (OnChainPay\Exception $err) {
echo $err;
}
echo $checkSignature ? 'Signature correct' : 'Signature incorrect';
$avalableCurrencies = [];
try {
$avalableCurrencies = $onChainPayApi->getAvailableCurrenciesList();
} catch (OnChainPay\Exception $err) {
echo $err;
}
foreach ($avalableCurrencies as $coin) {
echo sprintf("%s (%s) = %0.2f$\n",
$coin['currency'], $coin['alias'], $coin['priceUSD']);
if($coin['networks']) {
echo "\t networks:\n";
foreach ($coin['networks'] as $network)
echo sprintf("\t\t%s (%s)\n", $network['name'], $network['alias']);
}
}
$price = $onChainPayApi->priceRate('ETH', 'USDT');
$balance = null;
try {
$balance = $onChainPayApi->account->getAdvancedBalanceInfo($balanceId);
} catch (OnChainPay\Exception $err) {
echo $err;
}
echo sprintf(
"[%s] (%s)\n\tAvalable for deposit: %s\n",
$balance['advancedBalanceId'],
$balance['currency'],
implode(', ', $balance['availableCurrenciesForDeposit'])
);
$balances = [];
try {
$balances = $onChainPayApi->account->getAdvancedBalancesList();
} catch (OnChainPay\Exception $err) {
echo $err;
}
foreach ($balances as $balance) {
echo sprintf(
"[%s] (%s)\n\tAvalable for deposit: %s\n",
$balance['advancedBalanceId'],
$balance['currency'],
implode(', ', $balance['availableCurrenciesForDeposit'])
);
}