Closed aljawaid closed 1 year ago
@creecros could you please help?
I have got as far as this:
class LiveRateHelper extends Base
{
// https://www.exchangerate-api.com/docs/php-currency-api
// https://www.exchangerate-api.com/docs/free
public static function getLiveRate($application_currency, $rate_currency)
{
// Fetching JSON
//$req_url = 'https://open.er-api.com/v6/latest/USD';
$req_url = 'https://open.er-api.com/v6/latest/'.$application_currency;
$response_json = file_get_contents($req_url);
// Continuing if we got a result
if(false !== $response_json) {
// Try/catch for json_decode operation
try {
// Decoding
$response = json_decode($response_json);
// Check for success
if('success' === $response->result) {
// YOUR APPLICATION CODE HERE, e.g.
//$base_price = 1; // Your price in USD
// $EUR_price = round(($base_price * $response->conversion_rates->EUR), 2);
//$live_rate = round(($base_price * $response->conversion_rates->$rate_currency), 2);
$base_currency = $application_currency;
foreach ($response as $key => $value) {}
}
return $live_rate
}
catch(Exception $e) {
// Handle JSON parse error...
return 'Error retrieving live rate';
}
}
}
}
I don't know how to do the foreach
This is how I am calling the helper...
<?= $this->helper->liveRateHelper->getLiveRate($application_currency, $rate_currency = $this->text->e($rate['currency'])) ?>
ok so I get no errors now but the result is always ZWL and I cant figure out how to do #2 in the same function. would try a new function but there is a rate limit of 24hrs which must be avoided.
Kind of regret deeply into this but I badly need a live currency in kanboard for my daily work
its always the last currency code and rate, no matter what i try
@creecros any feedback on where i am going wrong?
Found this https://www.exchangerate-api.com/docs/free which does not require an API
currency/show.php
against each kanboard currency code the user has addedI think the last updated date might be a seperate helper