Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Currency Update from Worldpay


64sp

Recommended Posts

I would like to canvas ideas for how to integrate the idea of Craig Smiths currency update contribution http://www.oscommerce.com/community/contri...ions,877/page,6

 

So that it works neatly for Worldpay users, using for example the Worldpay module contributed by Graeme Conkie et al

 

http://www.oscommerce.com/community/contri...ions,882/page,6

 

Firstly my problem:

The default base currency for my shop is GBP and this is the currency I price all my products in. So for example I have a product priced at ?50 and I want ultimately to receive ?50 for it. In my OSC shop I also allow payment/price viewing in USD and EURO so I have set up conversion rates in the currencies table. Say I am using 1.5 USD to 1.0 GBP so if you switch currency to USD you see my same product priced at $75. The customer then uses my worldpay module to pay in USD. But because Worldpay are using different conversion rates to me (say 1.6) then I only get ?46.88 for my product. I lost ?3.12 because my currency table was out of date.

 

I think Craig has written his contribution as a class which you can run as a routine. Worldpay update their currency rates once per day at midnight GMT http://support.worldpay.com/kb/integration.../spig12410.html

 

So essentially you need to have Craig's routine to run once per day shortly after midnight...or more often to be sure ?

 

Any ideas how best to automate this process so it runs like a cron job ?

 

Or depending upon the overhead involved, the routine could run everytime the default page is loaded so that you know the rates are up to date for each visitor ?

 

Or you replace/integrate the existing currency class with Craig's class so that everytime (and only when) a customer moves out of your base default currency to view in a different currency the rates are updated ?

 

Personally I think this last idea would be the most efficient, albeit the most difficult to code.

 

All ideas or help appreciated !! I am afraid my coding is not really up to any of the above solutions !

 

Thanks

Simon

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

I believe I read somewhere that WP only update their exchange rates once per day - but not sure on that now.

 

Live, ongoing, updates would seem to be an unnecessary overhead. Also, bear in mind that many sites do not have access to cron.

 

I guess the compromise would be to run the update each time that admin is loaded?

 

Secondly, you can force the correct payment if you do not allow alternative currencies in WP. In this case, all orders would be passed to WP in GBP and have to be paid in GBP.

 

Thirdly, a problem I had with this module is that it only allows the update of the currencies that you have registered (and paid extra for) with WP. ie. I display Yen, GBP, Dollar and Euro but can only accept payment in GBP and Yen. So Dollar and Euro probably do not get updated (actually, not sure about these - they may be allowed by default in WP - but assume it was Switzerland Francs for example)

Ian-san

Flawlessnet

Link to comment
Share on other sites

I got this to work with only minor modification.

 

1) WP only update currencies once a day at midnight so no real need for an auto update. So it can be easily added to the normal currency update in Admin.

 

2) You need to set a password for the info server in WP Admin.

 

3) You need to add this to admin/application_top.php

 

// WP Currency Update

require(DIR_WS_CLASSES . 'currency_update.php');

 

4) You need to add this to admin/currencies.php:

 

$baseCurrency = 'GBP'; // requested by you when worldpay was setup. this is the ISO country code of your trading currency

$instId = MODULE_PAYMENT_WORLDPAY_ID; // issued by worldpay

$infoPW = 'xxxxx'; // set by you in the worldpay admin area

$worldpayUrl = 'select.worldpay.com/wcc/info?op=rates&instId=' . $instId . '&infoPW=' . $infoPW;

 

$cu = new CurrencyUpdate( $worldpayUrl, $baseCurrency );

$cu->Download();

$cu->UpdateDB();

 

between the last bracket of case 'update': and tep_redirect(tep_href_link(FILENAME_CURRENCIES, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $HTTP_GET_VARS['cID']));

 

Replace the xxxxx with your info server password.

 

5) Modify function UpdateDB in class currency_update.php to:

 

