Send Field to Realex Payment Gateway

armagh 14 Jun, 2011
I have a form set up for a customer to pay their account on a clients site via the Realex Payment Gateway. It has fields for Name, email address, Amount to be paid (which can be any amount) and Invoice Number. I believe that I only really need to send Realex the Amount field result but I am at a total loss for how to send them my Amount Field data.

They have a <!-- w --><a class="postlink" href="http://www.xxxx.cgi">www.xxxx.cgi</a><!-- w --> script url where the information is to be sent.

My form Field Name is "TOTAL_AMOUNT"

I"m afraid I am very unexperienced with setting up a form and I'm using Chronoforms 4 which appears to simplify things up to a point.

Would it be possible for anyone to explain this to me simply or am I better off just giving up. I have spent about 2 weeks investigating how it's done at this stage and still can't make it happen!

Thanks
GreyHead 14 Jun, 2011
Hi armagh,

And what does the CGI script require? It's impossible to help much without more information.

Any payment gateway requires some identifying info as well as the amount. Usually you can handle this with either the CURL or Redirect plug-ins.

Bob
armagh 14 Jun, 2011
Thanks GreyHead, Think this is what's needed but have no idea how to implement it. If it was a complicated job I would happily pay someone to do it for me but maybe I am just missing something simple.

//The code below is used to create the timestamp format required by Realex Payments
$timestamp = strftime("%Y%m%d%H%M%S");
mt_srand((double)microtime()*1000000);

/*

 orderid:Replace this with the order id you want to use.The order id must be unique.
 In the example below a combination of the timestamp and a random number is used.

*/

$orderid = $timestamp."-".mt_rand(1, 999);


/*
In this example these values are hardcoded. In reality you may pass 
these values from another script or take it from a database. 
*/
$curr = "GBP";

/*-----------------------------------------------
Below is the code for creating the digital signature using the MD5 algorithm provided
by PHP. you can use the SHA1 algorithm alternatively. 
*/
$tmp = "$timestamp.$merchantid.$orderid.$amount.$curr";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);

?>

</head>

<body bgcolor="#FFFFFF">

<!--
https://xxxxx/xx.cgi is the script where the hidden fields
are POSTed to.

The values are sent to Realex Payments via hidden fields in a HTML form POST.
Please look at the documentation to show all the possible hidden fields you
can send to Realex Payments.

Note:> 
The more data you send to Realex Payments the more details will be available
on our reporting tool, realControl, for the merchant to view and pull reports 
down from.

Note:>
If you POST data in hidden fields that are not a Realex hidden field that data 
will be POSTed back directly to your response script. This way you can maintain
data even when you are redirected away from your site

-->
<form action=https://xxxxx/xxxx.cgi method=post>

<input type=hidden name="MERCHANT_ID" value="<?=$merchantid?>">
<input type=hidden name="ORDER_ID" value="<?=$orderid?>">
<input type=hidden name="CURRENCY" value="<?=$curr?>">
<input type=hidden name="AMOUNT" value="<?=$amount?>">
<input type=hidden name="TIMESTAMP" value="<?=$timestamp?>">
<input type=hidden name="MD5HASH" value="<?=$md5hash?>">
<input type=hidden name="AUTO_SETTLE_FLAG" value="1">

<input type=submit value="Proceed to secure server">
</form>
GreyHead 14 Jun, 2011
Hi armagh,

Not completly straightforward but this should be OK.

Keep your existing from as it is but add a ReDirect URL to a second, new form. Use the ReDirect User action to add the amount and the unique order id to the Redirect URL.

Create a new form called say, confirm_payment.

This form needs only have a Submit button (though you might also add some text to make the user feel happy). It will need to get the value of the amount from the calling URL and then more or less replicate the code you have in the previosu post. You can add all of this in a Custom Code element:
<?php
$amount     = JRequest::getString('a', '', 'get');
$orderid    = JRequest::getString('oid', '', 'get');
$secret     = '???????';
$merchantid = '???????';
$timestamp  = strftime("%Y%m%d%H%M%S");
mt_srand((double)microtime()*1000000);
$curr       = "GBP";
/**
    Below is the code for creating the digital signature using the MD5 algorithm provided
    by PHP. you can use the SHA1 algorithm alternatively.
*/
$md5hash = md5($timestamp.$merchantid.$orderid.$amount.$curr);
$md5hash = md5($md5hash.$secret);
?>
<input type=hidden name="MERCHANT_ID" value="<?php echo $merchantid; ?>" />
<input type=hidden name="ORDER_ID" value="<?php echo $orderid; ?>" />
<input type=hidden name="CURRENCY" value="<?php echo $curr; ?>" />
<input type=hidden name="AMOUNT" value="<?php echo $amount; ?>" />
<input type=hidden name="TIMESTAMP" value="<?php echo $timestamp; ?>" />
<input type=hidden name="MD5HASH" value="<?php echo $md5hash; ?>" />
<input type=hidden name="AUTO_SETTLE_FLAG" value="1" />


Set the OnSubmit URL of this second form to https://xxxxx/xxxx.cgi

I think that should do it.

Bob
armagh 14 Jun, 2011
Hi Bob,

Thanks very very much and I certainly will buy you a few beers when I get this sorted. Think I am getting somewhere at last.

At least I have managed to add the amount and order id to the redirect URL.

Is the "amount= JRequest::getString('a', '', 'get');" the part of the code that gets the amount value from the url and if so do I need to change 'a' to my field name TOTAL-AMOUNT - If it isn't how do I get the value of the amount from the calling URL ?

Lastly where do I set the OnSubmit URL action

Sorry for sounding like a complete fool

Thanks
Columba.
armagh 17 Jun, 2011
Think I have the gist of this sorted now thanks, just one thing to overcome ..

Realex don't allow decimal points to be submitted in the currency so if someone has entered say 300.00 in the amount field the result of the JRequest::getString url sends realex 300.00 and they interpret that as 3.00

Is there a way with Chronoforms to automatically remove the decimal on submit or is it a javascript thing or am I barking up the wrong tree completely?
armagh 18 Jun, 2011
Please ignore above post as I have just worked out that removing the decimal point wouldn't work if someone entered 300 instead of 300.00 as they would then end up having £3 deducted off their card. Maybe a way of multiplying the figure by 100 would work but I'll just keep digging round the internet and I'll get there eventually. Ta for all your help.
This topic is locked and no more replies can be posted.