Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 120 additions & 147 deletions api-examples/currencies/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<body>
<div class="container">
<br/>
<a href="/conversion_check.php?code=true">Code sample</a>
<a href="./index.php?code=true">Code sample</a>
<br/>
<br/>
<form>
Expand All @@ -39,188 +39,161 @@

<div class="form-group">
<label for="action">Action</label>
<select class="form-control selector" id="action" name="action">
<option value="list" <?= $_GET['action'] == 'list' ? 'selected' : '' ?>>Currencies list</option>
<option value="find" <?= $_GET['action'] == 'find' ? 'selected' : '' ?>>Find a currency by its ID</option>
<option value="get_block" <?= $_GET['action'] == 'get_block' ? 'selected' : '' ?>>Get the latest block number by currency</option>
<option value="get_req" <?= $_GET['action'] == 'get_req' ? 'selected' : '' ?>>Get the required confirmations for each currency</option>
<option value="icon_retrieve" <?= $_GET['action'] == 'icon_retrieve' ? 'selected' : '' ?>>Retrieve the currency icon</option>
<option value="conversions" <?= $_GET['action'] == 'conversions' ? 'selected' : '' ?>>All possible currency conversions</option>
<option value="validate" <?= $_GET['action'] == 'validate' ? 'selected' : '' ?>>Validation</option>
<select class="form-control" id="action" name="action">
<option>--</option>
<option>Currencies list</option>
<option>Find a currency by its ID</option>
<option>Get the latest block number by currency</option>
<option>Get the required confirmations for each currency</option>
<option>Retrieve the currency icon</option>
<option>Retrieve the currency icon as svg</option>
<option>All possible currency conversions</option>
<option>Validation</option>
</select>
</br>

<div class="form-group" id="name_code_block" style="display: none;">
<label for="name_code">Name/code: </label>
<input type="text" class="form-control" id="name_code" name="name_code">
</div>

<div class="form-group" id="type_block" style="display: none;">
<label for="type">Type:</label>
<select class="form-control" id="type" name="type">
<option>--</option>
<option>Crypto</option>
<option>Token</option>
<option>Fiat</option>
</select>
</div>

<div class="form-group" id="capabilities_block" style="display: none;">
<label for="capability">Capabilities:</label>
<select class="form-control" id="capability" name="capability">
<option>--</option>
<option>multiSigAccounts</option>
<option>sharedAccounts</option>
<option>payments</option>
<option>singleSigAccounts</option>
</select>
</div>

<div class="form-group" id="after_block" style="display: none;">
<label for="after">After:</label>
<input type="text" class="form-control" id="after" name="after">
</div>

<div class="form-group" id="limit_block" style="display: none;">
<label for="limit">Limit:</label>
<input type="text" class="form-control" id="limit" name="limit">
</div>

<div class="form-group" id="currency_id_block" style="display: none;">
<label for="currency_id">Currency ID: <span style="color:#ff0000">*</span></label>
<input type="text" class="form-control" id="currency_id" name="currency_id">
</div>

<div class="form-group" id="address_block" style="display: none;>
<label for="address">Address: <span style="color:#ff0000">*</span></label>
<input type="text" class="form-control" id="address" name="address">
</div>

<div class="form-group form-temp">
</div>

<button type="submit" class="btn btn-default">Submit</button>
</form>
<script type="text/javascript">
const selectElement = document.getElementsByClassName("selector")[0];
var get = document.getElementById("action");
var list_elem = document.createElement('div');
list_elem.id = "list";
list_elem.innerHTML =
'<div class="form-group">' +
'<label for="q">Name/code: </label> ' +
'<input type="text" class="form-control" id="q" name="q" ' +
'value="<?= $_GET["q"] ?>"> </div>' +

'<div class="form-group">' +
'<label for="type">Type:</label>' +
'<select class="form-control type_selector" id="type" name="type">' +
'<option value="none" <?= $_GET["type"] == "none" ? "selected" : "" ?>>--</option>' +
'<option value="crypto" <?= $_GET["type"] == "crypto" ? "selected" : "" ?>>Crypto</option>' +
'<option value="token" <?= $_GET["type"] == "token" ? "selected" : "" ?>>Token</option>' +
'<option value="fiat" <?= $_GET["type"] == "fiat" ? "selected" : "" ?>>Fiat</option>' +
'</select></div>' +