function UpdateDB(){

for( $i=0; $i<count( $this->exchangeRates ); $i++ ){

$sql = 'UPDATE currencies SET value = '' . $this->exchangeRates[$i]['rate'] . '',

last_updated = '' . $this->date . ' ' . date("H:i:s") . ''

WHERE code = '' . $this->exchangeRates[$i]['destinationISOCode'] . ''';

tep_db_query( $sql );

}

 

 

and add this file to admin/includes/classes

 

 

So how does it work?

 

Firstly, it updates currencies according to the normal OS method. Then it replaces the exchange rates for the installed WP currencies with WP exchange rates. This allows you to display more currencies in OS than you have installed in WP (you cannot get exchange rates from WP for non-installed curencies so this is a bit of a comprimise).

 

At the moment, it is not general enough nor linked to the WP Admin part but this are very simple issues. Also, I would prefer that it didnt replace the GBP currency again with an exchange rate of 1 - pointless waste of resource.

 

When I have time, I will make it into a contribution. If any brave souls want to test it and feedback ....

Ian-san

Flawlessnet

Link to comment
Share on other sites

I will turn this into a contribution as soon as I find time.

 

It would be nice if the info server password was added to the basic WP module otherwise the rest of the variables can be auto-inserted into the module so it would be easy to integrate.

Ian-san

Flawlessnet

Link to comment
Share on other sites

I will make a contribution after I integrate this into my own store - maybe within 5 days. You will need to have version MS1 or better of OS and the core WP mod for it to work - otherwise you will probably have to adapt it for older versions.

Ian-san

Flawlessnet

Link to comment
Share on other sites

Hello again,

 

For some reason I wasn't automatically tracking this thread and have only just checked manually for posts....so my apologies Ian for not having commented yet on your contributions to my original post.....very rude of me....sorry !

 

I will implement as you suggest and test myself and comment later....but how you describe it is just what I was looking for.

 

Thanks a million

Simon

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

I am running CVS 2.2 snapshot from 01/04/2003, I will do what it takes to get this working

 

In that case, you should have no problem with the implementation - I will try to make it as general as possible. I am ahead of schedule with my other tasks so you may even get it tomorrow.

 

nothing sexual though
Would you prefer my swiss bank account number instead?

Ian-san

Flawlessnet

Link to comment
Share on other sites

Hello

 

I have just loaded up and tested your contribution and it all worked fine...thanks Ian for a great solution.

 

The one problem I did have is that I got the following error message from PHP:

 

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in currency_update.php on line 46

 

I have changed the allow_call_time_pass_reference flag in php.ini to On (from Off) and it got rid of the error.

 

I don't know enough about the fsockopen() function to know what the problem is. If pass-by-reference is being deprecated in future versions of PHP it may be worth solving the problem now.

 

Anyone else encounter this error....if not do you have your flag set to On or Off ?

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

I dont get this message and fsockopen is used for the normal currency update - the problem looks to be the pass-by-reference.

 

Can you try this to replace the function call?

 

$err_num = '';

$err_msg = '';

$socket = fsockopen( $host, 80, $err_num, $err_msg, 90 );

Ian-san

Flawlessnet

Link to comment
Share on other sites

Sorry to be a trifle confused here, just to clear up a point.

 

1st install version 4.0 - V1.0 from Graeme Conkie 04/08/2003

 

then update with your version Ian, 04/15/2003 replacing files as in readme.

 

I have'nt installed anything yet , just wanted to make sure the right files to install first.

 

Thanks

What goes up MUST come down

Link to comment
Share on other sites

Thanks Ian, I have amended the function call as you suggested and there is no error now.

 

However, On closer inspection the currency update is not working for me (nothing to do with the above error), I think my rates are still getting updated from oanda.

 

Just to clarify, am I correct in thinking.....

 

When you go into admin and click the update currencies button it first updates all the exchange rates from oanda, and then after this your WP currency update replaces these exchange rates with wp rates, only for those currencies you have active in wp.

 

My base currency is GBP

I have USD and EUR as additional currencies. When I click update currencies the rates update to 1.57 and 1.4535 respectively.

I think worldpays rates for today are 1.575849 and 1.4771698

 

Any ideas what the problem maybe ?

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

The WP Payment module needs to be enabled and active, the flag for curency update in this mod must be set to 1 with your password. (I will change that for the next release to True / False).

 

Try the manual method first:

 

http://select.worldpay.com/wcc/info?op=GBP...&infoPW=XXXXXXX

 

Replace with your ID and password.

 

to see what you get. I just dis a test and it was okay.

Ian-san

Flawlessnet

Link to comment
Share on other sites

Thanks again Ian,

 

In the confusion I mixed up my sort order of display field with my use wp exchange rates field, so instead of 1 (=true) to use wp rates I had 2.....which of course =sod all !!

 

Thanks for the help. As you say, next version should have a true or false radio field rather than 1 or 0, to help out morons like me !

 

Also your tip on getting the rates manually was very useful, just to establish that my instId and infoPW were correct and that it was getting the correct rates for the correct currencies. Might be worth putting that tip in the install.txt on the next version...again to help out my fellows.

 

Cheers

Simon

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

Simon

 

Yes - thanks. The benefit of making contributions like this is that you get others to do your bug testing for you!

 

I will post another version tonight to correct the bugs found so far.

Ian-san

Flawlessnet

Link to comment
Share on other sites

Hello Ian

 

I was browsing through "other" contributions and found this currency update:

 

http://www.oscommerce.com/community/contri...ions,406/page,2

 

I havn't had a look at it properly yet but it looks like a standalone file version of the currency_update.php which can be called on its own as a cron job to update currencies.

 

Made me think....might be worth building a similar standalone file which can be called by cron to do your WP currency update. It would be an optional extra for those with cron access so that they dont have to press the update button in admin once a day after midnight.

 

Just a quick thought......i'll mull it over the weekend and have a go next week.

 

Cheers

Simon

***************************************

I've been contemplating thinking about thinking

***************************************

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...