HSBC CPI Card Payment Module

This was developed originally for a client. The original brief was to update the existing module (provided by a member on the PrestaShop forum) to work in version 1.1 of PrestaShop and tie up any loose ends, but ended up being a complete re-write almost entirely from scratch (some of the third-party code in the original was re-used).


There are instructions included in the configuration screen that should cover the main questions regarding usage. The orderHash.php code (obtained from a third party) requires that both the mhash and mcrypt modules are installed on your server; you can verify that these have been installed by using the phpinfo() php function call in a test script. If you’re unsure then you should ask your hosting company to assist you. You will also have to have an adequate SSL certificate for your server (for the return pages). From the HSBC documentation:

The CPI currently supports secure POSTs via SSL3.0 and TLS1.0 technologies (SSL2.0 is not supported).

Only a limited set of cipher suites are enabled for the two security protocols, these are outlined below:

TLS1.0

  • RC4 encryption with a 128-bit key and an MD5 MAC
  • TLS_RSA_WITH_RC4_128_MD5
  • FIPS 140-1 compliant triple DES encryption and a SHA-1 MAC
  • TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
  • Triple DES encryption with a 168-bit key and a SHA-1 MAC
  • TLS_RSA_WITH_3DES_EDE_CBC_SHA

SSL3.0

  • RC4 encryption with a 128-bit key and an MD5 MAC
  • SSL_RSA_WITH_RC4_128_MD5
  • FIPS 140-1 compliant triple DES encryption and a SHA-1 MAC
  • SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA
  • Triple DES encryption with a 168-bit key and a SHA-1 MAC
  • SSL_RSA_WITH_3DES_EDE_CBC_SHA

The module only supports the single currency for which your id and hash have been issued. It may be that a future version will allow support for multiple currencies (and by implication multiple user ids and hash keys).

ADDITION (19 May 2009) There have been a lot of questions regrading the error codes, so here’s a handy table!

HSBC Payment module error codes
Code Description
0 The transaction was approved.
1 The user cancelled the transaction.
2 The processor declined the transaction for an unknown reason.
3 The transaction was declined because of a problem with the card.
For example, an invalid card number or expiration date was specified.
4 The processor did not return a response.
5 The amount specified in the transaction was either too high or too low for the processor.
6 The specified currency is not supported by either the processor or the card.
7 The order is invalid because the order ID is a duplicate.
8 The transaction was rejected by FraudShield.
9 The transaction was placed in Review state by FraudShield (see note 1 below).
10 The transaction failed because of invalid input data.
11 The transaction failed because the CPI was configured incorrectly.
12 The transaction failed because the Storefront was configured incorrectly.
13 The connection timed out.
14 The transaction failed because the cardholder’s browser refused a cookie.
15 The customer’s browser does not support 128-bit encryption.
16 The CPI cannot communicate with the Payment Engine.

Version 1.2 (Initial Release January 2009) : HSBC CPI Payment Module v1.2

Comments