'<div class="form-group">' +
'<label for="capability">Capabilities:</label>' +
'<select class="form-control capabilities_selector" id="capability" name="capability">' +
'<option value="none" <?= $_GET["capability"] == "none" ? "selected" : "" ?>>--</option>' +
'<option value="multiSigAccounts" <?= $_GET["capability"] == "multiSigAccounts" ? "selected" : "" ?>>multiSigAccounts</option>' +
'<option value="sharedAccounts" <?= $_GET["capability"] == "sharedAccounts" ? "selected" : "" ?>>sharedAccounts</option>' +
'<option value="payments" <?= $_GET["capability"] == "payments" ? "selected" : "" ?>>payments</option>' +
'<option value="singleSigAccounts" <?= $_GET["capability"] == "singleSigAccounts" ? "selected" : "" ?>>singleSigAccounts</option>' +
'</select></div>' +

'<div class="form-group">' +
'<label for="after">After:</label>' +
'<input type="text" class="form-control" id="after" name="after"' +
'value="<?= $_GET["after"] ?>"> </div>' +

'<div class="form-group"> ' +
'<label for="limit">Limit:</label> ' +
'<input type="text" class="form-control" id="limit" name="limit"' +
'value="<?= $_GET["limit"] ?>"> </div>';

var find_elem = document.createElement('div');
find_elem.id = "find";
find_elem.innerHTML =
'<div class="form-group"> ' +
'<label for="currency_id">Currency ID: <span style="color:#ff0000">*</span></label> ' +
'<input type="text" class="form-control" id="currency_id" name="currency_id"' +
'value="<?= $_GET["currency_id"] ?>"> </div> ';

var validate_elem = document.createElement('div');
validate_elem.id = "validate";
validate_elem.innerHTML =
'<div class="form-group"> ' +
'<label for="currency_id">Currency ID: <span style="color:#ff0000">*</span></label> ' +
'<input type="text" class="form-control" id="currency_id" name="currency_id"' +
'value="<?= $_GET["currency_id"] ?>"> </div>' +

'<div class="form-group"> ' +
'<label for="address">Address: <span style="color:#ff0000">*</span></label> ' +
'<input type="text" class="form-control" id="address" name="address"' +
'value="<?= $_GET["address"] ?>"> </div>';

window.onload = updateValue;

var form = document.getElementsByClassName("form-temp")[0];

