Forum Moderators: coopster

Message Too Old, No Replies

HSBC CPI integration with PHP

Having a lot of trouble with this...

         

vincevincevince

12:55 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I've not had experience with HSBC CPI before, and am trying to integrate a shopping cart with it.

The server is Linux/Apache, and I have coded the cart in PHP. I'm desperately hoping that someone can give me a few pointers on what to do here, especially regarding the POST statements.

vincevincevince

6:21 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're lucky - the executable segfaults on my machine, and I don't have Java installed either :( Keep posting if you solve any more problems though, I might have to go back over this!

chaskins

12:28 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Hi,

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

carneddau

10:07 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Hi,

I've got this up and running now :) Albeit after many phone calls and emails to the HSBC tech team!

You need to drop it in your path somewhere, I put it in /lib

Cheers

chaskins

1:16 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Hi Thanks for that. I can now get the c program to run but I'm getting an error message "Error generating hash!"

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

iantresman

4:34 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



Did you ever get PHP to interface with HSBC's secure epayments CPI? It's a nightmare!

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

andeeh

9:59 am on Jul 28, 2004 (gmt 0)

10+ Year Member



Hi all, I got an HSBC integration running at the end of last year with Linux/PHP. It's a real bugbear and the samples provided by HSBC are fairly poor in my view. It's not easy like worldpay. I had to re-write and re-compile the C scripts provided and then used exec() to call them from PHP. HSBC seem to have made little effort to build more helpful guides to using scripting languages with their product.

chaskins

10:22 am on Jul 28, 2004 (gmt 0)

10+ Year Member



Hi I ended up just calling 'testhash.e' and passing the required params to it. This method saved a lot of time, but is not the greatest way of implementing it.

Oh well at least it works. Any problems give me a shout and I'll see if I can help out.

Cheers

Chris

andeeh

10:45 am on Jul 28, 2004 (gmt 0)

10+ Year Member



I did get it working, just took ages. Did you get one of the dodgy cds with the corrupted libCpi library? That was a real hoot getting to the bottom of that one. I see you generated the hash using the binary provided, but did you manage to validate the return POST as well? Glad you got it working anyway :)

ajimenez

9:32 am on Jul 29, 2004 (gmt 0)

10+ Year Member



Hi,

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!

andeeh

11:48 am on Jul 29, 2004 (gmt 0)

10+ Year Member



I have changed the hash generation script a little, but I pass the parameter in a url encoded format:

$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?

This 92 message thread spans 10 pages: 92