Work with Litle PHP SDK


In a recent project, we need to process Credit Card on real time. The vendor we use is Litle. Litle provides some SDK libraries including PHP, JAVA, .NET, RUBY, and PYTHON, but lack of documentation. They host the code in Github, and we grab the php SDK from there.

After download the source code, you can run Setup script (under litle-sdk-for-php-master/lib/). During the setup, you can choose Litle URL including different environments. For playing, you may choose sandbox, which has no credentials required and no special access needed. Basically, it will generate litle_SDK_config.ini as shown in the following:

user =USER
password =PASSWORD
currency_merchant_map ['DEFAULT'] =123456
url =
proxy =
version = 8.13
timeout =  65
reportGroup = Default Report Group

And then you can run the testing script named SampleDriver.php (under litle-sdk-for-php-master/test/). If you are using PHP V5.2+, then you should be ok. But if you are running lower version PHP, then you may see the error, as the following,

[24-Jan-2013 15:25:08] PHP Notice:  Undefined index:  currency_merchant_map in /home/test/litle-sdk-for-php-master/lib/Obj2xml.php on line 94
[24-Jan-2013 15:25:09] PHP Fatal error:  Uncaught exception 'Exception' with message 'Unknown SSL protocol error in connection to ' in /home/test/litle-sdk-for-php-master/lib/Communication.php:44

The reason is that in PHP 5.1.6, the pharse_ini_file() function does not recognize the format of ini file generated by Setup script. No sure why, if you know please leave comment below. So if there is a case, then you can change the format of litle_SDK_config.ini as shown in the following:

user =USER
password =PASSWORD
merchant_id =123456
url =
proxy =
version = 8.13
timeout =  65
reportGroup = Default Report Group

And you also need to change the logic in Obj2xml.php, on line 94, do the following change,

//$config['merchantId'] = $config_array['currency_merchant_map']['DEFAULT'];
$config['merchantId'] = $config_array['merchantId'];

Then, you should be all set to test against Litle sandbox.

OK, now let’s move on to Litle Cert environment. First update the url in litle_SDK_config.ini file to be,

;url = 
url =

And then run SampleDriver.php under test folder. You may got another headache, at least it happened to us. It’s SSL Certificate problem, as the show in the following,

PHP Fatal error:  Uncaught exception 'Exception' with message 'SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' in .....

In fact, this php curl issue, if you Google it, and you may see a lot of people had this issue (I’m glad if you come to this article by searching this in Google :-)). OK, let’s check Communication.php under lib folder,

class Communication{
   function httpRequest($req,$hash_config=NULL){
      $config = Obj2xml::getConfig($hash_config);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_PROXY, $config['proxy']);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
      curl_setopt($ch, CURLOPT_URL, $config['url']);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
      curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
      //you need define CURLOPT_CAINFO, if you set CURLOPT_SSL_VERIFYPEER to be true
      curl_setopt($ch, CURLOPT_CAINFO, "YOUR-CERT-PATH/ca-bundle.crt");
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,2);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_SSLVERSION, 3);
      $output = curl_exec($ch);
      $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      if (! $output){
         throw new Exception (curl_error($ch));
         return $output;


On line 14, we define CURLOPT_CATINFO, which is missing in original Communication.php. What’s CURLOPT_CATINFO? As state in,

The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.

And where can we download ca-bundle.crt? Here are two handy scripts to generate ca-bundle.crt,
1. For linux –
2. For windows –

Note that you need to save them with correct extension, ‘pl’ and ‘vbs’ separately, not text file. And then run the script, and it will generate ca-bundle.crt for you. Also you need to use absolute path when you define CURLOPT_CAINFO. For example:

curl_setopt($ch, CURLOPT_CAINFO, "/home/tester/ca-bundle.crt");
curl_setopt($ch, CURLOPT_CAINFO, "C:\CERT\ca-bundle.crt");

Leave a Reply

Your email address will not be published. Required fields are marked *