Jump to content
Sign in to follow this  
ambience

[Contribution] Worldpay V4 Beta

Recommended Posts

Hi All,

 

I hope I've been able to resolve some of the problems experienced in the current WorldPay modules by now utilising the callback feature from Worldpay directly.

 

I can't test this live though, so I hope this contrib will spark off someone who is prepared to test it and make further refinements.

 

http://www.oscommerce.com/community/contri...utions,5/page,3


Graeme Simms.

Share this post


Link to post
Share on other sites

Thanks for your contribution.

 

Everything seems to work perfectly, redirecting to Worldpay, all relevant fields are populated, however, when Worldpay redirects back to OSC it reports that payment has been cancelled in a red bar at the top, and you are presented with the (OSC) payment screen again - effectively starting again.

 

Thanks

Graeme

Share this post


Link to post
Share on other sites

Hi,

 

Are you definitely sure that you have enabled callback on Worldpay hence NOT using the Result files as supplied in the previous module?


Graeme Simms.

Share this post


Link to post
Share on other sites

Here is why I'm pretty convinced that it should work...

 

Setup : I've setup osc on a local linux server running redhat 6.2, mysql, php, and apache. All operations of osc work perfectly via my Windows based PC where I make code changes and FTP to the local webserver.

 

According to the worldpay docs, when they send a callback to you, they use a post command. I replicated the action of this by creating a file called test.php

 

I modified my worldpay module to direct to test.php instead of the usual worldpay https address, effectively making everyone think test.php is worldpay.

 

Here is the code for test.php

 

<html>



<head><title>My First PHP Page</title>

</head>



<body bgcolor=#ffffff>

<FORM ACTION="http://192.168.1.2/catalog/checkout_process.php?osCsid=493c70c52f1d617dcf2f7049a2504ec5&shipping_selected=" METHOD="POST">



<INPUT TYPE=HIDDEN NAME="transStatus" VALUE="C">





<INPUT TYPE=SUBMIT VALUE="FAIL">



</FORM>

<br>

<FORM ACTION="http://192.168.1.2/catalog/checkout_process.php?osCsid=493c70c52f1d617dcf2f7049a2504ec5&shipping_selected=&shipping_cost=&shipping_method=" METHOD="POST">



<INPUT TYPE=HIDDEN NAME="transStatus" VALUE="Y">

<INPUT TYPE=SUBMIT VALUE="PASS">

</FORM>



</body>



</html>

 

There are two criteria. Pass or fail. One posts the transtatus Y and the other C - the only useful info osc can use in determining what happened.

 

I created the form action links manually by looking at the code produced by osc on the final confirmation screen just before the last click would take you through to worldpay - that's how I got the session id that was created for me that I am using to link back. Effectively the same thing should be happening transparently at worldpay.

 

Using this mock setup which I believe my logic is correct on, pressing PASS returns to the page saying transaction successful and processes the order as normal, while pressing FAIL returns you to the payment page with the error message.

 

Due to the design, you will always get the error message unless it picked up the Y variable of transtatus. However in the code it looks like it should be doing the opposite.

 

However, the test works so I know it will work in the real model... or have I completely lost the plot?

 

Logically, if you have the RESULTC/Y files from the previous module version in worldpays configuration, that page will redirect you back without the transtatus variable, which will generate the error because the script is currently designed that way (at least I think.) This whole PHP thing is new to me but I'm passionate about this and it's my mission in life to get this thing working since I need to use it for my upcoming store ;-)


Graeme Simms.

Share this post


Link to post
Share on other sites
Thanks for your contribution.

Worldpay redirects back to OSC it reports that payment has been cancelled in a red bar at the top, and you are presented with the (OSC) payment screen again - effectively starting again.

 

Graeme

 

I have also been looking at your contribution (Many thanks) but get the above error also. I have deleted the old result Y/C .html files and have directed the callback URL to a capture script supplied by WorldPay but still the error appears - any ideas? or has anyone else had more success than me?

 

kind regards

Share this post


Link to post
Share on other sites
I have deleted the old result Y/C .html files and have directed the callback URL to a capture script supplied by WorldPay but still the error appears - any ideas?

Hey mattpary,

 

You're right - I've been working with Scotty who has assisted me and I'm narrowing the problem down all the time. I've got another modification worth trying, but it needs testing before being released again.. I'll PM you.


Graeme Simms.

Share this post


Link to post
Share on other sites

Well, I'm afraid the whole script is pretty useless :( I can't seem to get it working in a live environment - I think my problem has mainly to do with my lack of php knowledge.

 

At this point I think the worldpay callback seems to require that your callback script contains

<WPDISPLAY ITEM=banner>

within the script... but even creating a test page as follows does not help

 

<html>



