Forum Moderators: coopster
[ukbusiness.hsbc.com...]
There is an osCommerce addon module for HSBC - you could download it and see how they implemented for ideas.
Putting together a SSL Post using SSL 3.0 and sending it to the HSBC server... so far so good...
but...
The POST must contain a hash generated by HSBC provided libraries (java and C++). This must be installed on the server and makes a hash of all order details. The problem has been for me getting this library to work.
I don't know any way of accessing functions within C libraries directly through PHP, and numerous attempts to create some form of C wrapper for the function have been met with compilation problems.
My main problem is that the source code of the library is not available, so I am unable to port it into PHP.
I haven't done this myself, but it's certainly possible:
[uk2.php.net ]
<?php
$cmd = "test1";
$path='/srv/www/htdocs';
$cmd="$path/TestHash.e HSBCHASHKEYHERE $cmd";
$ret=exec($cmd);
$ret=split(':',$ret);
//Returns the hash
$hash=trim($ret[1]);
echo $hash;
?>
Seems to work fine. Haven't tried hooking up to the HSBC system yet though.
I'm also trying to do this and can call the 'TestHash.e' from within my php script but when I run it I get:
TestHash.e: error while loading shared libraries: libCcCpiTools.so: cannot open shared object file: No such file or directory
Where do I put the 'libCcCpiTools.so' file so that it get picked up?
Thanks
Chris
I thought it was because of the data I was pushing through to it but I copied the example from the manual and still getting the error :( This is driving me crazy! :(
Do you have the email address for the tech support team, I can't find it anywhere?
Thanks
Chris
I think I have libCcCpiTools.so loaded, though I can't find any reference to it using phpinfo()... perhaps it is only loaded when required?
Can I access the library's function GenerateHash directly from PHP, and if so, do you have a PHP snippet that shows me how to do this?
Or must I go through a compiled binary such as testhash.e?
Regards,
Ian Tresman
Derby, UK
I have found this forum very helpful and am finally getting somewhere with this gateway.
I'm still a bit stuck though.
I can generate a hash using c:
function create_hash($str){
$path='/srv/www/htdocs';
$cmd="$path/TestHash.e HSBCHASHKEYHERE $str";
$ret=exec($cmd);
$ret=split(':',$ret);
//Returns the hash
$hash=trim($ret[1]);
return $hash;
}
But how do i build the $str?
Do I just implode the post?
Or do I have to put the fields in a certain order?
ie $str=$_POST['OrderID'].$_POST['TimeStamp'] etc.
Please help!
$strParam = str_replace(' ','+',$strParam);
$strParam = str_replace("&","\\&",$strParam);
only difference is that the ampersand must be escaped so it can pass to the script via exec().
I added in some different return codes throughout so that I could catch them with exec() if hash generation failed.
exec($strParam,$output,$returncode);
Not sure why you are imploding a POST, unless you are passing everything from another script in your purchase sequence. But you could do something like..
$keys = array_keys($_POST);
foreach ($keys as $key)
{
write your \&key=value stuff to a string in here
}
one other thing.. hard coding the CPI key in your php script is against the terms and conditions set by HSBC. You seem to be doing that in your exec() call?
The initial form is posted to a confirmation page. The confirmation page submits the info to hsbc.
On the confirmation page I am now generating the hash value with the following:
$fields=array('OrderId','OrderHash','TimeStamp','CpiReturnUrl',
'CpiDirectResultUrl','StorefrontId','OrderDesc','PurchaseAmount','PurchaseCurrency','TransactionType',
'UserId','Mode','MerchantData'
);
foreach($fields as $field){
$str.="$field=".$_POST[$field]."&";
}
$str=substr($str,0,-1);
$str = str_replace("&","\\&",$str);
Altho the hash values aren't matching up,,,
Is there something wrong with my string?
I also have now moved the hash key out of the web path. Thanks for noticing that.