Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Move to new currency data API - google's has become eractic.
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Mar 22, 2018
1 parent c8685e1 commit 49537d3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gem 'devise'
gem 'font-awesome-sass', '~> 4.7.0'
gem 'geocoder'
gem 'gocardless_pro'
gem 'google_currency', git: 'https://github.com/RubyMoney/google_currency', branch: 'master'
gem 'hiredis'
gem 'httparty'
gem 'i18n-js'
Expand Down Expand Up @@ -45,6 +44,7 @@ gem 'airbrake-ruby', '1.7.1'
gem 'aws-sdk-rails'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'browser', '~> 2.0', '>= 2.0.3'
gem 'money-oxr'
gem 'compass-rails' # was using git master branch before
gem 'config'
gem 'envyable', require: 'envyable/rails-now'
Expand Down
12 changes: 3 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
GIT
remote: https://github.com/RubyMoney/google_currency
revision: fa6e8ba366c0b63f8583e7ec7675f47d8ee7c410
branch: master
specs:
google_currency (3.3.0)
money (~> 6.7)

GIT
remote: https://github.com/SumOfUs/actionkit_connector
revision: 43454681be53430f9671795bcb3a250554231acb
Expand Down Expand Up @@ -309,6 +301,8 @@ GEM
minitest (5.11.3)
money (6.9.0)
i18n (>= 0.6.4, < 0.9)
money-oxr (0.3.0)
money (~> 6.6)
msgpack (1.1.0)
multi_json (1.13.1)
multi_xml (0.6.0)
Expand Down Expand Up @@ -574,7 +568,6 @@ DEPENDENCIES
friendly_id
geocoder
gocardless_pro
google_currency!
guard-rspec
hiredis
httparty
Expand All @@ -588,6 +581,7 @@ DEPENDENCIES
magic_lamp
metamagic
money
money-oxr
newrelic_rpm
omniauth-google-oauth2
paper_trail
Expand Down
13 changes: 9 additions & 4 deletions app/lib/payment_processor/currency.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'money'
require 'money/bank/google_currency'
require 'money_oxr/bank'

module PaymentProcessor
# = PaymentProcessor::Currency
Expand All @@ -20,12 +20,17 @@ module PaymentProcessor
#
# amount = PaymentProcessor::Currency.convert(1_50, :eur)
# amount.format
# "1.12"
# "EURO 1.12"
#
class Currency
# Cache fetche conversion rates.
Money::Bank::GoogleCurrency.ttl_in_seconds = 86_400 # 24 hours
Money.default_bank = Money::Bank::GoogleCurrency.new
# API provided by https://openexchangerates.org
#
Money.default_bank = MoneyOXR::Bank.new(
app_id: Settings.oxr_app_id,
cache_path: 'tmp/oxr.json',
max_age: 86_400 # 24 hours
)

def self.convert(amount, end_currency, start_currency = 'USD')
Money.new(amount, start_currency).exchange_to(end_currency)
Expand Down
1 change: 1 addition & 0 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ twilio:
development_database: 'champaign'

member_services_secret: 'hotpotato!'
oxr_app_id: '' # get app id from https://openexchangerates.org
1 change: 1 addition & 0 deletions config/settings/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ calls:
dynamodb_mailer_table: <%= ENV['DYNAMODB_MAILER_TABLE'] %>

member_services_secret: <%= ENV['MEMBER_SERVICES_SECRET'] %>
oxr_app_id: <%= ENV['OXR_APP_ID'] %>

0 comments on commit 49537d3

Please sign in to comment.