<head>



<title>Test</title>

</head>



<body bgcolor=#ffffff>

<? echo "<WPDISPLAY ITEM=banner>"; ?>

<? echo "Hello World"; ?>

<? echo $HTTP_GET_VARS[MC_banner]; ?>



<b><WPDISPLAY ITEM=banner></b>

</body>



</html>

 

The confirm/cancel screen still uses the worldpay default which means they had a problem with the above script, even when worldpay.php is modified to redirect to that script and filename. The problem is finding out where the problem is!!! ARGH *pulls out hair*

 

Can anyone more experienced confirm if I am on the right track!?

 

Does anyone have a working php callback script for worldpay, even perhaps not with OSC just so that I can see how it should work?


Graeme Simms.

Share this post


Link to post
Share on other sites

RE: <WPDISPLAY ITEM=banner>

 

I think the process is that the ResultY and C files must contain this line and if they do not, then Worldpay will insert it anyway. It has nothing to do with the callback as far as I can see. As you will now be defaulting to the Worldpay supplied ResultY & C then I dont think this is the problem.

 

Looking at your code and the problem reported, it seems to me that the issue is that the test for transStatus != 'Y' is at fault. ie. the test is either failing or being done too early. Has anyone tried the code without this test to see if it works for a successful transaction?


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites
I think the process is that the ResultY and C files must contain this line and if they do not, then Worldpay will insert it anyway.

That's what I thought! But even creating a simple test.php script (see thread above) with only the worldpay banner string in it gets completely ignored as well. I think the next step in the process is not to get it to work with oscommerce, and rather try get it working on a standard piece of arb php code.. that way we can easily rule out anything osc is doing, and at the same time get an idea of worldpay are trying to do.

Has anyone tried the code without this test to see if it works for a successful transaction.

Using the same piece of test code I wrote above, this has been tested as well and I still get no result.

 

What I'm thinking of is the following:

 

- Get the worldpay server callback setup to a test script directly, eg, in worldpay admin, make it directly http://my.server/test.php

 

- Create a standard test.php page with a few settings to display some of the strings worldpay send

 

- Create another standard php page with a test form that passes direct variables to worldpay

 

I'm hoping this rules out any variable passing errors and hopefully it should assist to debug.. I'm going to attempt this a little later and see what happens..


Graeme Simms.

Share this post


Link to post
Share on other sites

As I understand it, the problem doesnt seem to be your updating the code to new checkout but more to do with changing to using callbacks?

 

Of course you don't actually have to use php or OS - html may be simpler to use for testing.

 

I have set up a small html page for making off-line payments -

 

http://www.nowsayit.com/worldpay.html

 

THIS IS LIVE - so don't pay me!

 

You could copy this code (ie. open the page and view source but remember to change your installation id or you will be paying me!) and you can insert your variables as normal hidden fields to test out the callback problem. I can't do this myself as my store is live and I only have 1 worldpay account.

 

If you got it to work with html, then changing back into php should be easy.


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites

After a good few hours working at this, I have got the callback working to a test script (also using some of Graeme Simms code).

 

Basically, Worldpay is receiving data, processing and returning to OSc using callback. Worldpay returns the information successfully, but I cannout get the following code to work! :oops:

 

The test script is at

http://www.irishsportscorp.com/paytest/pay.php

 

Click the button - use a dummy card number 4444333322221111 and enter a name then click submit. This will return you to a page listing all the parameters returned from Worldpay.

 

<?php

$WorldPayResult='<WPDISPLAY ITEM=transStatus>';

print $WorldPayResult; // Always returns Y or C



switch($WorldPayResult) {

case 'Y':

 print 'Worldpay authorised';

 break;

case 'C':

 print 'Worldpay cancelled';

 break;

default:

 print 'not recognised'; // Always goes here! :-(

}



?>

WPDISPLAY ITEM=transStatus is returned by the Worldpay callback system - and successfully returns a Y or C (and displays it on the scrren successfully). I then want to test this to see if the transaction is Authorsied (Y) or cancelled ©.

 

If I set $Worldpay='Y' instead of $WorldPayResult='<WPDISPLAY ITEM=transStatus>'; then it works, so its obviously the result from Worldpay thats not right, but it does return a Y and displays it on the page - so my question is why cant I test on it?

 

Any ideas??

 

Thanks

Graeme

Share this post


Link to post
Share on other sites

Sorry, the code should have read:

 

<?php

$WorldPayResult="<WPDISPLAY ITEM=transStatus>";

print $WorldPayResult; // Always returns Y or C



switch($WorldPayResult) {

case 'Y':

 print 'Worldpay authorised';

 break;

case 'C':

 print 'Worldpay cancelled';

 break;

default:

 print 'not recognised'; // Always goes here! :-(

}