25 responses to “HSBC CPI Card Payment Module”

  1. Will avatar

    Hi is there any way i can remove the page after clicking on the hsbc icon in my payment options so it goes straight there rather than a confirmation page like pay pal does?

    May Thanks

  2. Dan avatar

    also have the same error as Jalux EU and when I change the include line I get this error instead
    Warning: Division by zero in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 2

    Warning: include(/home/belinec1/public_html/shop/classesphp�) [function.include]: failed to open stream: No such file or directory in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 2

    Warning: include() [function.include]: Failed opening ‘/home/belinec1/public_html/shop/classesphp�’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 2

    Warning: include(codes.php) [function.include]: failed to open stream: No such file or directory in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 3

    Warning: include(codes.php) [function.include]: failed to open stream: No such file or directory in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 3

    Warning: include() [function.include]: Failed opening ‘codes.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/belinec1/public_html/shop/classes/Module.php(325) : eval()’d code on line 3
    also at the payment when i click to pay by hsbc i get internal 500 error

  3. JAIME avatar
    JAIME

    Hi im having this error when i click “i confirm my order”:

    Error code: #0099: We are experiencing difficulties processing your payment, please try again later or select an alternative payment option. If you wish to contact us, then please quote the error code to help us resolve your issue promptly. You are welcome to contact our customer support team if you require further assistance.

    Any help? Thanks

  4. anand avatar

    i am using HSBC payment gatway.i am tried to implement ur download module.its shows error.can u give the details step by step through complete code

  5. Vishal avatar
    Vishal

    Hi,

    Is it possible to use this module with any payment gateway with some changes? I need a module that will work with ccavenue. I see in hsbc.php I need to change all the hsbc information with the one provided to me by ccavenue. I also need to change the error codes, processing url etc. Can anyone think of anything I might have missed out?

    Thanks very much for a great module.

    1. admin avatar

      As long as your target payment gateway uses a similar mechanism, then there should be no problem adapting it, as quite a bit of the code would be common to any card processing module.

  6. Igor avatar
    Igor

    Bonjour, est ce que le module fonctionne pour hsbc en grande bretagne ?
    Hello, is this module run with hsb uk ? (sorry for my bad english 😉 )

    Merci, thanks.

  7. admin avatar

    I’ve updated the post to include a table of the official error codes from HSBC which may help with some of the issues you may be having with the module. Enjoy!

  8. Jalux EU avatar

    Hi Admin

    I have checked the compressed file on your website and codes.php does exist.

    Anyway I still think it works, my employers are taking a long time to okay the switch to prestashop, but on my trials it goes straight to HSBC payment website with the correct amount to be paid.

    It is just the above text indicating errors appears in the back office.

    Still if it works it works right?

    (I think I have used this module before without the errors appearing, so more than likely it is an issue with something on my server).

  9. philrisk avatar

    does anyone know what error 3 means?

  10. philrisk avatar

    only problem is on the return from hsbc i get error code 8. im in test mode but does anyone know what this means?

  11. philrisk avatar

    ok my error code 10 is fixed. i changed the code you suggested which didnt work but i found that the info sent through has a max of 54 charcters so make sure your shop name isnt too long.

  12. philrisk avatar
    philrisk

    i am getting the same error but tried replacing that line of code and nothing happened. get the same error. line 170 in my file though! any suggestions?

  13. admin avatar

    It’s confusing but it isn’t a multiplication!

    $TimeStamp = time() . ‘000’;

    It’s a period, not a “star” and the zeros are enclosed in single quotes. In effect it converts the time to a string, then adds three zeros to the end of the string. This prevents it from being treated as a number, and converted into scientific notation (e.g. 4.5678E+10)

  14. Patrick avatar
    Patrick

    admin, I’ve done exactly what you wrote $TimeStamp = time()*1000; relpaced to $TimeStamp = time()*000; and now I’m getting error code #004. do you have any idea what might be the problem?
    thanks a lot

  15. admin avatar

    To Jalux EU :

    These files are included by the module and are necessary, so they are either missing, or you may need to replace the second line in hsbc.php;

    Replace: include(‘orderHash.php’);

    With: include(dirname(__FILE__).’/orderHash.php’);

    I’m not sure where the reference to codes.php comes into it – that’s not a part of this module 😉

  16. admin avatar

    For the error in post 6 – this was an issue with the order timestamp. On some servers this may end up converted to scientific notation rather than an integer (after it passes a particular value). My initial solution didn’t work out but Kenny managed to use the following replacement to line 143 in hsbc.php;

    replace : $TimeStamp = time()*1000;

    with: $TimeStamp = time() . “000”;

    I had meant to update the archive with this fix but it has slipped my mind. I’ll hopefully get it done shortly!

  17. Patrick avatar
    Patrick

    I’m getting the same error code. Any solutions so far?

  18. Jalux EU avatar

    Hi

    I have some warnings appear when I have tried to install this module these are:

    Warning: include(orderHash.php) [function.include]: failed to open stream: No such file or directory in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 2

    Warning: include(orderHash.php) [function.include]: failed to open stream: No such file or directory in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 2

    Warning: include() [function.include]: Failed opening ‘orderHash.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 2

    Warning: include(codes.php) [function.include]: failed to open stream: No such file or directory in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 3

    Warning: include(codes.php) [function.include]: failed to open stream: No such file or directory in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 3

    Warning: include() [function.include]: Failed opening ‘codes.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/japanes3/public_html/mise/classes/Module.php(318) : eval()’d code on line 3

    Apart from the above I think it working fine I just wonder if there is anything I should be doing as a previous install did not have these warnings I believe.

    Anyway after checking many options this is the only HSBC module that seems to work for me and therefore I am locked now into prestashop – oh well I guess it works.

  19. Kenny avatar
    Kenny

    Help! Has something changed with HSBC, I am getting this error:-

    Error code: #0010: We are experiencing difficulties processing your payment, please try again later or select an alternative payment option. If you wish to contact us, then please quote the error code to help us resolve your issue promptly. You are welcome to contact our customer support team if you require further assistance.

    It’s weird because it was fine before.
    Any clues?
    Thanks,
    Kenny

  20. Pierre avatar

    Bravo pour le développement de ce module. Je suis en train de le tester sur une 1.1 de presta.
    bravo aussi pour ce sympathique blog prestaphop.

    Etant avant sous OSCSS (fork de OSC). J’avoue que je reste assez séduit par Prestahop en général.
    Merci . Continuez et qui sait peut-être à un de ces jours sur un SVN 🙂
    Pierre

  21. Musika avatar
    Musika

    Hay un modulo preparado para ser utilizado en Euro 6000?

  22. Kreativas avatar
    Kreativas

    La entidad con que trabajo maneja todo por si misma. de que manera puedo transladar los parametros a su tpv desde PS,. si uno de sus requsitos es pasarls via GET???
    un saludo