<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>These things are far too hard &#187; HSBC CPI</title>
	<atom:link href="http://leadingedgescripts.co.uk/tag/hsbc-cpi/feed/" rel="self" type="application/rss+xml" />
	<link>http://leadingedgescripts.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 24 Feb 2011 13:05:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to Set Up the HSBC CPI Integration (part two &#8211; the Java method)</title>
		<link>http://leadingedgescripts.co.uk/hsbc-cpi/how-to-set-up-the-hsbc-cpi-integration-part-two-the-java-method/</link>
		<comments>http://leadingedgescripts.co.uk/hsbc-cpi/how-to-set-up-the-hsbc-cpi-integration-part-two-the-java-method/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 16:45:51 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[HSBC CPI]]></category>
		<category><![CDATA[CPI]]></category>
		<category><![CDATA[HSBC]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/?p=97</guid>
		<description><![CDATA[Some of you may have just read about my experiences setting up the HSBC CPI system on Linux in my previous post about this subject well, unfortunately I&#8217;ve got bad news for you&#8230; after running some upgrades on our production web hosting server, guess what, it broke! And it didn&#8217;t break a little bit, it [...]]]></description>
			<content:encoded><![CDATA[<p>Some of you may have just read about my experiences setting up the HSBC CPI system on Linux in my <a href="http://www.leadingedgescripts.co.uk/server-administration/install-hsbc-cpi-credit-card-processing-on-linux/">previous post about this subject</a> well, unfortunately I&#8217;ve got bad news for you&#8230; after running some upgrades on our production web hosting server, guess what, it broke!</p>
<p>And it didn&#8217;t break a little bit, it broke a lot, to the point where we couldn&#8217;t get it working again, well, we probably could have, but since that would have meant un-installing the updates we have just installed, and that basically meant making our server less secure than it might have otherwise been, we decided to abandon the C version of the HSBC CPI installation and try something else. Not an easy decision considering how hard this was to set up in the first place, but now it&#8217;s working again it was absolutely definitely the right decision.</p>
<p>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4904188713812219";
/* 468x60, created 02/11/08 */
google_ad_slot = "9286450703";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
<p>So, in the spirit of helpfulness, I&#8217;m going to tell you how we got this up and running again using a different method.</p>
<p>We (my business partner James and I) are 90% certain that an update to the GCC library on our Linux server was responsible for breaking the LibcCpiTools.so implementation of the HSBC CPI system.</p>
<h3>The Java Implementation</h3>
<p>After deciding that the GCC update we ran was the most likely candidate for breaking this system, we decided to try using Java.</p>
<p>Thankfully, I have some experience programming Java, and I think if it wasn&#8217;t for that I would have completely given up on this whole HSBC integration thing.  You&#8217;re not going to need to know anything about Java programming in order to get this up and running though so don&#8217;t worry.</p>
<h2>What you&#8217;ll need</h2>
<p>You are going to need a few things before you get started:</p>
<ol>
<li>Your shared secret (as supplied by the HSBC)</li>
<li>A unique IP address (so you can use an SSL certificate for your domain)</li>
<li>An SSL certificate</li>
<li>A web hosting package with PHP enabled</li>
<li>The facility to use a Java server on your web hosting package (like <a href="http://tomcat.apache.org/">Apache Tomcat</a>)</li>
<li>WinRAR or WinZip (Mac users try <a href="http://www.zipeg.com/home.html">Zipeg</a>)</li>
<li>A .war file of the Java files supplied by the HSBC &#8211; this is a package of Java files, stored almost like a .zip file. (Don&#8217;t worry too much, I&#8217;ve got one I made earlier you can download later)</li>
<li>The scripts from my <a href="http://www.leadingedgescripts.co.uk/server-administration/install-hsbc-cpi-credit-card-processing-on-linux/">previous post regarding the HSBC CPI system</a>.</li>
</ol>
<h2>Setting It Up</h2>
<h3>Web Hosting</h3>
<p>You&#8217;ll need a hosting package with PHP enabled, a unique IP address, the facility to install SSL certificates and the facility to use a Java server (like Apache Tomcat).</p>
<h3>Apache Tomcat</h3>
<p>I can&#8217;t really tell you how to install this or get it working, unfortunately I had to rely on my colleague James setting this up for me, however I&#8217;m sure you&#8217;ll find everything you need on the <a href="http://tomcat.apache.org/">Apache Tomcat website</a>.</p>
<h3>SSL Certificate</h3>
<p>You&#8217;ll need a unique IP address for your SSL certificate, then ask your web hosting company for an SSL certificate. If they can&#8217;t supply you with one, you can get them from businesses like Thawte, Verisign or Globalsign. You&#8217;ll need to get it installed on your web server so you can serve pages over a secure socket (https://)</p>
<h3><strong>OrderHash.war</strong></h3>
<p>Once you&#8217;ve got everything else set up, you&#8217;ll need to <a href="http://www.leadingedgescripts.co.uk/wp-content/2008/11/orderhash.war">download my OrderHash.war</a> &#8211; this is simply the Java files supplied by the HSBC but packaged into a .war file. If you&#8217;re on Windows use WinRAR to browse the .war file (Mac users use Zipeg) You&#8217;ll be able to browse the folder structure, which should look something like this:</p>
<div><a href="http://www.leadingedgescripts.co.uk/wp-content/2008/11/orderhashwar.jpg"><img class="alignnone size-medium wp-image-106" title="orderhashwar" src="http://www.leadingedgescripts.co.uk/wp-content/2008/11/orderhashwar-300x220.jpg" alt="" width="300" height="220" /></a></div>
<div>If you click on the WEB-INF folder, you will find two more files, one of which is called ss.txt, if you open this file by double-clicking on it and copy your HSBC shared secret into this file then save it, with luck it will be saved into the .war and you&#8217;re ready to go!</div>
<h3>Putting it all together</h3>
<p>You need to upload your new .war file into your Java server, the process may differ with different Java Servers, but with Tomcat and the Plesk web hosting control panel, it&#8217;s as simple as uploading the OrderHash.war file into Plesk.</p>
<p>Now you&#8217;re ready to go!</p>
<p>Try uploading the sample.html file supplied by the HSBC but changing the action of the form to point to the new Java Server Page:</p>
<pre>&lt;form name="cpiForm" action="http://www.example.com:9080/OrderHash/OrderHash.jsp" method="POST" onSubmit="singleSubmit(this)"&gt;</pre>
<p>With luck you&#8217;ll be able to generate a valid Order Hash! Now, as before, the actual OrderHash generator creates some pretty ugly HTML, and you wouldn&#8217;t want your clients looking at it, but you can use the <a href="http://www.leadingedgescripts.co.uk/downloads/hsbc_php.zip">PHP files I wrote in my previous post</a> on this subject to &#8220;wrap&#8221; the horrible HSBC pages in your own code.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/hsbc-cpi/how-to-set-up-the-hsbc-cpi-integration-part-two-the-java-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install HSBC CPI credit card processing on Linux</title>
		<link>http://leadingedgescripts.co.uk/server-administration/install-hsbc-cpi-credit-card-processing-on-linux/</link>
		<comments>http://leadingedgescripts.co.uk/server-administration/install-hsbc-cpi-credit-card-processing-on-linux/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 17:46:41 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[HSBC CPI]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[CPI]]></category>
		<category><![CDATA[HSBC]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/wp/?p=13</guid>
		<description><![CDATA[UPDATE: I have written some more information about setting up the HSBC CPI using the Java method rather than the C method outlined below. I ran into a problem recently where a client of mine could not install the HSBC credit card payments, despite his best efforts at following the CPI specification document HSBC provided. [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE: I have written some <a href="http://www.leadingedgescripts.co.uk/hsbc-cpi/how-to-set-up-the-hsbc-cpi-integration-part-two-the-java-method/">more information about setting up the HSBC CPI</a> using the Java method rather than the C method outlined below.</p>
<p>I ran into a problem recently where a client of mine could not install the HSBC credit card payments, despite his best efforts at following the CPI specification document HSBC provided.</p>
<p>To cut a long(ish) story short, he ended up asking me to take a look at it. Since I managed to figure out the problem, and noticed that the HSBC documentation is somewhat lacking to say the least&#8230; (and the HSBC support staff don’t seem to know this either!) I thought I’d give something back by letting you know how to get this thing working on a Linux server. Sorry, anyone using any other type of server, I can’t help.</p>
<p>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4904188713812219";
/* 468x60, created 02/11/08 */
google_ad_slot = "9286450703";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
<p>Right, to begin with you need to get all the files that HSBC send you. For completeness I’ve copied the text right out of the CPI Specification document below:</p>
<p><q></q></p>
<h4>Linux</h4>
<ul>
<li>Copy sample.html to a web enabled directory.</li>
<li>Copy OrderHash.e to a web enabled directory with execute permissions and without &#8220;directory browse&#8221; permissions (the pages will need to be able to read from and write to a file in the local directory).</li>
<li>Copy results.e to a secure (https) web enabled directory with execute permissions and without &#8220;directory browse&#8221; permissions (the pages will need to be able to read from and write to a file in the local directory).</li>
<li>Add the path to libCcCpiTools.so to the LD_LIBRARY_PATH environment variable (either by suitable file location, or direct addition). It may be necessary for a merchant to speak to their host regarding suitable location / installation of this file.</li>
<li>The executable sample files look for the shared secret in a file called ss.txt within the same folder.</li>
</ul>
<p>Lets take this one step at a time.</p>
<p>• Copy sample.html to a web enabled directory.</p>
<p>Ok, why this is the first step, I don&#8217;t know, but it’s quite correct, just create a folder in your web space (or put it into the root of the website) and copy this file over. You don’t need to do anything special with this file just yet.</p>
<p>• Copy OrderHash.e to a web enabled directory with execute permissions and without &#8220;directory browse&#8221; permissions (the pages will need to be able to read from and write to a file in the local directory).</p>
<p>Ok, again, this is strange thing to ask for at the beginning of the document in my opinion, but that doesn’t matter too much. What REALLY DOES MATTER is the essential information that is missing here!!!</p>
<p><strong>Copy this file into your CGI-BIN folder!</strong> I could not get this to work in any other folder, it needs to be located in your CGI-BIN (yes I know I’ve repeated myself).</p>
<p>Several people seem to have had problems with the CGI-BIN, I should explain, you don’t just create a folder on your server called /CGI-BIN/ you need to tell your Apache web server to use CGI scripts, instructions on this can be found here: <a href="http://httpd.apache.org/docs/1.3/howto/cgi.html">http://httpd.apache.org/docs/1.3/howto/cgi.html</a> – If your server already has a folder called /CGI-BIN/ then it probably already knows how to execute CGI scripts.</p>
<p>Then <strong>set the permissions for this file to 755</strong></p>
<p>That information alone should be enough to help to figure out this (in my opinion) poorly documented system. Anyway, on with the rest:</p>
<p>• Copy results.e to a secure (https) web enabled directory with execute permissions and without &#8220;directory browse&#8221; permissions (the pages will need to be able to read from and write to a file in the local directory).</p>
<p>Again, this file <strong>must be placed in the CGI-BIN</strong> folder in your web space, <strong>and have 755 permissions.</strong></p>
<p>• Add the path to libCcCpiTools.so to the LD_LIBRARY_PATH environment variable (either by suitable file location, or direct addition). It may be necessary for a merchant to speak to their host regarding suitable location / installation of this file.</p>
<p>What? I hear you asking. Well, don’t worry all they want you to do is ask your web host to install the libCcCpiTools.so binary file on your web hosts server &#8230; Not asking much then! anyone using a normal web host won&#8217;t be allowed to use this. Make sure your host will allow you to install this file.  The server administrator should be able to install this and setup the LD_LIBRARY_PATH for you. If they can, you can also get them to test that the libCcCpiTools.so file is working using the ‘testhash.e’ file that HSBC kindly supply. If that works, then we’re in business.</p>
<p>• The executable sample files look for the shared secret in a file called ss.txt within the same folder.</p>
<p>What? the same folder as what? What they hell are they talking about??? Well, the missing text is &#8230; within the same folder as the OrderHash.e file (your CGI-BIN, if you hadn’t figured that out.) You need to copy your shared secret into this SS.txt file.</p>
<h4>So you think that’s it?</h4>
<p>We’re almost there now, just some more missing information to fill you in on.</p>
<p>This one isn’t even covered in the <a href="http://www.leadingedgescripts.co.uk/downloads/CPI%20Specification.pdf">CPI specification</a> at all.</p>
<p><strong>Now you have to edit the sample.html file.</strong></p>
<p>Open up the sample.html using your favourite HTML editor, you should see something similar to the following:</p>
<pre>&lt;FORM name="cpiForm" action="http://www.yourdomain.com/cgi-bin/OrderHash.e" method="POST" onSubmit="singleSubmit(this)"&gt;
	&lt;INPUT TYPE="submit" NAME= "submitButton" VALUE="Submit"&gt;

	&lt;INPUT TYPE="button" NAME= "resetButton" VALUE="Reset" onClick="this.form.reset();resetDynamicFields();"&gt;

	&lt;!-- Fill in the VALUE attribute below with the URL to the CPI. --&gt;
	&lt;INPUT type="hidden" name="CpiUrl" value="https://www.cpi.hsbc.com/servlet"&gt;
	&lt;BR&gt;
	&lt;TABLE&gt;
	&lt;TR&gt;&lt;TD&gt;OrderId:&lt;/TD&gt;&lt;TD&gt;&lt;INPUT type="text" name="OrderId" value=""&gt;&lt;/TD&gt;&lt;/TR&gt;

	&lt;TR&gt;&lt;TD&gt;TimeStamp:&lt;/TD&gt;&lt;TD&gt;&lt;INPUT type="text" name="TimeStamp" value=""&gt;&lt;/TD&gt;&lt;/TR&gt;
	&lt;TR&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;

	&lt;!-- Fill in the VALUE attribute below with the URL to the Results sample. --&gt;

	&lt;TR&gt;&lt;TD&gt;CpiReturnUrl:&lt;/TD&gt;&lt;TD&gt;&lt;INPUT type="text" name="CpiReturnUrl" value="https://www.yourdomain.com/cgi-bin/Results.e"&gt;&lt;/TD&gt;&lt;/TR&gt;</pre>
<p style="text-align: left;">Edit the bits I have highlighted in red so that they point to the files in your CGI-BIN. (Like I have done above.)</p>
<h4>Now you’re nearly done!</h4>
<p>Now, if you open up the sample.html file in your browser, you should be able to click submit, open OrderHash.e, click on Submit again and be taken through to the HSBC online ordering service.</p>
<p><strong>OK great, but my web host won&#8217;t allow me to use exec().</strong></p>
<p>If you’re on a shared server, for one thing, you’ve been lucky to get this far, most web hosts who run shared servers will not install the libCcCpiTools.so shared object. If yours did, you may not need this next bit of information. For those who do, now you’ll be starting to think to yourself, well yeah that&#8217;s great but how the hell do I customise these pages? I don’t want my customers looking at pages that say &#8216;Sample Order Hash Page&#8217; (or whatever it says). So how am I meant to get a valid order hash from OrderHash.e, without sending my customers via the OrderHash.e file?</p>
<p>Well, now you’re expected to be able to execute the OrderHash.e file. <strong>Nice System &#8230;</strong></p>
<p>Excuse me HSBC, but most shared hosts don&#8217;t allow me execute random binary files on their server &#8230;</p>
<p>I run a small shared hosting server with a colleague, for security reasons (good reasons) we don’t allow use of the PHP exec() function, it&#8217;s simply too dangerous</p>
<p>So when I was asked to find a way around this using PHP on my server without using the exec() function, at first I was stumped. But here’s how I got around the issue (there is possibly another way using curl, but I don’t know it, so this was my solution &#8230;)</p>
<p><strong>PHP Code:</strong></p>
<pre><code>$postdata = array2String($_POST);

$fp = fsockopen("www.yourdomain.com", 80);

if (!$fp)
{
	echo "Couldn't open the connection to OrderHash.e file";
}
else
{
	/***************************
	|lets build our post request
	***************************/
	$out = "POST /cgi-bin/OrderHash.e HTTP/1.1\r\n";
	$out .= "Host: www.yourdomain.com\r\n";
	$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 .= "Referer: http://www.yourdomain.com/hsbc/sample.html\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);
	...

			</code></pre>
<p>Here is a copy of the <a href="http://www.leadingedgescripts.co.uk/downloads/hsbc_php.zip">full PHP script</a>.</p>
<p>All credit to Ed Fowler, who ran up against the same problem as I did and came up with this version using Perl. It&#8217;s based on the same concept as my PHP script, and has the same pre-requisite (that you can generate a valid order hash). But I&#8217;m pleased to be able to offer the Perl version as well (Thanks Ed!) <a href="http://www.leadingedgescripts.co.uk/downloads/hsbc_perl.zip">full Perl script</a></p>
<p>Why not take a look at Eds site: <a href="http://www.abodeHIP.co.uk/">www.abodeHIP.co.uk</a></p>
<hr /><em>Ok</em>, I&#8217;ve noticed that some of you who&#8217;ve emailed me have had problems understanding the array2String() function that I&#8217;ve mentioned in the code above. I probably should have added this in when I first wrote this page. What this function does is take all the post variables and concatenate them into a string. POST requests (if you could see them (which you can using <a href="http://livehttpheaders.mozdev.org/">LiveHTTPHeaders</a>)) look exactly like GET requests. So if you just turn your $_POST array into a URL safe string, that is what we pass within our HTTP header to the OrderHash.e file.</p>
<p>Our variable $postdata should contain a string looking something like this (cut down) version:</p>
<p>CpiUrl=https%3A%2F%2Fwww.cpi.hsbc.com%2Fservlet&amp;OrderId=123456789&amp;TimeStamp=123456789&amp;CpiReturnUrl=https%3A%2F%2Fwww.yourdomain.com%2Fthanks.php&amp;CpiDirectResultUrl=https%3A%2F%2Fwww.yourdomain.com%2Fcgi-bin%2FResults.e&amp;StorefrontId=UK123456789GBP&amp;</p>
<p>I&#8217;ve also been asked &#8220;what next?&#8221;, well $fp can be treated like a file and read back into your script, if you read it into a string you will have an exact copy of the HTML output of the OrderHash.e file to play with, all you need to do then is strip out the stuff you don&#8217;t want and output the stuff you do. Hope that helps.</p>
<h4>Other sources of helpful stuff to look at</h4>
<ul>
<li>This doesn&#8217;t relate to anything I have written, but someone might find this useful. <a href="http://www.angryrooster.co.uk/software/hsbccpi.php">a tiny Php Module that sits between the HSBC library for generating Order Hash Codes, and PHP.</a></li>
<li>CPI support telephone number: 08456 022880</li>
<li>If you don&#8217;t already have a CGI-BIN or your server isn&#8217;t processing the OrderHash.e as an executable, you probably need to set Apache up to use CGI scripts, instructions on this can be found here:<a href="http://httpd.apache.org/docs/1.3/howto/cgi.html">http://httpd.apache.org/docs/1.3/howto/cgi.html</a></li>
<li>I haven&#8217;t tried this, but you might be able to execute the OrderHash.e file using the PHP backtick operator -&gt; ` (look up how to do this)</li>
</ul>
<p>You can see roughly what I did; open a connection to the OrderHash.e file in the CGI-Bin &amp; send it some POST data via HTTP headers using my fsockopen() connection. Then I retrieve the result, which contains a valid order hash. Then I can do whatever I want with the returned result, which contains, among other things my <strong>valid Order Hash</strong></p>
<p><sub>In order to use this code, you need to have already got your libCcCpiTools.so file installed and have CGI and PHP scripting working. If you do already have the libCcCpiTools.so file installed and a working cgi-bin and PHP, then you should only need my code to get the project finished. You should be able to slot it into any html/css layout with relative ease.</sub></p>
<p>Disclaimer</p>
<p>I never said this would definitely work for you, I&#8217;m just trying to help. This worked for me, using my server, hopefully it&#8217;ll work for you, but I&#8217;m in no way responsible if you mess up your server or your website. I don&#8217;t work for HSBC, and don&#8217;t have any knowledge of their systems. I have reproduced their documents in this file, and am making their CPI specification document freely available. I&#8217;m not sure if that&#8217;s ok, but it remains HSBC&#8217;s property and if they want me to take it off this site, then please email me before you sue me.<br />
Chris Cook</p>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/server-administration/install-hsbc-cpi-credit-card-processing-on-linux/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

