feat: add apilayer as provider for fixer api (#127)
feat: add apilayer as provider for fixer api feat: update exchange rate when saving api key
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
session_start();
|
||||
|
||||
function update_exchange_rate($db) {
|
||||
$query = "SELECT api_key FROM fixer";
|
||||
$query = "SELECT api_key, provider FROM fixer";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($result) {
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
if ($row) {
|
||||
$apiKey = $row['api_key'];
|
||||
$provider = $row['provider'];
|
||||
|
||||
$codes = "";
|
||||
$query = "SELECT id, name, symbol, code FROM currencies";
|
||||
@@ -29,8 +30,20 @@
|
||||
$mainCurrencyCode = $row['code'];
|
||||
$mainCurrencyId = $row['main_currency'];
|
||||
|
||||
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
||||
$response = file_get_contents($api_url);
|
||||
if ($provider === 1) {
|
||||
$api_url = "https://api.apilayer.com/fixer/latest?base=EUR&symbols=" . $codes;
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => 'apikey: ' . $apiKey,
|
||||
]
|
||||
]);
|
||||
$response = file_get_contents($api_url, false, $context);
|
||||
} else {
|
||||
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
||||
$response = file_get_contents($api_url);
|
||||
}
|
||||
|
||||
$apiData = json_decode($response, true);
|
||||
|
||||
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
|
||||
@@ -125,9 +138,9 @@
|
||||
if ($result) {
|
||||
$cookieExpire = time() + (30 * 24 * 60 * 60);
|
||||
$oldLanguage = isset($_COOKIE['language']) ? $_COOKIE['language'] : "en";
|
||||
$root = str_replace('/endpoints/user', '', dirname($_SERVER['PHP_SELF']));
|
||||
$root = $root == '' ? '/' : $root;
|
||||
setcookie('language', $language, $cookieExpire, $root);
|
||||
$root = str_replace('/endpoints/user', '', dirname($_SERVER['PHP_SELF']));
|
||||
$root = $root == '' ? '/' : $root;
|
||||
setcookie('language', $language, $cookieExpire, $root);
|
||||
if ($username != $oldUsername) {
|
||||
$_SESSION['username'] = $username;
|
||||
if (isset($_COOKIE['wallos_login'])) {
|
||||
@@ -168,4 +181,4 @@
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user