How To: Return the customer to your site after paying with WorldPay

Stripe is generally our go-to PCI compliant payment gateway but from time to time we're asked to use alternatives such as WorldPay. For the most this is fine but redirecting the shopping from WorldPay on a successful transaction is a bit of a pain and there are a lot of people online asking about how to get WorldPay to redirect you back to their store after completing the order.

 

Showing the shopper your store's custom order confirmation page is simple enough, you need to check the "Enable the Shopper Response" checkbox in the installation settings area:

image

 

That will then go to the url your site's callback specifies and grab the content -which is great, only because the customer is actually still on the WorldPay url you'll likely end up with some ugly unformatted version of your site at best:

image

 

You can work around that by adding a simple base url in the <head> tag of your page like this:

<base href="http://yourdomainhere.com/">

The issue with this though is the url in the address bar is still WorldPay's so to work around it properly and return the customer to your website after paying on WorldPay, we'll need to modify your Ucommerce order confirmation page a touch by adding a redirect:

@if (string.IsNullOrWhiteSpace(Request.QueryString["processed"]))
{
    <meta http-equiv="refresh" content="0;[email protected]()&processed=yes" /">
}

This little snippet outputs a meta redirect tag if the url is from WorldPay (cheating by adding processed to the url) so when WorldPay output the page, you simply redirect the user to your site. Voila:

image

This is currently supported and documented by WorldPay if you're worried we've hacked around things too much: http://support.worldpay.com/support/kb/bg/paymentresponse/payment_response.html

Author

Tim

comments powered by Disqus