Knowledgebase: Payment Modules
World pay not redirecting back to cart
Posted by Matt Hayes on 23 January 2014 08:56 PM

Version: Loaded 6.5.xx

1. Reported Issue:

 World pay fails to redirect the customer back to the cart from world pay payment page.

The issue here is with the meta refresh code on the world pay call back URL. The meta refresh tag of worldpay call back page is placed in template and the template was called only after validating (isset($_POST['M_sid']) && !empty($_POST['M_sid'])) {, which created issue in redirecting customer back to cart.

Resolution:

/wpcallback.php

CODE:

if (isset($_POST['M_sid']) && !empty($_POST['M_sid'])) {
  require ('includes/application_top.php');
  if ($_POST['transStatus'] == 'Y') {
    $pass = false;
    if (isset($_POST['M_hash']) && !empty($_POST['M_hash']) && ($_POST['M_hash'] == md5($_POST['M_sid'] . $_POST['M_cid'] . $_POST['cartId'] . $_POST['M_lang'] . number_format($_POST['amount'], 2) . MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD))) {
      $pass = true;
    }
    if (isset($_POST['callbackPW']) && ($_POST['callbackPW'] != MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD)) {
      $pass = false;
    }
    if (tep_not_null(MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD) && !isset($_POST['callbackPW'])) {
      $pass = false;
    }
    if ($pass == true) {
      include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_WPCALLBACK);     
      $order_query = tep_db_query("SELECT orders_status, currency, currency_value
                                     from " . TABLE_ORDERS . "
                                   WHERE orders_id = '" . (int)$_POST['cartId'] . "'
                                     and customers_id = '" . (int)$_POST['M_cid'] . "'");
      if (tep_db_num_rows($order_query) > 0) {
        $order = tep_db_fetch_array($order_query);
        if ($order['orders_status'] == MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID) {
          $order_status_id = (MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID);
          tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $order_status_id . "', last_modified = now() where orders_id = '" . (int)$_POST['cartId'] . "'");
          $sql_data_array = array('orders_id' => $_POST['cartId'],
                                  'orders_status_id' => $order_status_id,
                                  'date_added' => 'now()',
                                  'customer_notified' => '0',
                                  'comments' => 'WorldPay: Transaction Verified');
          tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
          if (MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE == 'True') {
            $sql_data_array = array('orders_id' => $_POST['cartId'],
                                    'orders_status_id' => $order_status_id,
                                    'date_added' => 'now()',
                                    'customer_notified' => '0',
                                    'comments' => MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_WARNING_DEMO_MODE);
            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
          }
          $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_WPCALLBACK, '', 'NONSSL'));
          $content = 'wpcallback';
          require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
        }
      }
    }
  }
  require(DIR_WS_INCLUDES . 'application_bottom.php');
}

REPLACE WITH:

 require ('includes/application_top.php');
 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_WPCALLBACK);     


if (isset($_POST['M_sid']) && !empty($_POST['M_sid'])) {
  if ($_POST['transStatus'] == 'Y') {
    $pass = false;
    if (isset($_POST['M_hash']) && !empty($_POST['M_hash']) && ($_POST['M_hash'] == md5($_POST['M_sid'] . $_POST['M_cid'] . $_POST['cartId'] . $_POST['M_lang'] . number_format($_POST['amount'], 2) . MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD))) {
      $pass = true;
    }
    if (isset($_POST['callbackPW']) && ($_POST['callbackPW'] != MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD)) {
      $pass = false;
    }
    if (tep_not_null(MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD) && !isset($_POST['callbackPW'])) {
      $pass = false;
    }
    if ($pass == true) {
      $order_query = tep_db_query("SELECT orders_status, currency, currency_value
                                     from " . TABLE_ORDERS . "
                                   WHERE orders_id = '" . (int)$_POST['cartId'] . "'
                                     and customers_id = '" . (int)$_POST['M_cid'] . "'");
      if (tep_db_num_rows($order_query) > 0) {
        $order = tep_db_fetch_array($order_query);
        if ($order['orders_status'] == MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID) {
          $order_status_id = (MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID);
          tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $order_status_id . "', last_modified = now() where orders_id = '" . (int)$_POST['cartId'] . "'");
          $sql_data_array = array('orders_id' => $_POST['cartId'],
                                  'orders_status_id' => $order_status_id,
                                  'date_added' => 'now()',
                                  'customer_notified' => '0',
                                  'comments' => 'WorldPay: Transaction Verified');
          tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
          if (MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE == 'True') {
            $sql_data_array = array('orders_id' => $_POST['cartId'],
                                    'orders_status_id' => $order_status_id,
                                    'date_added' => 'now()',
                                    'customer_notified' => '0',
                                    'comments' => MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_WARNING_DEMO_MODE);
            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
          }
          $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_WPCALLBACK, '', 'NONSSL'));
          $content = 'wpcallback';
          require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
        }
      }
    }
  }
}

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_WPCALLBACK, '', 'NONSSL'));
  $content = 'wpcallback';
  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  require(DIR_WS_INCLUDES . 'application_bottom.php');

2. Reported Issue:

The second issue of cart showing Abandoned instead of actual order total value in admin >> orders >> order listing page, The issue was with OPC (one page checkout). The module had missing check for OPC, added the below code in worldpay_junior.php file located at includes >> modules > payment folder.

Resolution:

/includes/modules/payment/worldpay_junior.php

CODE:

     if (defined('MODULE_ADDONS_ONEPAGECHECKOUT_STATUS') && MODULE_ADDONS_ONEPAGECHECKOUT_STATUS == 'True') {
          if (is_array($order_total_modules->modules)) {
            // OPC has not run the process, so do so now
            $order_total_modules->process();
          }
        }

3. Reported Issue:

Order email had missing delivery and billing address, changed the code and passed session value for customers_id in worldpay_junior.php file located at includes >> modules > payment folder.

/includes/modules/payment/worldpay_junior.php

CODE:

tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";

REPLACE WITH:

tep_address_label($_SESSION['customer_id'], $_SESSION['billto'], 0, '', "\n") . "\n\n";

CODE:

tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";

REPLACE WITH:

tep_address_label($_SESSION['customer_id'], $_SESSION['sendto'], 0, '', "\n") . "\n";

Attached updated files.



Attachments 
 
 world pay.zip (10.98 KB)
(1 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako Fusion