?>

 

If you look at the results from the done.php page you will see a Y (the result from print $WorldPayResult;

followed by "'not recognised" - the result from the switch statement.

 

Thanks

Graeme

Share this post


Link to post
Share on other sites

Ive changed to double quoted as follows

 

$WorldPayResult="<WPDISPLAY ITEM=transStatus>";

print $WorldPayResult; // Always returns Y or C



switch($WorldPayResult) {

case "Y":

 print "Worldpay authorised<br>";

 break;

case "C":

 print "Worldpay cancelled<br>";

 break;

default:

 print "not recognised - after puting double quotes<br>"; // Always goes here!

}

 

Still returns "not recognised - after puting double quotes"

 

Thanks for your help

Graeme

Share this post


Link to post
Share on other sites

Is it possible that the switch statement is assuming a logical test? ie it assumes that the 'Y' means Yes, looks for 'No' and so defaults to 'default'??

 

Try putting in an if statement:

 

$WorldPayResult="<WPDISPLAY ITEM=transStatus>";

 

if ($WorldPayResult == 'Y') {

define (WPRESULT, 'Success');

} else {

define (WPRESULT, 'Fail');

};

 

print WPRESULT;

 

switch(WPRESULT) {

case "Success":

print "Worldpay authorised<br>" ;

break ;

case "Fail":

print "Worldpay cancelled<br>" ;

break ;

default:

print "not recognised - after puting double quotes<br>" ; // Always goes here!

}


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites

Graeme

 

Does it also print 'Fail' as well or does the if statement work okay? If so, why do you need the switch statement - can you not just get rid of it?


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites

Graeme

 

Looking at this again, are you not just assigning the string "<WPDISPLAY ITEM=transStatus>" to $WorldPayResult. ie you are not assigning the value of <WPDISPLAY ITEM=transStatus>?

 

Should you not be using something like this:

 

if ($HTTP_POST_VARS['transStatus'] == 'Y') {

Your Action goes here;

}


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites

I got the answer at last - thanks for all your help - It was indeed the suggestion Ian San made, although I have also done an isset statement, ie.

 

if(isset($transStatus) && $transStatus == "Y") { // Success!

...

 

I will now integrate this with OSc, although Graeme Simms has done most of this work already. Hopefully have something ready for testing very soon.

 

Thanks again

Graeme

Share this post


Link to post
Share on other sites

I have finally made some progress on this. I have set up a demo site and would appreciate if I could get some feedback on this.

 

You can use a demo credit card number of 4444333322221111 and any expiry date as this is still in demo mode.

 

Site URL is http://www.irishsportscorp.com

 

Thanks to Graeme Simms and Ian Simpson for helping me get this far.

 

Regards

Graeme

Share this post


Link to post
Share on other sites

Brilliant - works a treat! Well done.

 

Probably you need to expand on the words displayed to incorporate WP's mandatory messages:

 

e.g.

 

Thank you, your payment has been cancelled

Merchant's Reference: {your Shop Name}

Please contact WorldPay immediately if there has been a problem making your payment.

 

etc

 

but this is a trivial issue.


Ian-san

Flawlessnet

Share this post


Link to post
Share on other sites

Looks great from the customer point of view. As was mentioned above, Worldpay do get crappy if certain information is not displayed at the end though.

 

I'm currently stuck with 2 stores running an old version of OSc that I am frightended to upgrade in case I end up with knackered payments (like the last store I upgraded). If this gets released I'll be looking forward to a bit of an upgrade frenzy!

Share this post


Link to post
Share on other sites

All,

 

The code is not in a fit state to post as a contribution, so I have posted it here: http://www.irishsportscorp.com/worldpay

 

I need help in getting the integration working properly with OSC - the worldpay part and callback all work fine.

 

Can someone please assist - there is not much to do here I dont think, then we can all have a Worldpay contribution that works with callbacks and the benefits that gives us?

 

The required Worldpay details are in fact displayed at the bottom of the callback screen. These are required by Worldpay. You can add any text or (callback) returned variables (see appendix A in the Select Junior guide) by modifying the WPCallback.php file.

 

Thanks

Graeme

graeme@conkie.net

Share this post


Link to post
Share on other sites

any news on the worldpay contrib.... i have a clietn who has already ordered worldpay merchant and i have already modded and started to customise a new snapshot.. i would hate to have to use an older snapshot to ge world pay working..

 

 

would anyone be willing to contract to ge this completed for a live site??

Share this post


Link to post
Share on other sites

After many hours at this, I have finally got a working solution. I need to do some testing and will release as a contribution in the next few of days. I need to tidy things up a bit and document.

 

Graeme

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
Sign in to follow this  

×