PHP Fix CCAvenue Payment Gateway Integration Kit Deprecated function

The CCAvenue payment gateway is one of the most popular payments gateways worldwide. You can easily integrate this payment gateway into your website. CCAvenue provides the integration Kit to integrate, I am going to use it.

You have to login in your CCAvenue account and download the Integration Kit from in nav menu Resources > Web Integration Kit > Download Integration Kits download for PHP.

When I was integrating I found that they have not updated it for PHP7. So, I searched for other library but they also have not updated, they all are using PHP5 functions which are deprecated in PHP7. They all are using mcrypt functions which are deprecated for PHP7.

After a lot of searches, I found the solution. This Kit contains a Crypto.php file. This file is used to encrypt the data before sending it further and decrypt function to decrypt the response. These functions are using deprecated mcrypt functions.

Open this file in your editor and change the code with the following code:

    function encrypt($plainText,$key)
    {
        $encryptionMethod = "AES-128-CBC";
        $secretKey = hextobin(md5($key));
        $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
        $encryptedText = openssl_encrypt($plainText, $encryptionMethod, $secretKey, OPENSSL_RAW_DATA, $initVector);
        return bin2hex($encryptedText);
    }

    function decrypt($encryptedText,$key)
    {
        $encryptionMethod     = "AES-128-CBC";
        $secretKey         = hextobin(md5($key));
        $initVector         =  pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
        $encryptedText      = hextobin($encryptedText);
        $decryptedText         =  openssl_decrypt($encryptedText, $encryptionMethod, $secretKey, OPENSSL_RAW_DATA, $initVector);
        return $decryptedText;
    }

    function pkcs5_pad ($plainText, $blockSize)
    {
        $pad = $blockSize - (strlen($plainText) % $blockSize);
        return $plainText . str_repeat(chr($pad), $pad);
    }

    function hextobin($hexString) 
    { 
        $length = strlen($hexString); 
        $binString="";   
        $count=0; 
        while($count<$length) 
        {       
            $subString =substr($hexString,$count,2);           
            $packedString = pack("H*",$subString); 
            if ($count==0)
            {
                $binString=$packedString;
            } 
                
            else 
            {
                $binString.=$packedString;
            } 
                
            $count+=2; 
        } 
        return $binString; 
    }

Now you can test it, it will work fine without any issue. If you still having any issue regarding integration, let me know.

1 Comment

  1. The result of which they didn’t do a really good job simply because started to feel cleared.

    One of the ways I really want you to avoid them from is PLR, Public Label
    Rights products. So, what perform going location in its pages