-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Free Currency Converter API requires API key now. #22461
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
Free Currency Converter API requires API key now. #22461
Conversation
Hi @Hailong. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
* @param array $currenciesTo | ||
* @return array | ||
*/ | ||
protected function _makeEmptyResponse(array $currenciesTo): array |
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.
Why?
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.
This method was originally in FixerIo.php, moved it into this base class so that it can be reused by CurrencyConverterApi. But I just see the AbstractImport class is marked by @api
annotation, so probably I can not add any new method in it. I can remove it if needed.
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.
@Hailong yep, please let this method be private as it was initially.
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.
I just reverted the changes in AbstractImport and FixerIo, but cloned makeEmptyResponse method in CurrencyConverterApi class.
@@ -12,7 +12,7 @@ class CurrencyConverterApi extends AbstractImport | |||
/** | |||
* @var string | |||
*/ | |||
const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra'; //@codingStandardsIgnoreLine | |||
const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v6/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra&apiKey={{API_KEY}}'; //@codingStandardsIgnoreLine |
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.
What happened to V3 API?
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.
Both v3 and v6 require API Key, but since the latest version is v6, I changed it to v6.
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.
Then I suppose some functionality is broken, please report steps to reproduce as an issue and mention it in description.
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.
Let me add the steps in description now.
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.
@orlangur I just added the steps to reproduce the original error in description. Thanks!
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.
@Hailong please report an issue separately in https://github.com/magento/magento2/issues and then add it here to description
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.
Done.
8164bc9
to
7baa877
Compare
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
if (empty($apiKey)) { | ||
$this->_messages[] = __('No API Key was specified or an invalid API Key was specified.'); |
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.
I don't see how it can be not empty here.
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.
If user gives an API Key from Currency Setup of backend, $apiKey would be not empty. Otherwise, it would be empty.
@@ -47,7 +47,12 @@ | |||
</group> | |||
<group id="currencyconverterapi" translate="label" sortOrder="45" showInDefault="1" showInWebsite="0" showInStore="0"> | |||
<label>Currency Converter API</label> | |||
<field id="timeout" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0"> | |||
<field id="api_key" translate="label" type="obscure" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0"> |
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.
Please add validation as this field seems to be mandatory.
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.
User may input the API key for either Fixer.io or Currency Converter API on the backend, so not mandatory seems more user friendly.
); | ||
if (empty($apiKey)) { | ||
$this->_messages[] = __('No API Key was specified or an invalid API Key was specified.'); | ||
$data[$currencyFrom] = $this->makeEmptyResponse($currenciesTo); |
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.
Returning such response is not a option, please throw some error instead.
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.
Let me see how to throw a proper error from there, and change it accordingly.
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.
@orlangur by reviewing the code again, I found setting the _messages[] array here seems a good idea. Because the caller will check the _messages[] array and report error to users. For this part I actually cloned the code from the FixerIo class.
Here is a screenshot of the warning message: https://pasteboard.co/IbuUilQ.png
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.
Thanks, good to know. Still, we should not produce an empty response.
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.
I agree with you. Let me check what kind of response is better for this case later today, and refine the code properly.
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.
@orlangur I have changed it to throw a LocalizedException
, in this way there would be a red error message shown in the UI when the key is empty. Screenshot
314c0f6
to
1cbf202
Compare
1cbf202
to
10518b7
Compare
Hi @orlangur, thank you for the review. |
✔️ QA passed |
…for-free-currency-converter-api
@magento run all tests |
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.
@ysapiga please squash all build-fixing commits into one.
1976e27
to
12f6b88
Compare
@orlangur please review. |
Hi @Hailong, thank you for your contribution! |
Description (*)
Free Currency Converter API now requires API key, this change is to add the API key setting to backend and append the key to request url.
Fixed Issues (if relevant)
#22468
Manual testing scenarios (*)
Contribution checklist (*)