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.
buying androxal buy dallas
cheap androxal american express canada
order androxal us pharmacies
16 Aug 25 at 6:32 pm
discount enclomiphene generic overnight delivery
free enclomiphene canada
va approved enclomiphene drug
16 Aug 25 at 6:43 pm
order rifaximin lowest price viagra
how to buy rifaximin price london
buying rifaximin usa sales
17 Aug 25 at 3:29 am
discount xifaxan cheap in canada
cheapest buy xifaxan generic a canada
buy cheap xifaxan canada over the counter
17 Aug 25 at 3:42 am
discount staxyn cost australia
online order staxyn buy uk no prescription
get staxyn cheap store
17 Aug 25 at 5:10 am
cheapest generic avodart
purchase avodart lowest price
online order avodart uk sales
17 Aug 25 at 5:10 am
how much is viagra over the counter [url=https://sildenapeak.shop/#]SildenaPeak[/url] SildenaPeak
RobertCat
17 Aug 25 at 5:12 am
kamagra canada sans ordonnance
kamagra l’angleterre au comptoir
acheter kamagra en ligne avec livraison express
17 Aug 25 at 8:54 am
get flexeril cyclobenzaprine generic mexico
canadian discount pharmacy flexeril cyclobenzaprine
cheapest buy flexeril cyclobenzaprine generic ireland
17 Aug 25 at 1:01 pm
online order dutasteride buy online canada
buy cheap dutasteride generic europe
cheap dutasteride buy sydney
17 Aug 25 at 1:55 pm
buy fildena online melbourne
cheap fildena buy from canada
buying fildena cheap genuine
17 Aug 25 at 3:15 pm
cheapest buy gabapentin canada fast shipping
order gabapentin prescription
gabapentin american express canada
17 Aug 25 at 3:23 pm
purchase itraconazole generic side effect
how to buy itraconazole no prescription usa
cheap itraconazole cheap wholesale
18 Aug 25 at 3:57 am
koupit kamagra online uk
generická kanadská lékárna kamagra
generická kanadská lékárna kamagra
18 Aug 25 at 9:31 am
Предлагаем качественную ветошь обтирочную в наличии на складе в Санкт-Петербурге. Хлопчатобумажная, трикотажная, цветная и белая — под любые задачи. Подходит для предприятий, автосервисов, производств и клининга. Цена — от 125 руб/кг, при заказе от 300 кг — скидки. Ветошь отобрана https://vetosh-optom.ru , без фурнитуры и загрязнений, готова к применению. Отгружаем от 10 кг, работаем с физ. и юр. лицами. Возможна доставка по СПб и Ленобласти. Оформить заказ можно через сайт или по телефону.
Timspady
19 Aug 25 at 1:13 am