-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change RubyMoney bank to currencylayer #10520
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'money/bank/currencylayer_bank' | ||
|
||
Money.locale_backend = :i18n | ||
|
||
eu_bank = EuCentralBank.new | ||
Money.default_bank = eu_bank | ||
if Rails.env.test? || Rails.env.development? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's nice, updated. |
||
eu_bank = EuCentralBank.new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, done. |
||
Money.default_bank = eu_bank | ||
else | ||
mclb = Money::Bank::CurrencylayerBank.new | ||
mclb.access_key = AppSecrets.CURRENCY_LAYER_API_KEY | ||
mclb.currencylayer = true | ||
mclb.ttl_in_seconds = 86_400 | ||
mclb.cache = proc.new do |payload| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually rubocop asked to replace |
||
key = 'money:currencylayer_bank' | ||
if payload | ||
Rails.cache.write(key, payload) | ||
else | ||
Rails.cache.read(key) | ||
end | ||
end | ||
mclb.update_rates | ||
Money.default_bank = mclb | ||
end | ||
|
||
Money.default_currency = Money::Currency.new("USD") | ||
Money.rounding_mode = BigDecimal::ROUND_HALF_UP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these keys (here in
test
and same indev
) random dummy values or are they actual access keys?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actual access keys from my test account. I understand that exposing actual access keys is risky, but I went ahead since my test account is a free account and I don't mind even if the account gets deactivated.
The reason why I added actual access key is that if I give a dummy access key, it will throw error in CI/CD.
I tried if there is any way to fix this with a dummy access key, but couldn't find any way. Can you please let me know whether you faced this problem while initializing env variables for paypal or stripe or anything similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually use access keys from testing or dummy accounts for Stripe and PayPal. Look into
.env.test
, you will see that a lot ofPAYPAL_*
variables exist. These are from "real" accounts, which means we have actual username/password to log in to PayPal dashboard. But if you do actually log in, you will see that these accounts are marked as test accounts by PayPal, and you cannot send actual, real money with them. Only sandbox money. So that's why the accounts are not real, they are only "real".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think currencylayer doesn't have a test account as it doesn't do any sensitive things. So will it make sense to create two currencylayer accounts for WCA - one for test and one for production?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, now that I think about it, I have another idea...
What would you think about using the
if Rails.env.test?
check to use theEuCentralBank
in local environments and switch on the CurrencyLayer in production only?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can introduce a flag in
EnvConfig
(fileenv_config.rb
) where developers can switch on CurrencyLayer manually if they want, for local testing and stuffThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a great idea, I've now implemented it. :-)