Integrate Realex Redirect Payment option using C#

We do a lot of payment integrations these days for online stores, charity sites, etc. One provider we do a lot of payment integrations with is Realex Payments. They offer a number of payment solutions for both clients and developers to choose from. The main types of setup are called Realex Redirect or Realex Remote. Unless you absolutely have a thirst for pain I would recommend the Redirect option.

The advantages of choosing this setup are that Realex will handle all the credit card processing on their side so you don't need to worry about verifying the credit cards entered and they handle the notifications for 3Dsecure/Verified By VISA. The only downside is that, to date, the Redirect option does not allow you to do re-occurring payments. If you need that then you will be better off using the Remote option but be prepared to create all the 3Dsecure code yourself! 3D secure is not turned on by default either so make sure you ask for this option if required (I would highly recommend it to avoid costly charge backs!).

The point of this article is to talk you through how to setup the Realex Redirect option within a C# application. From doing a few quick searches online there doesn't seem to be many examples out there and Realex themselves only provide a classic ASP example.

Before you begin it is probably worth understanding the process of the Realex Redirect option. You should read their explanation of this process in the Realex RealAuth Developer Guide. This can be found in the developer area and explains everything you need to know about the flow and what is required by their system to take credit card payments from your site. You will be required to provide Realex with a styled up Template page written in HTML that they will setup on their server so the payment page looks the same as your own website. This is required because, as the name suggests, the Redirect option will take the customer from your website to Realex's servers for credit card processing and then back to your site once the card has been processed. For this example I am focusing on the pages that send your details to Realex and handle the response page from Realex.

Before you can test your new Realex pages you will need to contact Realex and get them to add the URLs of your redirect and response pages. This is required, without doing this you will not be able to test your pages.

Because there are a few elements to this setup I have included all the code as a download at the end of this article. The code itself should be very easy to follow so I have not bothered to repost the code here. Just download the file youself and you will see how straight forward it is.

In the zip files there is a Redirect page (RealexRedirect) that sends your details to Realex and a response page (RealexResponse) that will handle the call from Realex once the credit card has been processed.

On the Redirect page I have it setup to auto postback the form using JavaScript on page load in the body tag. All the form elements are generated from the code behind page. This setup is a little bit messy so if someone wants to suggest a cleaner way to auto postback an asp.net form that posts to an external URL please let me know ;)

The Response page is called by Realex after it has processed the credit card. It is important to note that this page is called WITHIN the template you provided Realex. So you don't need to worry about styles here as it will be loaded within the template page you gave them. All we worry about is handling the order depending on the value Realex provide us. A "00" means that everything worked perfectly. Anything else is an error. For simplicity I have ignored the individual errors but you can display more descriptive error messages to the end user by consulting with the Realex RealAuth Developer Guide and catching these error numbers in your code.

I have 2 very simple classes for generating the timestamp for Realex and for passing the MerchantID and Shared Secret from the web.config file to the Redirect and Response pages. These should be placed in your App_Code folder in your project.

You can download the files here: Realex Redirect Option.zip (5.74 kb)

I hope this guide helps you out. Let me know if you have any questions or queries about it.

C#
blog comments powered by Disqus

Get In Touch

Follow me online at TwitterFacebook or Flickr.

Latest Tweets