Currency Conversion in PHP Script
Recently I have implemented a shopping cart for a
site and integrated a payment solution with a payment gateway from one
of the popular payment service, CCAvenue. I wanted to share my experience on this project. I thought this may help you when you do similar IT projects.
We had to register our client�s account on CCAvenue as Indian e-merchant and not as Global e-merchant to start the project. The payment processing and settlement of currencies was done in Indian Rupees only. We were able to pass the amount from our shopping cart to this payment service only in Indian Rupees.
Our client�s requirement was to show the amounts of products in shopping cart purely on US Dollar. We found that transferring the account from Indian e-merchant service to Global e-merchant service will take some time and it will be consuming as well.
We couldn't wait for that and we needed an urgent solution. So we had to convert the US Dollar amount to Indian Rupees before transferring the amount of shopping cart to payment gateway.
So I wrote a PHP script on the website that queries Google for the current exchange rate. The script is given below.
The first parameter is the amount, the second one is the currency in which the amount is expressed in, and the third one is the currency in which you want to make the exchange. Since Google�s algorithms are very reliable, currencies� names can be expressed in many ways. For example, the function will work with any of �usd�, �us dollars�, �united states dollars�, and so on. If the query fails, the function will simply return false.
You can download the currency converter script from here. http://www.it-base.ro/downloads/exchange_rate.php.tar.gz.
But keep in mind that if Google changes the way currency conversion queries are displayed, this function might not work properly, or, depending on your luck, might not work at all.
Please read the Google Currency Converter Disclaimer at here. http://www.google.com/intl/en/help/currency_disclaimer.html
Please post your suggestions. If you have better ideas for currency conversion than this please share with us.
Thank you.
We had to register our client�s account on CCAvenue as Indian e-merchant and not as Global e-merchant to start the project. The payment processing and settlement of currencies was done in Indian Rupees only. We were able to pass the amount from our shopping cart to this payment service only in Indian Rupees.
Our client�s requirement was to show the amounts of products in shopping cart purely on US Dollar. We found that transferring the account from Indian e-merchant service to Global e-merchant service will take some time and it will be consuming as well.
We couldn't wait for that and we needed an urgent solution. So we had to convert the US Dollar amount to Indian Rupees before transferring the amount of shopping cart to payment gateway.
So I wrote a PHP script on the website that queries Google for the current exchange rate. The script is given below.
| Code: |
| <?php
require( '/path/to/exchange_rate.php' ); echo '100 US Dollar equals ' . exchangeRate( 100, 'inr', 'usd' ); ?> |
The first parameter is the amount, the second one is the currency in which the amount is expressed in, and the third one is the currency in which you want to make the exchange. Since Google�s algorithms are very reliable, currencies� names can be expressed in many ways. For example, the function will work with any of �usd�, �us dollars�, �united states dollars�, and so on. If the query fails, the function will simply return false.
You can download the currency converter script from here. http://www.it-base.ro/downloads/exchange_rate.php.tar.gz.
But keep in mind that if Google changes the way currency conversion queries are displayed, this function might not work properly, or, depending on your luck, might not work at all.
Please read the Google Currency Converter Disclaimer at here. http://www.google.com/intl/en/help/currency_disclaimer.html
Please post your suggestions. If you have better ideas for currency conversion than this please share with us.
Thank you.
Commentaires
Enregistrer un commentaire