selectElement.addEventListener('change', updateValue);
function updateValue(e) {
if (get.value === "list")
{
form.innerHTML = "";
form.appendChild(list_elem);
} else if (get.value === "find" || get.value === "get_block" || get.value === "icon_retrieve" )
{
form.innerHTML = "";
form.appendChild(find_elem);
} else if ( get.value === "validate"){
form.innerHTML = "";
form.appendChild(validate_elem);
} else {
form.innerHTML = "";
}
</div>
<script>
var insertEl = document.getElementById("insert");
const selectElement = document.getElementById("action");
selectElement.addEventListener("change", (event) => {
document.getElementById('name_code_block').style.display = "none";
document.getElementById('type_block').style.display = "none";
document.getElementById('capabilities_block').style.display = "none";
document.getElementById('after_block').style.display = "none";
document.getElementById('limit_block').style.display = "none";
document.getElementById('currency_id_block').style.display = "none";
document.getElementById('address_block').style.display = "none";
if (selectElement.value == 'Currencies list'){
document.getElementById('name_code_block').style.display = "block";
document.getElementById('type_block').style.display = "block";
document.getElementById('capabilities_block').style.display = "block";
document.getElementById('after_block').style.display = "block";
document.getElementById('limit_block').style.display = "block";
}
</script>
else if (selectElement.value == 'Find a currency by its ID' || selectElement.value == 'Get the latest block number by currency' ||
selectElement.value == 'Retrieve the currency icon' || selectElement.value == 'Retrieve the currency icon as svg'){
document.getElementById('currency_id_block').style.display = "block";
}
else if (selectElement.value == 'Validation'){
document.getElementById('currency_id_block').style.display = "block";
document.getElementById('address_block').style.display = "block";
}
});
</script>

<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<?php
$params = null;
$date = new \Datetime();

if (!empty($_GET['action'])) {

$apiUrl = 'https://api.coinpayments.net/api/v1/currencies';
$method = 'GET';
$params = [];
$query_builder = [];

switch ($_GET['action']) {

case 'list':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies';
$is = false;
if (!(empty($_GET['q']))) {
$apiUrl = $apiUrl . '?q=' . $_GET['q'];
$is = true;
case 'Currencies list':

if (!(empty($_GET['name_code']))) {
$query_builder['q'] = $_GET['name_code'];
}
if ($_GET['type'] !== "none") {
if ($is)
$apiUrl = $apiUrl . '&types=' . $_GET['type'];
else {
$apiUrl = $apiUrl . '?types=' . $_GET['type'];
$is = true;
}
if ($_GET['type'] !== "--") {
$query_builder['types'] = $_GET['type'];
}
if ($_GET['capability'] !== "none") {
if ($is)
$apiUrl = $apiUrl . '&capabilities=' . $_GET['capability'];
else {
$apiUrl = $apiUrl . '?capabilities=' . $_GET['capability'];
$is = true;
}
if ($_GET['capability'] !== "--") {
$query_builder['capabilities'] = $_GET['capability'];
}
if (!(empty($_GET['after']))) {
if ($is)
$apiUrl = $apiUrl . '&after=' . $_GET['after'];
else {
$apiUrl = $apiUrl . '?after=' . $_GET['after'];
$is = true;
}
$query_builder['after'] = $_GET['after'];
}
if (!(empty($_GET['limit']))) {
if ($is)
$apiUrl = $apiUrl . '&limit=' . $_GET['limit'];
else {
$apiUrl = $apiUrl . '?limit=' . $_GET['limit'];
$is = true;
}
$query_builder['limit'] = $_GET['limit'];
}
if (count($query_builder) > 0) {
$apiUrl .= '?' . http_build_query($query_builder);
}
$params = [];
break;

case 'find':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/' . $_GET['currency_id'];
$params = [];
case 'Find a currency by its ID':
$apiUrl .= '/' . $_GET['currency_id'];
break;

case 'get_block':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/blockchain-nodes/' . $_GET['currency_id'] . '/latest-block-number';
$params = [];
case 'Get the latest block number by currency':
$apiUrl .= '/' . $_GET['currency_id'] . '/latest-block-number';
break;

case 'get_req':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/required-confirmations';
$params = [];
case 'Get the required confirmations for each currency':
$apiUrl .= '/required-confirmations';
break;

case 'icon_retrieve':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/' . $_GET['currency_id'] . '/logo';
$params = [];
case 'Retrieve the currency icon':
$apiUrl .= '/' . $_GET['currency_id'] . '/logo';
break;

case 'Retrieve the currency icon as svg':
$apiUrl .= '/' . $_GET['currency_id'] . '/logosvg';
break;

case 'conversions':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/conversions';
$params = [];
$apiUrl .= '/conversions';
break;

case 'validate':
$apiUrl = 'https://api.coinpayments.net/api/v1/currencies/' . $_GET['currency_id'] . "/" . $_GET['address'] . "/validate";
$params = [];
$apiUrl .= '/' . $_GET['currency_id'] . "/" . $_GET['address'] . "/validate";
break;
}

$response = sendRequest($method, $apiUrl, $_GET['clientId'], $_GET['clientSecret'], $date, $params);

echo "<pre>";
Expand Down Expand Up @@ -289,4 +262,4 @@ function signature($method, $apiUrl, $clientId, $date, $clientSecret, $params)
]);

return base64_encode(hash_hmac('sha256', $signatureString, $clientSecret, true));
}
}