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.

Comments

740 responses to “Using the Google currency converter”

  1. 139.196.177.200 Avatar

    References:

    Anabolic steroids are a synthetic version of testosterone

    References:
    https://gitea.johannes-hegele.de/cherylguillory

  2. profmustafa.com Avatar

    References:

    All hyperbolic steroids are also anabolic.

    References:
    https://nauticauruguay.com/ernesto42x5233

  3. http://36.213.200.127 Avatar

    References:

    Male muscle growth pills

    References:
    https://www.ttd.group/corneliusdagos

  4. 120.26.116.243 Avatar

    References:

    Anabolic steroid price

    References:
    http://8.138.192.83:39639/maniebni296790

  5. 81.69.57.215 Avatar

    References:

    Most powerful muscle building supplement

    References:
    https://www.findinall.com/profile/renatespann504

  6. 645123.com Avatar

    References:

    Physique hair products

    References:
    https://koonis.net/winifredher994

  7. nildigitalco.com Avatar

    References:

    Anabolic steroids guide

    References:
    https://lovcam.mydaddyonline.in/@samualk9375988

  8. 124.236.46.74 Avatar

    References:

    Injection to make muscle bigger

    References:
    https://git.rmarl.in/marlysbatchelo

  9. pure.itsabouttimetv1.com Avatar

    References:

    Can steroids help you lose weight

    References:
    http://120.48.141.82:3000/kristygwendole

  10. 39.99.238.14 Avatar

    References:

    What do steroids contain

    References:
    http://provision-sa.co.za:3000/bennycarden271

  11. 62.234.194.66 Avatar

    References:

    What anabolic steroids do

    References:
    https://datingmywish.com/@valentinamaste

  12. fmagency.co.uk Avatar

    References:

    Warrior cats medicine cat herbs

    References:
    http://110.42.101.39:13000/shaybll016610

  13. qalmsecurity.nl Avatar

    References:

    Buying steroids online reviews

    References:
    http://139.224.81.74:3355/deandrehunt909

  14. verde8.woobi.co.kr Avatar

    References:

    Anabolic androgenic steroids for sale

    References:
    http://139.224.81.74:3355/deandrehunt909

  15. https://syq.im/ Avatar

    References:

    What are steroids for

    References:
    http://81.69.221.216:3000/arnulfoc919048

  16. 월드카지노 Avatar

    I used to be suggested this blog via my cousin. I am now not certain whether this post is written via him as no one else know such distinct about my problem.

    You’re wonderful! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *