Author Topic: World Pay worldpay_notify.php order status update issues  (Read 14636 times)

derek webster

  • Jr. Member
  • **
  • Posts: 74
World Pay worldpay_notify.php order status update issues
« on: September 19, 2008, 14:31:28 pm »
Hi I've been trying to get worldpay_notify.php to updaye my order status and I've just found a solution. Hope this helps someone.

regards

derek

I used the updated version of worldpay_notify.php to suit joomla 15. but it din't work for me. the fololowing lines were wrong

Code: [Select]
    /* load the VirtueMart Language File */
    if (file_exists( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' ))
      require_once( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' );
    else
   require_once( ADMINPATH. 'languages/english.php' );

The path to the admin language file was wrong - it should be

Code: [Select]
    /* load the VirtueMart Language File */
    if (file_exists( ADMINPATH. 'languages/admin/'.$mosConfig_lang.'.php' ))
      require_once( ADMINPATH. 'languages/admin/'.$mosConfig_lang.'.php' );
    else
   require_once( ADMINPATH. 'languages/admin/english.php' );

This Seemed to fix mine anyway - Hope this Helps
So the full worldpay_notify.php should be

Code: [Select]
<?php

if (
$_POST) {
header("HTTP/1.0 200 OK");

    global 
$mosConfig_absolute_path$mosConfig_live_site$mosConfig_lang$database,
    
$mosConfig_mailfrom$mosConfig_fromname;
    
        
/*** access Joomla's configuration file ***/
        
$my_path dirname(__FILE__);
        
        if( 
file_exists($my_path."/../../../configuration.php")) {
            
$absolute_path dirname$my_path."/../../../configuration.php" );
            require_once(
$my_path."/../../../configuration.php");
        }
        elseif( 
file_exists($my_path."/../../configuration.php")){
            
$absolute_path dirname$my_path."/../../configuration.php" );
            require_once(
$my_path."/../../configuration.php");
        }
        elseif( 
file_exists($my_path."/configuration.php")){
            
$absolute_path dirname$my_path."/configuration.php" );
            require_once( 
$my_path."/configuration.php" );
        }
        else {
            die( 
"Joomla Configuration File not found!" );
        }
        
        
$absolute_path realpath$absolute_path );
        
        
// Set up the appropriate CMS framework
        
if( class_exists'jconfig' ) ) {
define'_JEXEC');
define'JPATH_BASE'$absolute_path );
define'DS'DIRECTORY_SEPARATOR );

// Load the framework
require_once ( JPATH_BASE DS 'includes' DS 'defines.php' );
require_once ( JPATH_BASE DS 'includes' DS 'framework.php' );

// create the mainframe object
$mainframe = & JFactory::getApplication'site' );

// Initialize the framework
$mainframe->initialise();

// load system plugin group
JPluginHelper::importPlugin'system' );

// trigger the onBeforeStart events
$mainframe->triggerEvent'onBeforeStart' );
$lang =& JFactory::getLanguage();
$mosConfig_lang $GLOBALS['mosConfig_lang']          = strtolower$lang->getBackwardLang() );
// Adjust the live site path
$mosConfig_live_site str_replace('/administrator/components/com_virtuemart'''JURI::base());
$mosConfig_absolute_path JPATH_BASE;
        } else {
        
define('_VALID_MOS''1');
        
require_once($mosConfig_absolute_path'/includes/joomla.php');
        
require_once($mosConfig_absolute_path'/includes/database.php');
        
$database = new database$mosConfig_host$mosConfig_user$mosConfig_password$mosConfig_db$mosConfig_dbprefix );
        
$mainframe = new mosMainFrame($database'com_virtuemart'$mosConfig_absolute_path );
        }

        
// load Joomla Language File
        
if (file_exists$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' );
        }
        elseif (
file_exists$mosConfig_absolute_path'/language/english.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/english.php' );
}
    
/*** VirtueMart part ***/        
        
require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
        include_once( 
ADMINPATH.'/compat.joomla1.5.php' );
        require_once( 
ADMINPATH'global.php' );
        require_once( 
CLASSPATH'ps_main.php' );

$sess = new ps_session();

    
/* load the VirtueMart Language File */
    
if (file_existsADMINPATH'languages/admin/'.$mosConfig_lang.'.php' ))
      require_once( 
ADMINPATH'languages/admin/'.$mosConfig_lang.'.php' );
    else
   require_once( 
ADMINPATH'languages/admin/english.php' );

    require_once( 
CLASSPATH'payment/ps_worldpay.cfg.php' );

    
/* Load the VirtueMart database class */
    
require_once( CLASSPATH'ps_database.php' );

    
/*** END VirtueMart part ***/

    /**
    Read in the post from worldpay.
    **/

    
$workstring 'cmd=_notify-validate'// Notify validate
    
$i 1;
    foreach (
$_POST as $ipnkey => $ipnval) {
        if (
get_magic_quotes_gpc())
            
// Fix issue with magic quotes
            
$ipnval stripslashes ($ipnval);
            
       if (!
eregi("^[_0-9a-z-]{1,30}$",$ipnkey)  || !strcasecmp ($ipnkey'cmd'))  { 
            
// ^ Antidote to potential variable injection and poisoning
            
unset ($ipnkey); 
            unset (
$ipnval); 
        } 
       
// Eliminate the above
        // Remove empty keys (not values)
        
if (@$ipnkey != '') { 
          
//unset ($_POST); // Destroy the original ipn post array, sniff...
          
$workstring.='&'.@$ipnkey.'='.urlencode(@$ipnval); 
        }
       echo 
"key ".$i++.": $ipnkey, value: $ipnval<br />";
    } 
// Notify string

    
$payment_status  trim(stripslashes($_POST['transStatus'])); //if $payment_status == 'Y'?
    
$order_id =  trim(stripslashes($_POST['cartId']));
    
    
$d['order_id'] = $order_id;    //this identifies the order record

    
if( $payment_status == 'Y' ){
        
$d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}
    else if( 
$payment_status == 'C' ){
        
$d['order_status'] = 'X';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}

    require_once ( 
CLASSPATH'ps_order.php' );

    
$ps_order= new ps_order;

    
$ps_order->order_status_update($d);
}

?>






derek webster

  • Jr. Member
  • **
  • Posts: 74
Re: World Pay worldpay_notify.php order status update issues
« Reply #1 on: September 19, 2008, 15:00:45 pm »
Also if this helps - I've added the code to worldpay_notify.php to trigger the order confirmation AFTER the worldpay transaction goes thru
After
Code: [Select]

    /*** VirtueMart part ***/       
        require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
        include_once( ADMINPATH.'/compat.joomla1.5.php' );
        require_once( ADMINPATH. 'global.php' );
        require_once( CLASSPATH. 'ps_main.php' );
Add
Code: [Select]
require_once ( CLASSPATH . 'ps_checkout.php' );
$ps_checkout = new ps_checkout;

Then change
Code: [Select]
    if( $payment_status == 'Y' ){
        $d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed

    }

to

Code: [Select]
    if( $payment_status == 'Y' ){
        $d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed
$ps_checkout->email_receipt($d['order_id']);
    }

this line $ps_checkout->email_receipt($d['order_id']);
triggers the confirmation email to be sent out on the Callback

Just in case you need to know how to turn off the initial pre-authorisation email - go to ps_checkout.php and make sure the following line is commented out

   // Send the e-mail confirmation messages
   $this->email_receipt($order_id);

should be
// Send the e-mail confirmation messages
// $this->email_receipt($order_id);

Anyway hope this helps

regards

derek

Penge

  • Beginner
  • *
  • Posts: 9
Re: World Pay worldpay_notify.php order status update issues
« Reply #2 on: October 10, 2008, 13:58:38 pm »
This fix worked for me, the order status is correct now but the redirect back to the website does not, any thoughts?

derek webster

  • Jr. Member
  • **
  • Posts: 74
Re: World Pay worldpay_notify.php order status update issues
« Reply #3 on: October 10, 2008, 14:09:09 pm »
as far as I know - this is a the way world pay is setup it does not offer any return url.
don't quote me but Nothing you do to virtuemart will fix this as once you've changed over to the world pay website. the order is intheir hands. They would need to implement a return URL field in their setup to enable a post back to virtuemart.


Penge

  • Beginner
  • *
  • Posts: 9
