Easy Currency Conversion in eCommerce Website using CurrencyLayer

If you are an eCommerce developer creating eCommerce websites or mobile apps or mobile web apps, you always have to deal with currency conversation. Specifically if you are dealing with global customers.  This has to be done properly and carefully or else it will create chaos in system. Some time Customers have to pay more than actual amount and receiver will get less money and nobody would like that. So it will be better if you use some secure and reliable API for currency conversation and CurrencyLayer is one such API.

CurrenyLayer

Adding CurrencyLayer to your eCommerce Application

It gives you free account with limited API requests. Also there are other paid plans with more API request. You can signup from here. Start using currency layer API.

Once you signup you will get an API key, which you have to pass in API requests. Now we will see some APIs of currency layer and see how we can use it.

Please note here base currency will be USD.

Getting all currency listing

To get list of all the supported currency by API. You have to make get request with following params.

http://apilayer.net/api/list?access_key=YOUR_API_KEY&format=1

Here we have specified format = 1, which will give us return data in JSON format, Here is sample output.

{
“success”:true,
“terms”:”https://currencylayer.com/terms”,
“privacy”:”https://currencylayer.com/privacy”,
“currencies”:{
“AED”:”United Arab Emirates Dirham”,
“AFN”:”Afghan Afghani”,
“ALL”:”Albanian Lek”,
“AMD”:”Armenian Dram”,
“USD”:”United States Dollar”,
“UYU”:”Uruguayan Peso”,
“UZS”:”Uzbekistan Som”,
“VND”:”Vietnamese Dong”
}
}

Getting real time conversation rate

You have to make API call with following params.

http://apilayer.net/api/live?format=1&currencies=USD&access_key=YOUR_API_KEY&currencies=GBP,EUR,

And following is sample output.
{
“success”: true,
“terms”: “https://currencylayer.com/terms”,
“privacy”: “https://currencylayer.com/privacy”,
“timestamp”: 1496300046,
“source”: “USD”,
“quotes”: {
“USDGBP”: 0.77777,
“USDEUR”: 0.889028
}
}

Here we are passing API key format and currencies as param and it will give us conversation rate for this currencies for USD

So using this API you can easily add conversation features to your eCommerce application. It will be reliable and real time so you don’t have to worry about issue in conversation. The currencylayer API is one of the easiest to use APIs I’ve ever worked with.

Leave a Reply

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