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.

ajimenez

8:54 am on Aug 2, 2004 (gmt 0)

crypto

2:17 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



Hi Andeeh,

I have hosted the site on the same server that you recommended. But I'm unable to execute the TestHash.e file. I don't get any output from exec("$path/TestHash.e arg1 arg2"). Can you shed some light on this?

Thanks

andeeh

2:44 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



hi there crypto

Have you got this working on your development server? De-bugging code on a remote system is going to be tedious to say the least.

crypto

5:49 am on Aug 5, 2004 (gmt 0)

10+ Year Member



I'm actually using the compiled C module(TestHash.e) provided by HSBC. Anyway the web host has allowed SSH from a static IP. So I'm going to do some trouble shooting today.

ajimenez

9:31 am on Aug 5, 2004 (gmt 0)

10+ Year Member



have you got them to install the lib file?

crypto

9:32 am on Aug 5, 2004 (gmt 0)

10+ Year Member



I did an SSH to the server. I can execute the TestHash.e like this:

$./TestHash.e arg1 arg2

But,

$TestHash.e doesn't work. Why is that? Any ideas?

andeeh

10:04 am on Aug 5, 2004 (gmt 0)

10+ Year Member



As ajimenez says, have you got the libCcCpitools.so installed on the server? What do you mean by it doesn't work, can you be more specific?

crypto

10:13 am on Aug 5, 2004 (gmt 0)

10+ Year Member



Yes libCcCpiTools.so has been installed on the server.

When I execute,

$./TestHash.e arg1 arg2 from the command prompt,it works fine.

And when I run,

$TestHash.e arg1 arg2 I get a bad command error.
This means the OS isn't executing it or treating it as an executable. I have given execute permissions also to the file.

When I run exec("./TestHash.e arg1 arg2") through PHP I don't get any output.

Please help. This is really getting frustrating.

andeeh

10:55 am on Aug 5, 2004 (gmt 0)

10+ Year Member



the problem is the path?

You need to give php a path, there is no path for exec() to your script, so try "/path/to/my/stuff/TestHash.e"

crypto

11:03 am on Aug 5, 2004 (gmt 0)

10+ Year Member



I have tried the full path also. It doesn't work.

Since you have also hosted your site on KDA, do you give the full path? Like:

/hsphere/local/home/client-dir/

or

simply /

ajimenez

2:56 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



does your host run php in safe mode?

luigi_uk

8:20 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Does the file 'libCcCpitools.so' have to be installed in my WEB-INF/lib folder or the servers /lib folder?
Can the TestHash.e file live anywhere? Ive put mine in the cgi-bin folder.

I cant seem to execute the TestHash.e file plus it doesnt report an error.
<?
$path='/home/virtual/site66/fst/var/www/cgi-bin';
$cmd="$path/TestHash.e CPIHASHKEY $str";
$ret=exec($cmd);
$ret=split(':',$ret);
//Returns the hash
$hash=trim($ret[1]);
return $hash;
?>

I have tested whether the file exists in its path and it does.

Please help.

crypto

5:17 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Hi guys,

I finally got the TestHash.e working. The problem was that I was passing a junk encrypted key as the argument. But I wasn't getting an error message either. I had to check the exit status with the system() function to get to the root of the problem. Anyway thanx everyone for the help. First hurdle is over, now moving onto the next one :)

crypto

5:25 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Hi luigi_uk,

libCcCpiTools.so has to be put in /usr/lib on the server.

And make sure "TestHash.e" has execute permissions(chmod 755) and it has to be uploaded in binary mode(via ftp)

Also I hope you are not making the same mistake as I did that is you need to pass the actual CPIHASHKEY to TestHash.e and not any junk value.

rossriley

5:54 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Hi guys,
I'm going through this same process with HSBC. I've got as far as sending the details to the cpi servlet but every time I just get bounced back to my return page with a Cpi Code of 4 which according to their integration pack means the server gave no response.
Incidentally, nothing is getting sent to the results url either.

Has anyone come across this yet?

crypto

6:55 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Hi Rossriley,

Are you through with the generation of the Order Hash Key?
Check that there could be a problem in the generation.

rossriley

7:53 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Yes i've got the hash generation working ok.
HSBC are returning immediately to my return url with their POST which includes an order hash and the CpiResultsCode. This code is always 4
I can verify their returned order hash and it is fine, just this error code which doesn't really explain anything.

Ross

ajimenez

8:07 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Have u made sure that you're sending the timestamp in ms?

ie

$timestamp=time();
$timestamp*=1000;

rossriley

8:30 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Thanks ajimenez
That was it, i wasn't multiplying by 1000!
Was i glad to see the hsbc site!

carneddau

11:03 am on Aug 6, 2004 (gmt 0)

10+ Year Member



"Was i glad to see the hsbc site!"

:) Same here, I've never been so pleased to see a web page. It took me a few days to get the POST sending all of the correct values to the servlet. It's not helped by poor documentation and a lack of support for people approaching this using a scripting language.

crypto

6:23 am on Aug 7, 2004 (gmt 0)

10+ Year Member



Same here guys. Never felt so happy after getting a code to run :)

luigi_uk

6:39 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



Should I be able to see anything in phpinfo(); when libCcCpiTools.so is loaded?

crypto

9:38 am on Aug 9, 2004 (gmt 0)

10+ Year Member



