hello there,
I noticed that there are no information in Ecommerce Overview section in Google Analytics after live transactions performed via WorldPay. Being trying to find out why it happens I received a tip from Ryan:

Does checkout end on cart/checkout/complete for you? If not, then that module needs to implement the new hook_ucga_display().

Checkout ends on /cart/worldpay/complete but there is no hook_ucga_display() reference like in the uc_2checkout.module

<?php
/**
 * Implementation of hook_ucga_display().
 */
function uc_2checkout_ucga_display() {
  // Tell UC Google Analytics to display the e-commerce JS on the custom
  // order completion page for this module.
  if (arg(0) == 'cart' && arg(1) == '2checkout' && arg(2) == 'complete') {
    return TRUE;
  }
}
?>

Shell we add the following code to uc_worldpay.module?

<?php
/**
 * Implementation of hook_ucga_display().
 */
function uc_worldpay_ucga_display() {
  // Tell UC Google Analytics to display the e-commerce JS on the custom
  // order completion page for this module.
  if (arg(0) == 'cart' && arg(1) == 'worldpay' && arg(2) == 'complete') {
    return TRUE;
  }
}
?>

Comments

NecroHill’s picture

Assigned: NecroHill » Unassigned
NecroHill’s picture

I've tried this patch but it doesn't help :(

bloke_zero’s picture

sorry, was talking rubbish

NecroHill’s picture

any ideas how to make this up?

matason’s picture

Version: 6.x-1.0-beta1 » 6.x-1.0-rc1
Status: Active » Needs review
StatusFileSize
new724 bytes

I've rolled the code above into a patch (untested) which is attached, the patch is against HEAD/RC1 so please test against that and let me know if you get favourable results.

One contributing issue to this problem may be to do with the fact that RBS Worldpay calls our cart complete page and displays it whilst we're still on their server ie. as far as I can work out /cart/worldpay/complete is run anonymously.

Anyway, let's see what this patch does!

jamestombs’s picture

I currently have a custom script for Worldpay payments on Drupal 5 which we are now upgrading to Drupal 6 but will be using Ubercart for the new project as opposed to a custom module.

When I spoke to WorldPay about the javascript issue for analytics tracking, the technical team suggested adding a meta redirect on the page that took effect after 3 seconds, I said why not set it to 0 and he said that is against their rules...but anyway, a meta redirect to the cart complete page would work. Some minor changes to the cart complete function to check to see what server the user is on can determine what text to appear.

So if it is called from the Worldpay server, you can have some text saying, please wait while you are redirected to the xxx site to confirm your payment. You will also need to display the WP banner on this page, which will no longer be available when moving back to your site, so you will have to replicate this yourself, or not show it at all. After our redirect it isn't shown and from user feedback people have wondered where this has gone even though they get an email with the information.

matason’s picture

Interesting idea, have you tested this approach @jamestamr?

jamestombs’s picture

Not only tested but been in use since the changes Worldpay made.

Like I said the only problem we have had out of it is that the Worldpay banner is missing once redirected, but it can easily be recreated using the saved transaction data.

The stats from Drupal and Google Analytics aren't a complete match, missing no more than 20 transactions a month. I assume this is because the user possibly closes the browser before they are redirected or use another link on the site before the redirect takes place. A work around for this would be to have a custom page-xxx.tpl.php for the cart complete page which has the navigation stripped off.

Some transactions are counted twice, due to page refresh, so I guess a bit of work to make sure that the GA code only appears once if the page is refreshed would be enough.

matason’s picture

Status: Needs review » Needs work

I suggest we work on a patch to add this, we can make it an option in the uc_worldpay settings so users can switch in on/off.

jamestombs’s picture

Just looked through the code and can't see where the following appears (which is a requirement for the callback response):

<WPDISPLAY ITEM=banner>

Worldpay automatically does a string replacement with a table (I think) showing the transaction ID, time etc.

Before we return the page, we need to add some code to check what site we are on. If we are on WorldPay then we need to redirect back to the site, but the cart id will have been emptied at this point.

Ideally:

User completes payment -> Get a confirmation page pulled out of the site in to WorldPay which says payment accepted, please wait while you are redirected... -> After 3-5 seconds or so, the user is redirected back to the standard confirmation page.

My current system is a single purchase which uses the node NID instead of cart so it is always known and isn't removed which is where this will become complicated.

jamestombs’s picture

I have this working although it is a major change.

In uc_worldpay_form(), I add the following:

  $_SESSION['do_complete'] = TRUE;
  $_SESSION['do_review'] = TRUE;

Then in uc_worldpay_complete(), after:

drupal_set_html_head("<base href=\"$base_url/\" />\n");

I added:

drupal_set_html_head('<meta http-equiv="refresh" content="3;url='. url('/cart/checkout/complete', array('absolute' => TRUE)) .'" />');

Then I commented out the $output for trans status 'Y'.

After the switch for trans status, I got rid of the following (the add comment isn't needed as this will be done by uc_cart):

  $output .= uc_cart_complete_sale($order);
  uc_cart_empty($uc_cart_id);

  // Add a comment to let sales team know this came in through the site.
  uc_order_comment_save($order->order_id, 0, t('Order created through website.'), 'admin');

And replaced with this:

  $_SESSION['do_complete'] = TRUE;
  $_SESSION['cart_order'] = $order->id;

  $output .= '<p>'. t('Please wait while you are redirected to the XXXXX server.') .'</p>';
  $output .= '<p>'. t('If you are not automatically redirect, please <a href="'. url('cart/checkout/complete', array('absolute' => TRUE)) .'">click here</a>.') .'</p>';

The user will then get the callback page up saying "please wait..." etc then after 3 seconds the user is redirected to /cart/checkout/complete which will run the final functions that we need such as uc_cart_complete_sale() as well as show the Google Analytics code and the user will be on your site so you don't have to worry about Javascript appearing on the page.

Still need to do some more testing, but it all appears to be working properly.

One last note, like I mentioned before, the following should appear on the confirmation page:

This is automatically replaced by WorldPay with the transaction ID etc, but will only appear for 3 seconds before the user is redirected. So you would have to replicate the output on your own site, but to do so you would need to save additional data as per #919178: Store additional payment details upon successful payment.

I have got around this by creating my own table, then saving the data from $_POST when trans status = 'Y'

fonant’s picture

As I understand it, the meta redirect is needed so that the completion page is displayed from the Drupal site's domain: this means the site session cookies (and any others) are sent.

The problem is caused because WorldPay serves the Drupal confirmation page from the WorldPay domain, which means the Drupal session cookies aren't sent. The proxy also strips stuff out of the HTML of the final page, such as HTML comments, IFRAMEs, etc. which can cause other issues.

fonant’s picture

StatusFileSize
new3.65 KB
new3.65 KB

Here's my patch, based on the excellent work done by jamestamr above.

It adds a three-second redirect to the page served via WorldPay's domain, back to the standard Ubercart payment completion page. This can then add the payment details for Google Analytics and also the correct completion message based on the user's account and login status.

I've included the standard WorldPay <WPDISPLAY ITEM=banner> payment details code, and a message saying that full details will be sent by email, and that the user should wait to be redirected. I also changed the page title to "Payment Confirmed" instead of "Order complete" to encourage people to wait.

gruberroland’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

The 7.x branch already contains an HTML refresh. For 6.x there will be only bug fixes.
So this can be closed now.