CCAvenue payment gateway is a most popular payment gateway which provides the best way of ecommerce solutions. It is only and complete payment gateway in India which allows e-merchants to process their transactions from Credit card,Netbbanking,Debit card and Online Bank Account etc.
CCavenue is authorized by Indian financial institutions and one of the most secure payment gateway to transact money for an online shopping. It accepts and validates most of the online payments modes via Credit and Debit Card, Net banking,Debit Card and Mobile Payment from the end customers in a real-time. It is simple to integrate in php.
Procedures to Integrate Cc Avenue Payment Gateway
- First need to create an account https://www.ccavenue.com/
- After registration CCAvenue team verify your account mobile and email.
- Your account will be activated within one to two hours.
- After that CCAvenue team verify your website and provide all required details like Marchant ID, Working Key etc.
Now need to create four files for CCAvenue Payment gateway integration first create form for that create a file index.php and copy below code and paste in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <!DOCTYPE html> <html lang="en"> <head> <title>CCAvenue Payment</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script> window.onload = function() { var d = new Date().getTime(); document.getElementById("tid").value = d; }; </script> </head> <body> <div class="container"> <h2>CCAvenue Payment Gateway</h2> <form method="post" name="customerData" action="ccavRequestHandler.php"> <div class="form-group"> <input type="text" class="form-control" id="name" placeholder="Enter name" name="name"> </div> <div class="form-group"> <input type="text" class="form-control" id="address" placeholder="Enter address" name="address"> </div> <div class="form-group"> <input type="text" class="form-control" id="amount" placeholder="Enter amount" name="amount"> </div> <input type="hidden" name="tid" id="tid" readonly /> <input type="hidden" name="merchant_id" value="123456"/> <input type="hidden" name="order_id" value="123654789"/> <input type="hidden" name="currency" value="INR"/> <input type="hidden" name="redirect_url" value="http://xyz.com/ccavenuePayment/ccavResponseHandler.php"/> <input type="hidden" name="cancel_url" value="http://xyz.com/ccavenuePayment/ccavResponseHandler.php"/><input type="hidden" name="language" value="EN"/> <button type="submit" class="btn btn-default">Pay Now</button> </form> </div> </body> </html> |
Then create a new file ccavRequestHandler.php and copy below code and paste it in just created file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <html> <head> <title>CCAvenue Payment</title> </head> <body> <center> <?php include('Crypto.php')?> <?php error_reporting(0); $merchant_data=''; $working_key='fdshaj131231231';//Shared by CCAVENUES $access_code='aG4632543265ghjg';//Shared by CCAVENUES foreach ($_POST as $key => $value){ $merchant_data.=$key.'='.$value.'&'; } $encrypted_data=encrypt($merchant_data,$working_key); // Method for encrypting the data. ?> <form method="post" name="redirect" action="https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction"> <?php echo "<input type=hidden name=encRequest value=$encrypted_data>"; echo "<input type=hidden name=access_code value=$access_code>"; ?> </form> </center> <script language='javascript'>document.redirect.submit();</script> </body> </html> |
Please make sure don’t forget to change the working key and access code in above code.
Now create ccavResponseHandler.php and copy below code and paste it in your file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php include('Crypto.php')?> <?php error_reporting(0); $workingKey='324bjksadbfs'; //Working Key should be provided here. $encResponse=$_POST["encResp"]; //This is the response sent by the CCAvenue Server $rcvdString=decrypt($encResponse,$workingKey); //Crypto Decryption used as per the specified working key. $order_status=""; $decryptValues=explode('&', $rcvdString); $dataSize=sizeof($decryptValues); echo "<center>"; for($i = 0; $i < $dataSize; $i++) { $information=explode('=',$decryptValues[$i]); if($i==3) $order_status=$information[1]; } if($order_status==="Success") { echo "<br>Thank you for shopping with us. Your credit card has been charged and your transaction is successful. We will be shipping your order to you soon."; } else if($order_status==="Aborted") { echo "<br>Thank you for shopping with us.We will keep you posted regarding the status of your order through e-mail"; } else if($order_status==="Failure") { echo "<br>Thank you for shopping with us.However,the transaction has been declined."; } else { echo "<br>Security Error. Illegal access detected"; } echo "<br><br>"; echo "<table cellspacing=4 cellpadding=4>"; for($i = 0; $i < $dataSize; $i++) { $information=explode('=',$decryptValues[$i]); echo '<tr><td>'.$information[0].'</td><td>'.$information[1].'</td></tr>'; } echo "</table><br>"; echo "</center>"; ?> |
Please make sure don’t forget to change the working key in above code. then create crypto.php and copy below code and paste in crypto.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <?php error_reporting(0); function encrypt($plainText,$key) { $secretKey = hextobin(md5($key)); $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f); $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', ''); $blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc'); $plainPad = pkcs5_pad($plainText, $blockSize); if (mcrypt_generic_init($openMode, $secretKey, $initVector) != -1) { $encryptedText = mcrypt_generic($openMode, $plainPad); mcrypt_generic_deinit($openMode); } return bin2hex($encryptedText); } function decrypt($encryptedText,$key) { $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); $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', ''); mcrypt_generic_init($openMode, $secretKey, $initVector); $decryptedText = mdecrypt_generic($openMode, $encryptedText); $decryptedText = rtrim($decryptedText, "\0"); mcrypt_generic_deinit($openMode); return $decryptedText; } //*********** Padding Function ********************* function pkcs5_pad ($plainText, $blockSize) { $pad = $blockSize - (strlen($plainText) % $blockSize); return $plainText . str_repeat(chr($pad), $pad); } //********** Hexadecimal to Binary function for php 4.0 version ******** 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; } ?> |
All Done!!
I’m a full-stack developer. My hobby and profession to write blog and programming tips that helps to others. I am a great admirer of PHP, Laravel, Codeigniter, AngularJS, Vue.js, Javascript, JQuery, WordPress, Plugin Development, Theme Development and Bootstrap from the early stage.
I have been absent for some time, but now I remember why I used to love this website. Thank you, I’ll try and check back more often. How frequently you update your web site?
I just want to say I’m newbie to blogging and certainly enjoyed this blog. Very likely I’m going to bookmark your site . You actually have superb articles and reviews. Regards for sharing with us your webpage.
Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.
Kudos. Plenty of info!
I have been surfing online more than 2 hours today,
yet I never found any interesting article like yours.
It’s pretty worth enough for me. In my opinion, if all website
owners and bloggers made good content as you did, the web
will be much more useful than ever before.
Greetings! Very useful advice within this article!
It is the little changes that will make the largest changes.
Thanks for sharing!
Thanks for sharing such useful information . I was currently building the website in WordPress and asked developers to do add this functionality. However, they hadn’t any idea about the link clocking. After reading your article, I forwarded the same link to them and they installed the plugin. Initially, I had to explore the link, but now it is working fine.