Tags: , | Categories: C# Posted by RichardReddy on 3/24/2009 9:16 PM | Comments (8)

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.aspx) that sends your details to Realex and a response page (RealexResponse.aspx) 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.

Comments

webpayments.ie
webpayments.ie on 6/23/2009 3:17 AM Good comprehensive article and nice package of sample code also. Good work!
Eoin Darcy
Eoin Darcy on 7/3/2009 4:15 AM Thanks for the code and the help. I am using VB but was able to easily translate the c# code.
A big help - thanks again.

richardreddy
richardreddy on 7/3/2009 4:23 AM Thanks for the comments guys. Always cool to hear you found something on here useful ;)
Peter
Peter on 7/10/2009 10:23 AM Hi, small question. How do you handle the amount. Doesn't look like you are doing anything with it. RealEX requires no decimal points. So if someone wants to pay 100 Euro they would have to type in 10000, if they will type in 100.00 it will not get thru. I would prefer to keep it as simple as possible for the customer, so I would prefer them to enter the amount as 100.00

Thanks for the reply
richardreddy
richardreddy on 7/11/2009 4:14 AM Hi Peter,

The sample code provided is there to help you send your information to Realex. I do assume that you will do things like convert the total amount before putting it into the Amount field on the RealexRedirect.aspx page.

I usually convert the total amount to cents in the previous page so that I don't have 'code logic' on my redirect to realex page. The thinking behind doing it this way was the less code I used on the redirect page the faster the page will load and send details/user to Realex.

To convert the amount to cents take the total amount and just multiplying it by 100. There are a number of options available to you to get the value from your checkout page to this realexredirect.aspx page for sending to Realex. You could:

Postback to the RealexRedirect.aspx and pick up the value that way or
Store the value in a session and read in the session in the RealexRedirect.aspx page or
Pass it as a querystring and read in the value or
Place it in the viewstate and take the value from there.
etc.

Whichever method you choose is up to you and should be based on whatever method makes the most sense for your application.

The user doesn't need to know that this takes place as you handle this on your form postback.

I hope that makes sense. Good luck with your integration.
Manik Neelam
Manik Neelam on 7/17/2009 3:45 AM Hi Reddy,

thanking you for your RealEx Payment application code. Its very nice.

while i try to test sample credit card details i am getting the following error. could please help out from this error.

The Error is :

Please contact the merchant whose goods or services you are purchasing and give the error message below.

Error 508
Incorrect hash - check your code and the Developers Documentation.
--------------------------------------------------------------------------------

thanking you
Manikandan Neelamegam
richardreddy
richardreddy on 7/17/2009 4:00 AM Hi Manik,

You need to make sure that you enter in your MerchantId and SharedSecret values that you received from Realex in the web.config file as these are used to generate your hash key.

To be honest, because this is a public blog, you should really email support@realexpayments.com and ask them for assistance. They are really quite friendly Smile

Best of luck!

Rich
RegCure Review
RegCure Review on 2/27/2010 12:38 AM Good idea Rich, I'm a fan of business and relaxed payment option seems to open a lot of doors Smile

Add comment


(Will show your Gravatar icon)


  • Comment
  • Preview
Loading