Re: World Pay worldpay_notify.php order status update issues
« Reply #4 on: October 10, 2008, 14:39:09 pm »
I'm suprised to hear that, OScommerce & WorldPay have had this redirect for years, back to a checkout sucess page. It would be nice if you could trigger the order status to take you back to the site.

derek webster

  • Jr. Member
  • **
  • Posts: 74
Re: World Pay worldpay_notify.php order status update issues
« Reply #5 on: October 10, 2008, 14:48:34 pm »
Really, wow. There must be a way to do it then. I'll investigate further as I'll need this too. I was just going to leave it on the worldpay site. I've used protx before and you put the return URL in the payment script. then you get redirected back to the virtuemart when the protx payment goes thru.

Let me know how you get on if you find a solution.

derek

derek webster

  • Jr. Member
  • **
  • Posts: 74
Re: World Pay worldpay_notify.php order status update issues
« Reply #6 on: October 10, 2008, 15:02:55 pm »
Well I just spoke with world pay and they said that I can edit the payment page (with the payment page editor) and add in a rediect on the worldpay confirmation page. this is great

Penge

  • Beginner
  • *
  • Posts: 9
Re: World Pay worldpay_notify.php order status update issues
« Reply #7 on: October 10, 2008, 15:59:27 pm »
http://worldpay.com/support/kb/mergedProjects/htmlredirect/rhtml5303.html


From Worldpay
Quote
The resong you are getting that error is that for the installation ID you are actually using, you have uploaded resultY.html and resultC.html files and they contain code for redirection. Redirection is not allowed and will fail or produce errors.

It must be somewhere else?

Penge

  • Beginner
  • *
  • Posts: 9
Re: World Pay worldpay_notify.php order status update issues
« Reply #8 on: October 10, 2008, 16:02:50 pm »
This is the redirection code for a OScommerce site in the Worldpay Payment response URL:

http://<wpdisplay item="MC_callback">

Penge

  • Beginner
  • *
  • Posts: 9

james1212

  • Beginner
  • *
  • Posts: 6
Re: World Pay worldpay_notify.php order status update issues
« Reply #10 on: December 11, 2008, 22:24:44 pm »
Derek, you are an absolute genius. I have been trying to get this to work for weeks and yours is the only post that has achieved successful results. Thank you!

openpixel

  • Beginner
  • *
  • Posts: 7
Re: World Pay worldpay_notify.php order status update issues
« Reply #11 on: October 25, 2011, 00:29:31 am »
This Seemed to fix mine anyway - Hope this Helps
So the full worldpay_notify.php should be

Code: [Select]
<?php

if (
$_POST) {
header("HTTP/1.0 200 OK");

    global 
$mosConfig_absolute_path$mosConfig_live_site$mosConfig_lang$database,
    
$mosConfig_mailfrom$mosConfig_fromname;
    
        
/*** access Joomla's configuration file ***/
        
$my_path dirname(__FILE__);
        
        if( 
file_exists($my_path."/../../../configuration.php")) {
            
$absolute_path dirname$my_path."/../../../configuration.php" );
            require_once(
$my_path."/../../../configuration.php");
        }
        elseif( 
file_exists($my_path."/../../configuration.php")){
            
$absolute_path dirname$my_path."/../../configuration.php" );
            require_once(
$my_path."/../../configuration.php");
        }
        elseif( 
file_exists($my_path."/configuration.php")){
            
$absolute_path dirname$my_path."/configuration.php" );
            require_once( 
$my_path."/configuration.php" );
        }
        else {
            die( 
"Joomla Configuration File not found!" );
        }
        
        
$absolute_path realpath$absolute_path );
        
        
// Set up the appropriate CMS framework
        
if( class_exists'jconfig' ) ) {
define'_JEXEC');
define'JPATH_BASE'$absolute_path );
define'DS'DIRECTORY_SEPARATOR );

// Load the framework
require_once ( JPATH_BASE DS 'includes' DS 'defines.php' );
require_once ( JPATH_BASE DS 'includes' DS 'framework.php' );

// create the mainframe object
$mainframe = & JFactory::getApplication'site' );

// Initialize the framework
$mainframe->initialise();

// load system plugin group
JPluginHelper::importPlugin'system' );

