Store Currency code along with price - ruby-on-rails

I am storing a price in my database.
I figured I should store the currency as my application with need to support internationalisation.
I believe the correct way is to store the ISO 4217 currency code, such as USD for US$, AUD for AU$ and EUR for Euros ...
I have a price and a currency attribute in model... Am I doing it right?
How do convert the currency code to it Symbol version? is there a helper for this? do I need to create myself a corresponding hash?
Cheers,
Joel

You should have a look at the Money gem. Handles currency codes and has support for exchange rates and formatting.
https://github.com/RubyMoney/money

Related

Drupal8 Currency Module, How to configure in my content type and views?

I installed the Currency module in my localhost, i really in need of the currency converter dynamically.
I store the currency value in USD on my field and shown as its in my view of table format.
For Customer, view of currency drop-down will be there, if the user selects the currency the value it need to be convert from USD to AUD, AUD to NZD etc., like this.
Kindly Provide me solution whether the currency converter gets the latest exchange rate and currency value.
Need for support
If you use Coorrency - Currency Converter module ,then this is the stratergy
if you use a free service then the rates are refreshed every 30
minutes.
if you use a Premium service then the rates are refreshed every 15 minutes.

Currency of in-app billing transaction

I see that the response I get from Google Play after the user had purchased one of my in-app products contains the following information:
Description, ItemType, Json, Price, Sku, Title and Type
Price is a string that contains the currency and price. eg: "€1.17".
I would like to get the same price information in a more structured way and separately. Something like a three digit ISO code of the currency and the price in numeric format, without having to parse the string, which would have been ugly and unsafe.
Do you think that there is a way to do this?
Check price_amount_micros field.
Price in micro-units, where 1,000,000 micro-units equal one unit of
the currency. For example, if price is "€7.99", price_amount_micros is
"7990000".
More here: In-app Billing Reference

get rate with Ruby Money gem

I'm using the Ruby Money gem (For rails) for my app and i want to save the used currency rate for every order.
My base currency is USD and i give my users the option to pay in EUR, on a order save i want to record the used currency conversion rate.
I just can't find a method to get the used rate from this lib, anybody knows how to do this?
I'm also looking for best practice on this, for now i'm planning on saving the prices in order_lines in the users currency and save the used currency per line. As my original prices are in dollars i'm also saving the price in dollar per order line as reference.
Thanks in advance!
For this example bank:
# config/initializers/money.rb
dev_bank = Money::Bank::VariableExchange.new
dev_bank.add_rate("EUR", "USD", 1.35)
dev_bank.add_rate("USD", "EUR", 1/1.35)
Money.default_bank = dev_bank
you can do this:
# somewhere else in your code
Money.default_bank.get_rate('EUR', 'USD')
See more info in the documentation
It looks like you're supposed to set up exchange rates in your configuration code using the exchange bank object or the money.rb initializer, in which case you already have access to the exchange rate in your code.
If for some reason you have access only to the input and output of the exchange conversion, you should be able to calculate the exchange rate yourself.

Where can I find the names of currency sub-divisions such as cents, centimes,

This should be useful for anyone who needs to write out amounts in words in SAP.
I need to convert an amount, e.g. $100.15, into words ("One hundred dollars and fifteen cents"). For the amount, I use function module spell_amount, which gives me "one hundred" and "fifteen". The name of the currency is easily found in table TCURT. Where can I find the name of the currency subdivision?
I think there is no such table. There are already some discussions about it (e.g at SCN: Table for currency) and the conclusion is: Make your own table.
If you want to create the table, you may get the name of sub-divisions in the German Wikipedia-article for ISO 4217 (Untereinheit means sub-division) or List of circulating currencies

How to sum up different currencies in Rails app?

I am currently building a Ruby on Rails invoicing application that is multilingual and supports a range of currencies. In the dashboard view all invoices a user has produced are totalled.
Now it would be nice if a user could choose the currency for each invoice.
But how can those invoices be totalled if different currencies are used?
E.g. if these three invoices were created today:
Invoice No. 1: $1000.00
Invoice No. 2: $2000.00
Invoice No. 3: €1000.00
Total: $4333.60
----------------------
The dollar-euro exchange rate would have to be based on each invoice's date of course.
How can this be achieved in Rails and does it even make sense?
Thanks for any pointers.
The sum of of multiple invoices using different currencies is not a single number, it's a collection of numbers. If you have a 20 USD invoice, a 15 EUR invoice, and a 20 EUR invoice, the sum is "20 USD + 35 EUR".
At the time when a payment is made from a single account using a single base currency, then a conversion will be performed to determine how much will have to be paid in that currency to cover the total converted costs. Presumably, there will also be currency conversion fees added at that time.
It would be convenient if you change the currency to a single one, either euro or dollar right when the user makes an invoice. That is, you save the 'converted' value in your database. In this way you won't have to lookup for past day rates.
Eu_central_bank provides exchange rates.

Resources