Jump to content
Philip79

Oanda failure in localization.php

Recommended Posts

It appears that Oanda has discontinued or changed the access to their currency rates as the program \admin\includes\functions\localization.php is erroring out with the URL previously that worked for years.  Anyone with any information?  This happened with XE in 2015.  Thanks.

Share this post


Link to post
Share on other sites

I believe it is not just oanda as xe is also getting errors.

 

Warning: file_get_contents(http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=USD&format=CSV&dest=Get+Table&sel_list=USD): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in  /home/XXXXXXXX/public_html/XXXXXXX/includes/functions/localization.php on line 14

Warning: file_get_contents(http://www.xe.net/ucc/convert.cgi?Amount=1&From=USD&To=USD): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in  /home/XXXXXXXX/public_html/XXXXXXX/includes/functions/localization.php on line 25


Kym

Projects Director @ ozEworks.com

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Is XE working for anyone?

 

Oanda seems to have a new converter https://www.oanda.com/currency/converter/ but they do reference their old one here https://www.oanda.com/currency/classic-converter 

 

https://www.oanda.com/convert/fxdaily redirects to https://www.oanda.com/currency/converter/

 

I read some more. https://oanda.secure.force.com/AnswersSupport?urlName=Exchange-Rates-API-FAQ-s&language=en_US

 

Looks like this is now a Paid Service via API

 

http://developer.oanda.com/exchange-rates-api/ 

Edited by FlyingKites

Kym

Projects Director @ ozEworks.com

Share this post


Link to post
Share on other sites

This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Thank you for testing @@raiwa - appreciated.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Thanks Gary. Your solution is working perfectly and is very much appreciated. 

Share this post


Link to post
Share on other sites

I been having the same problem, no currencies updating. has anyone found a solution to this problem ? Im really new to oscom. I dont understand the above "solution"

Share this post


Link to post
Share on other sites

Thank you for testing @@barnton - appreciated.

Do Google have a Currency API @@greasemonkey - I could not find one.

If youcannot handle this change @@dofi, then click this link for commercial help - which would cost you a beer most likely.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

@@burt here is some sample code that includes the address to google's API. I use this in a cron job to update automatically.

 

<code>

<?php

$from_currency = 'USD';

$to_currency = 'INR';

$amount = 1;

$results = converCurrency($from_currency,$to_currency,$amount);

$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';

preg_match($regularExpression, $results, $finalData);

echo $finalData[0];

 

function converCurrency($from,$to,$amount){

$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";

$request = curl_init();

$timeOut = 0;

curl_setopt ($request, CURLOPT_URL, $url);

curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");

curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);

$response = curl_exec($request);

curl_close($request);

return $response;

}

?><\code>

Share this post


Link to post
Share on other sites

Oh gosh no. 

 

That relies on a regex to find bld class, which is a similar thing to the problems in the USPS (or maybe UPS) addon.

That just brings so many problems to the table.

 

Avoid, like the plague.

 

I wonder why Google don't have a proper API for this?


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Thanks @@greasemonkey & burt. I had more than a few beers trying to fix this problem so will be great if I can get it done for a few bucks rather than going mad. I will put up a ticket one of the next days as the problem is more annoying than urgent. I want to give the exchange rate option for my customers. Great forum here, im sure I will be bak . thanks.

Share this post


Link to post
Share on other sites

Pretty much that is not good for relying upon as it does not give the "answer" in a clear format @@greasemonkey

It would take 10 minutes to knock up script to drop into admin to do it, but it would be so much better if Google allowed to append an output such as:

 

http://www.google.com/finance/converter?a=1&from=USD&to=GBP&outout=json

 

This would allow developers to write good code to get the result rather than this kludge;

 

$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';
 

 

to get the answer....

 

Put more simply, if Google decided to change the output to (say): 

 

 

<span class="currency">12.34</span>
 

 

the code as written would break.  Which is similar to what happens each year in the U(S)PS module...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Another option is European Central Bank daily rates in xml format http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml


Let's make things easier for new osCommerce users http://forums.oscommerce.com/topic/402638-discussion-about-hard-coded-database-tables/?p=1718900  Getting there with osCommerce 2.4! :thumbsup:

