MC_callback not redirecting when integrating WorldPay HTML redirect

2.6k Views Asked by At

I am building a script to send data to WorldPay via HTML POST. It all works great except when the payment has been processed it doesn't redirect back to the customer's site.

I have added in the return URL into the Payment Response URL in the administration system and also added the MC_callback value into the HTML form.

$call_back_url = HTTP_ROOT."/checkout_result/?order_id=".$_order->order_id;

$data = array(
"instId"      => "1009258",
"cartId"      => $_settings['shop_name']. " Order ID ".$_order->order_id,
"currency"    => "GBP",
"testMode"    => "100",
"name"        => $_order->first_name . " " .  $_order->surname,
"email"       => $_order->email,
"address1"    => $_order->billing_address_1,
"address2"    => $_order->billing_address_2,
"address3"    => $_order->billing_address_3,
"town"        => $_order->billing_town_city,
"postcode"    => $_order->billing_postcode,
"country"     => $_order->billing_country,
"tel"         => $_order->tel,
"amount"      => $_order->paid,
"desc"        => $_settings['shop_name']. " Order ID ".$_order->order_id,
"MC_callback" => $call_back_url,
);

?>

<div style="display: none;">
<form action="https://secure-test.worldpay.com/wcc/purchase" method="POST"  id="submit_worldpay" />
<?php foreach($data as $key => $value){ ?>
<input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>">
<?php } ?>
<fieldset class="submit">
<input type="submit" value="Confirm your purchase" />
</fieldset>
</form>
</div>

<script type="text/javascript">
document.getElementById('submit_worldpay').submit(); // SUBMIT FORM
</script>

I get the following message on WorldPay's site:

This was not a live transaction. No money has changed hands. Thank you, your payment was successful. Merchant's reference:My Store Order ID 823 WorldPay Transaction ID: {the number is here but I've hidden it}

1

There are 1 best solutions below

2
On

I had the same problem and here is what I did.

Firstly, understand that the callback URL is not meant for Worldpay to redirect to. It is only to perform a "server to server" call to notify the server of the status of the transaction.

Worldpay will display a page as you mentioned if you have not uploaded any resultY.html. Similarly for resultC.html. Note that these file names are case-sensitive.

I uploaded these 2 files with a simple META tag that redirects the user to my site. resultY will redirect a success page and resultC to the "Sorry Try again" page. In this redirect, you can add your original variables MC_*.

<meta http-equiv="refresh" content="0; url=<wpdisplay item=MC_callbackURL>?cartId=<wpdisplay item=MC_cartId>&Result=Y">

In the redirect, i attach the cart ID. Please note - you should not update your database based on this link. Updates to the database are performed through the server to server call from Worldpay.

That was it.