What an effort!!!!
I eventually got HSBC CPI thang working on Centos 5.6 linux through the below guide:
Thought I would contribute some more notes that you might find helpfull:
below from: http://forums.fedoraforum.org/showthread.php?t=77772
1.) use < .bashrc > file in your home directory (instead of .bash_profile)
2.) add the following line to this file :
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ; export LD_LIBRARY_PATH
DO ONE MORE THING : also add this line to < /etc/ld.so.conf > file
run /sbin/ldconfig after /etc/ld.so.conf changing
You will need to install some more goodness to get it all running, check the errors spat out in /var/log/http for more info.
If you are using php have a good look at:
http://www.leadingedgescripts.co.uk/downloads/hsbc_php.zip
Code beast!
In the below example we are selling registrations.
Sorry the formatting on the below code has gone pear shaped, would fix it but I've got a deadline to meet.
if ($onlinepayment == 'hsbc') {
echo '';
// OrderId random number
$randombeast = substr(md5(crypt(rand(0,10))),0,20);
//TimeStamp varibale
$hippytime = time();
$hippytime = $hippytime*1000;
// OrderDesc variable setting to $_REQUEST['RegNumber']
$OrderDesc = 'Your Registation number: ';
$OrderDesc .= $_REQUEST['RegNumber'];
// PurchaseAmount variable
//if we don't have a decimal place times by 10, PurchaseAmount must be a positive integer.
$numberOfDots = substr_count($_REQUEST['Amount'], '.');
if ($numberOfDots == 0) {
$hsbcAmount = preg_replace('/\D/', '', $_REQUEST['Amount']);
$hsbcAmount = $hsbcAmount . '00';
//echo $hsbcAmount;
}
if ($numberOfDots == 1) {
$hsbcAmount = preg_replace('/\D/', '', $_REQUEST['Amount']);
//echo $hsbcAmount;
}
//Encode all form values into one MerchantData variable, this comes back from HSBC. Using 'xxxDDDxxx' string as variable separator.
$merchdatabck = 'xxxDDDxxx' . urlencode($_REQUEST['RegNumber']) . 'xxxDDDxxx' . urlencode($_REQUEST['EmailAddress']) . 'xxxDDDxxx' . urlencode($_REQUEST['TelephoneNumber']) . 'xxxDDDxxx' . urlencode($_REQUEST['Amount']) . 'xxxDDDxxx';
//echo $merchdatabck;
/*******************************
|$postdata was created seperately using the array2String function in
|the following file http://www.leadingedgescripts.co.uk/downloads/hsbc_php.zip
|most of the below code is from this file
*******************************/
$postdata = 'submitButton=Submit&CpiUrl=https%3A%2F%2Fwww.cpi.hsbc.com%2Fservlet&OrderId=' . $randombeast . '&TimeStamp=' . $hippytime . '&CpiDirectResultUrl=https%3A%2F%2Fclients.somedomain.com%2FHsbcmail.php&CpiReturnUrl=https%3A%2F%2Fclients.somedomain.com%2Fhsbcback.php&StorefrontId=UKYourMerchantNumberGBP&OrderDesc=' . $OrderDesc . '&PurchaseAmount=' . $hsbcAmount . '&PurchaseCurrency=826&TransactionType=Capture&UserId=&Mode=T&MerchantData=' . $merchdatabck . '&';
/*******************************
|Strips out all the raw text we don't want
*******************************/
function strip_text($a)
{
$i = -1;
$n = '';
$ok = 1;
while(isset($a{++$i}))
{
if($ok&&$a{$i} != '<')
{
continue;
}
elseif($a{$i} == '>')
{
$ok = 1;
$n .= '>';
continue;
}
elseif($a{$i} == '<')
{
$ok = 0;
}
if(!$ok)
{
$n .= $a{$i};
}
}
return $n;
}
/*********************************
|Open the connection to the url
*********************************/
$fp = fsockopen("clients.somedomain.com", 80);
if (!$fp)
{
echo "There was an error connecting using fsockopen()\n";
}
else
{
/***************************
|lets build our post request
|these variables may change depending on your server
***************************/
$out = "POST /cgi-bin/OrderHash.e HTTP/1.1\r\n";
$out .= "Host: www.yourwebsite.com\r\n";
//Don't modify any of this unless you need to
$out .= "Accept:text/xml,application/xml,application/zhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$out .= "Accept-Language: en\r\n";
$out .= "Accept-Encoding: gzip,deflate\r\n";
$out .= "Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$out .= "Keep-Alive: 300\r\n";
$out .= "Content-Type:application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: ". strlen($postdata) ."\r\n";
$out .= "Connection: close\r\n\r\n";
$out .= $postdata;
/*****************************
|This passes our POST headers
|to the OrderHash.e form
*****************************/
fwrite($fp, $out);
/****************************
|Here is where we get the result from OrderHash.e
|then strip out all the stuff we don't need
|This is the really clever bit
****************************/
while (!feof($fp))
{
$output = fgets($fp, 500);
$output = strip_text($output);
$output = strip_tags($output, ',
//Change the form elements from 'text' to 'hidden'
$output = str_replace('type="text"', 'type="hidden"', $output);
$output = str_replace('onSubmit="singleSubmit(this)"', '', $output);
$output = trim($output);
$persist .= $output;
}
//Remove some more stuff we don't want and change the text on the submit button.
$persist = str_replace('method="POST" >', 'method="POST" >', $persist);
$persist = str_replace('', '', $persist);
/******************************
|This echo statement should output a nice simple form
|which can be submitted directly to the HSBC
|I've hidden all the form elements so all that is visible at this stage
|is a simple submit button.
*****************************/
echo $persist;
fclose($fp);
}
echo '';
}
?>