Share this post


Link to post
Share on other sites

Its a clearing localization problem. Hungarian Central Bank (MNB) is for me. There should be selectable currency info modules.


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

@@burt It is now updating all currencies just fine apart from BTC:  Error: The exchange rate for Bitcoin (BTC) was not updated via fixer. Is it a valid currency code?


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

@@frankl this fixr system gets rates from the ECB. It does take all 32 currencies...

 

@@Gergely HUF is returned by ECB, no problem? 1 EUR = 314.45 HUF

 

@@mr_absinthe BTC (aka XBT) is not (yet) a valid currency code per ISO4217...hence the ECB does not return a rate...you would need to update this manually from within admin.

Edited by burt

This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

@@burt

 

In our country we should use MNB (Hungarian Central Bank) currency exchange rates between bank account clearing. ECB exchange rates gives only informal data. Secondary options to use own bank currencies exchange rates.
There are a lot of cases depends on self bank or money markets and national accounting rules. One option is very bound. I dont mind I could use MNB for me :)


:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Share this post


Link to post
Share on other sites

Hi, I tested the following changes for the standard version as suggested by G Burton for the responsive version

of osCommerce 2.3.4, running on a Linux server with PHP Version 5.6.29, It worked! First delete
the rows marked with a minus sign, then add the rows marked with the plus signs. Please remove
the line numbers, minus signs and plus signs if any in the beginning of the rows.
Edit the file admin/includes/application_top.php
54 require(DIR_WS_INCLUDES . 'database_tables.php');
55
56 // Define how do we update currency exchange rates
57 - // Possible values are 'oanda' 'xe' or ''
58 - define('CURRENCY_SERVER_PRIMARY', 'oanda');
59 - define('CURRENCY_SERVER_BACKUP', 'xe');
57 +// Possible values are 'oanda' 'xe' 'fixer' or ''
58 +// fixer is the lastest added, more details at
59 + define('CURRENCY_SERVER_PRIMARY', 'fixer');
60 + define('CURRENCY_SERVER_BACKUP', '');
61 // include the database functions
62 require(DIR_WS_FUNCTIONS . 'database.php');
63
Edit the file admin/includes/functions/localization.php
NOTE!!!: I made a mistake when I edited this file. I put the ?> marker at the end of the file, and that
resulted in a blank screen at admin login, so don't add ?> at the end of this file!
37 return false;
38 }
39 }
40 - ?>
 
40 +
41 +
function quote_fixer_currency($to, $from = DEFAULT_CURRENCY) {
42 + if ($to == $from) return 1;
43 +
44 + $ch = curl_init('http://api.fixer.io/latest?base='. $from . '&symbols=' . $to);
45 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46 + $data = curl_exec($ch);
47 + curl_close($ch);
48 +
49 +
$currencies = json_decode($data, true);
50 +
51 + if (isset($currencies['rates'][$to])) {
52 + return $currencies['rates'][$to];
53 + } else {
54 + return false;
55 + }
56 + }
57 +
tep_not_null
Replace admin side tep_not_null with shop side function of the same name.
This solves a show-stopping bug where values less than 1.0 are seen as null
(admin side).
Edit the file admin/includes/functions/general.php
326 return false;
327 }
328 } else {
329 - if ( (is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') &&
(strlen(trim($value)) > 0)) {
329 + if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
330 return true;
331 } else {

332 return false;

 

It worked like a charm, for most currencies but not for TWD Taiwan new dollar. Why is that?

Another question: Is it time now to update to the responsive version of osCommerce?

/Bertil

Share this post


Link to post
Share on other sites

So as everyone knows this started december 2016, i've read the thread, i've updated the git changes proposed by gburton, and sure enough USD now updates, however none of the other currencies will update:

 

Heres my error:

 

success.gif The exchange rate for U.S. Dollar (USD) was updated successfully via fixer.

error.gif Error: The exchange rate for Euro (EUR) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for UK Pound (GBP) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for NZ Dollar (NZD) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for Australian Dollar (AUD) was not updated via fixer. Is it a valid currency code?

 

Please help!

Edited by stylesoft

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×