"Should I be able to see anything in phpinfo(); when libCcCpiTools.so is loaded?"

Nope. "libCcCpiTools.so" has nothing to do with PHP. Its a C shared object.

luigi_uk

8:40 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



Im waiting for my client to send me his Hash Key, obviously this needs to be correct before I can go any further.

Just to check my process. I am calling my hash generation script from a php function within the OrderHash variable. Like this ..

<input type="hidden" name="OrderHash" value="<?php create_hash($str);?>">

Then my function is declared at the top of the page itself like this.
<?
function create_hash($str){
$path='/home/virtual/site66/fst/var/www/cgi-bin';
$cmd="$path/TestHash.e eggandchips $str";
$ret=exec($cmd);
$ret2=split(':',$ret);
//Returns the hash
$hash=trim($ret2);
return $hash;
}
?>

My string looks like this when im passing it to TestHash.e

OrderId=GBP\&TimeStamp=1092082969\& CpiReturnUrl=http://www.cpu-uk.com/confirm_process.php\& CpiDirectResultUrl=/home/virtual/site66/fst/var/www/cgi-bin/resultpost.cgi\& StorefrontId=12345678910GBP\& OrderDesc=Online purchase from www.cpu-uk.com\&PurchaseAmount=71.50\&PurchaseCurrency=826\&TransactionType=Auth\& UserId=User00000001\& Mode=T\&MerchantData=1b300dad0c100197b109058627d47251

Does this look correct?

Thanks

[1][edited by: jatar_k at 8:59 pm (utc) on Aug. 9, 2004]
[edit reason] fixed sidescroll [/edit]

crypto

10:48 am on Aug 11, 2004 (gmt 0)

10+ Year Member



I'm not sure if it works this way:
OrderId=GBP\&TimeStamp=1092082969\&
CpiReturnUrl=http://www.cpu-uk.com/confirm_process.php\&
CpiDirectResultUrl=/home/virtual/site66/fst/var/www/cgi-
bin/resultpost.cgi\& StorefrontId=12345678910GBP\&
OrderDesc=Online purchase from www.cpu-
uk.com\&PurchaseAmount=71.50\&PurchaseCurrency=826
\&TransactionType=Auth\& UserId=User00000001\&
Mode=T\&MerchantData=1b300dad0c100197b109058627d47251

But I can tell you how I passed the arguments. You need not pass them in a specific order. Only thing you have to do is pass the values in "". So the arguments in the example you gave would go like this:
"GBP" "1092082969" "https://www.cpu-
uk.com/confirm_process.php"
"https://www.cpu-uk.com/cgi-bin/resultpost.cgi"
"12345678910GBP" "Online purchase from www.cpu-uk.com" "7150" "826" "Auth" "User00000001" "T" "1b300dad0c1
00197b109058627d47251"

Some points to note here are:
1.) CpiDirectResultUrl has to be a complete web-url.
2.) Both CpiReturnUrl and CpiDirectResultUrl has to be secure ie HTTPS.
3.) PurchaseAmount=71.50 has to be in sent in pence and not pounds (ie 7150). Check the documentation regarding this.

ajimenez

11:01 am on Aug 11, 2004 (gmt 0)

10+ Year Member



It would only work for me that way as well. Note that you only have to put the value in quotes if it contains spaces.

Telumehtar

3:39 pm on Aug 12, 2004 (gmt 0)

10+ Year Member



I have written a PHP Module that simply piggybacks on the .dll (and theoretically the .so file), so I can just call the Hashing function thusly...

dl("php_hsbccpi.dll");
$hash = _hsbccpi_generate_hash($vars, $hashKey);

I haven't had a chance to test it yet though, as I am still waiting for my client to receive their Hash Key. It requires the files php_hsbccpi.dll to be installed into the php/extensions directory and the CcCpi?.dll to be installed into System32/. I've not yet tried to compile in *nix, as I don't have it here at work.

Could someone tell me what format the hashKey takes (just a character count really - are we talking a small string, or a GPG type key)? I'm trying to program as much of it as I can before the Key arrives...

Namarie!

luigi_uk

6:09 pm on Aug 12, 2004 (gmt 0)

10+ Year Member



I have now revised my passing data.

"GBP" "1092333315" "https://ensim.logicaldns.net/~admin66/confirm_process.php" "https://ensim.logicaldns.net/~admin66/returnpost.php" "UK********GBP" "Online purchase from www.cpuuk.com" "7100" "826" "Auth"
"User00000001" "T" "09426424e4c1e899873fd80b80624039"

It still doesnt generate a hash thought. Infact if I was to submit all the information to the CPI without generating a hash it goes straight to my CpiReturnUrl.

Whats going on? Please help :))

Telumehtar

9:21 am on Aug 13, 2004 (gmt 0)

10+ Year Member



Do you have your Hash key yet? If not, then presumably the call to create the Hash will simply fail.

As for the page simply returning if it doesn't have the correct data - presumably it posts back the required CpiResultsCode to your CpiReturnUrl so that you can handle the error it receives. I think it's set to simply 'return with error' if it doesn't get all the required details (ie. the orderHash). Remember to ensure that all required fields have data, and that the data is of the right format (ie. The time is time() * 1000 etc.)

Good luck!

crypto

2:28 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



luigi_uk,

It seems you are not generating the timestamp correctly.

Use this:

$TimeStamp=time()*1000;

This 92 message thread spans 4 pages: 92