// trigger the onBeforeStart events
$mainframe->triggerEvent'onBeforeStart' );
$lang =& JFactory::getLanguage();
$mosConfig_lang $GLOBALS['mosConfig_lang']          = strtolower$lang->getBackwardLang() );
// Adjust the live site path
$mosConfig_live_site str_replace('/administrator/components/com_virtuemart'''JURI::base());
$mosConfig_absolute_path JPATH_BASE;
        } else {
        
define('_VALID_MOS''1');
        
require_once($mosConfig_absolute_path'/includes/joomla.php');
        
require_once($mosConfig_absolute_path'/includes/database.php');
        
$database = new database$mosConfig_host$mosConfig_user$mosConfig_password$mosConfig_db$mosConfig_dbprefix );
        
$mainframe = new mosMainFrame($database'com_virtuemart'$mosConfig_absolute_path );
        }

        
// load Joomla Language File
        
if (file_exists$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/'.$mosConfig_lang.'.php' );
        }
        elseif (
file_exists$mosConfig_absolute_path'/language/english.php' )) {
            require_once( 
$mosConfig_absolute_path'/language/english.php' );
}
    
/*** VirtueMart part ***/        
        
require_once($mosConfig_absolute_path.'/administrator/components/com_virtuemart/virtuemart.cfg.php');
        include_once( 
ADMINPATH.'/compat.joomla1.5.php' );
        require_once( 
ADMINPATH'global.php' );
        require_once( 
CLASSPATH'ps_main.php' );

$sess = new ps_session();

    
/* load the VirtueMart Language File */
    
if (file_existsADMINPATH'languages/admin/'.$mosConfig_lang.'.php' ))
      require_once( 
ADMINPATH'languages/admin/'.$mosConfig_lang.'.php' );
    else
   require_once( 
ADMINPATH'languages/admin/english.php' );

    require_once( 
CLASSPATH'payment/ps_worldpay.cfg.php' );

    
/* Load the VirtueMart database class */
    
require_once( CLASSPATH'ps_database.php' );

    
/*** END VirtueMart part ***/

    /**
    Read in the post from worldpay.
    **/

    
$workstring 'cmd=_notify-validate'// Notify validate
    
$i 1;
    foreach (
$_POST as $ipnkey => $ipnval) {
        if (
get_magic_quotes_gpc())
            
// Fix issue with magic quotes
            
$ipnval stripslashes ($ipnval);
            
       if (!
eregi("^[_0-9a-z-]{1,30}$",$ipnkey)  || !strcasecmp ($ipnkey'cmd'))  { 
            
// ^ Antidote to potential variable injection and poisoning
            
unset ($ipnkey); 
            unset (
$ipnval); 
        } 
       
// Eliminate the above
        // Remove empty keys (not values)
        
if (@$ipnkey != '') { 
          
//unset ($_POST); // Destroy the original ipn post array, sniff...
          
$workstring.='&'.@$ipnkey.'='.urlencode(@$ipnval); 
        }
       echo 
"key ".$i++.": $ipnkey, value: $ipnval<br />";
    } 
// Notify string

    
$payment_status  trim(stripslashes($_POST['transStatus'])); //if $payment_status == 'Y'?
    
$order_id =  trim(stripslashes($_POST['cartId']));
    
    
$d['order_id'] = $order_id;    //this identifies the order record

    
if( $payment_status == 'Y' ){
        
$d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}
    else if( 
$payment_status == 'C' ){
        
$d['order_status'] = 'X';  //this is the new value for the database field I think X for cancelled, C for confirmed
    
}

    require_once ( 
CLASSPATH'ps_order.php' );

    
$ps_order= new ps_order;

    
$ps_order->order_status_update($d);
}

?>


Worked a treat for me!! - Joomla 1.5 and Virtuemart 1.1.7a

Thanks Derek!

openpixel

  • Beginner
  • *
  • Posts: 7
Re: World Pay worldpay_notify.php order status update issues
« Reply #12 on: November 04, 2011, 01:43:52 am »
I wondered if i was doing something wrong?

My order status' are updating correctly, but the Payment ID from Worldpay is not being saved to the database?

Also, if in VM admin I try and set the "Payment class name" to worldpay_notify.php, I get the message "Joomla Configuration File not found!"
My Joomla config file is in the root directory.

I'm completley flummoxed >:o/

Running Joomla v1.5.22 & VirtueMart 1.1.7a stable