I want to develop my own web application on Vue.js and Firebase where uses can buy products or services using a payment API (paypal or stripe).
I would like to show the prices of these products in local currency of each user, but I dont figure out how to approach the problem. Perhaps using a currency conversion external API?
Please if anybody has faced this problem once I would like to know what alternatives (libraries, api, code samples…) exist to solve this on Vue.js and Firebase.
2
Answers
You will need to find the common exchange rates for the currency on the client. Re-calculating the prices in your database is inefficient. instead, you store the current trading value from a source and multiply that from your base value.
USD to RUPE is 1203% – simply multiplying the value by
1203
will render it as the correct priceThere are several sources that offer exchange rates, this could be an npm package like the following: https://www.npmjs.com/package/currency-converter
You’ll need a currency conversion package. There are multiple paid options provided by companies and there are some free tools. The link below is for a free currency conversion tool. Use this tool with the rate caching option to get real time exchange rates or to directly convert any amount from one currency to another.
https://www.npmjs.com/package/currency-converter-lt