Using the Google currency converter
For a project I’m working, I needed to get shipping rates from the UPS API (a blog post about this will follow soon).
The problem I ran into was that the UPS API returns the shipping rates with the currency of the country where the rates for are asked, so you can’t force it to always return the rates in EUR.
One solution to convert the prices is to make a very big array with all currency rates in it. I then would maintain the array every day at 9’o clock to check if the rates weren’t changed. Right, that’s not an option.
Like you might know you can easily convert currencies by using the Google search engine. For example searching on “1 Euro to dollar” will retrieve the Euro in dollar.
Below the class I wrote to convert currencies using the Google currency converter.
sConvertorUrl, $this->fPrice, $this->sFrom, $this->sTo);
$sResponse = file_get_contents($sUrl);
if(!$sResponse) {
throw new Exception('Google currency convertor is not available at the moment');
}
$oResult = json_decode($sResponse);
if($oResult->error != '') {
throw new Exception('The following error occurred: '.$oResult->error);
}
// Isolate the price
return (float)$oResult->rhs;
}
/**
* Get, retrieve the foreign currency
*
* @param float $fPrice
* @param string $sFrom, currency code (EUR, USD,...)
* @param string $sTo, currency code (EUR, USD,...)
*/
public function get($fPrice, $sFrom, $sTo)
{
if(!is_float($fPrice)) {
throw new Exception('The price to convert should be a float, "'.gettype($fPrice). '" given while calling: '.__FUNCTION__);
}
$this->fPrice = $fPrice;
$this->sFrom = strtoupper($sFrom);
$this->sTo = strtoupper($sTo);
return $this->exec();
}
}
?>
Pretty straightforward as you see.
https://t.me/s/reiting_top10_casino/6
EdwardAdete
21 Oct 25 at 5:35 am
https://t.me/s/reiting_top10_casino/4
EdwardAdete
21 Oct 25 at 8:03 am
https://t.me/s/reiting_top10_casino/3
EdwardAdete
21 Oct 25 at 9:18 am
https://t.me/reiting_top10_casino/9
EdwardAdete
21 Oct 25 at 1:09 pm
https://t.me/s/Gaming_1xbet
EdwardAdete
22 Oct 25 at 12:47 pm
https://t.me/s/PlayCasino_1xbet
https://t.me/s/PlayCasino_1xbet
22 Oct 25 at 10:41 pm
https://t.me/s/PlayCasino_1xbet
https://t.me/s/PlayCasino_1win
22 Oct 25 at 11:08 pm
https://t.me/s/PlayCasino_1win
https://t.me/s/PlayCasino_1xbet
22 Oct 25 at 11:36 pm
https://t.me/s/PlayCasino_1win
https://t.me/s/PlayCasino_1win
23 Oct 25 at 2:51 am
https://t.me/s/ofitsialniy_1win/33/Kix
https://t.me/s/ofitsialniy_1win/33/Kix
23 Oct 25 at 6:09 pm
https://t.me/s/iw_1xbet
Bradleysaige
23 Oct 25 at 10:12 pm
https://t.me/s/ofitsialniy_1win
Bradleysaige
23 Oct 25 at 11:06 pm
https://t.me/s/Official_beefcasino
Bradleysaige
24 Oct 25 at 12:00 am
https://t.me/bs_1xbet/28
https://t.me/bs_1xbet/49
24 Oct 25 at 5:17 pm