Today, We want to share with you ccavenue payment gateway integration in php.In this post we will show you ccavenue integration php, hear for ccavenue payment gateway integration in codeigniter we will give you demo and example for implement.In this post, we will learn about ccavenue integration php demo with an example.
how to integrate ccavenue payment gateway in php?
Contents
CCAvenue is a popular Payment Gateway that allows e-transaction. so first of all you can Create Merchant Account. and integrate CCAvenue Payment Gateway. and then Create a file named ccAvenueRequestHandler
Index.php
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Pay Your Payment With CCAvenue. - www.pakainfo.com</title> <?php require_once "config.php"; ?> <style> *,*:after,*:before{box-sizing: border-box;} body { max-width: 620px; margin: 20px auto; font-size: 0.95em; font-family: Arial; } .form-field { padding: 10px; width: 46%; border: #c1c0c0 1px solid; border-radius: 0; margin: 10px 2%; background-color: white; float: left; font-size: 15px; } .form-field-full{margin: 10px 2%;width: 96%;} #ccav-payment-form { border: #c1c0c0 1px solid; padding: 30px; float: left; width: 100%; box-shadow: 3px 3px 10px #0000001f; } .btn-payment { background: #009614; border: #038214 1px solid; padding: 11px 30px; color: #FFF; cursor: pointer;margin: 10px 2%;width: 96%; text-transform: uppercase; font-weight: bold; } .pay_header { text-align: center; } .group_holder{ width:100%; float:left;} </style> </head> <body> <div class="pay_header"> <h2>Welcome to LuvCite Digital Marketing Private Limited.</h2> <h3>Pay Your Payment With CCAvenue</h3> </div> <div id="ccav-payment-form"> <form name="frmPayment" action="ccavRequestHandler.php" method="POST"> <input type="hidden" name="merchant_id" value="<?php echo CCA_MERCHANT_ID; ?>"> <input type="hidden" name="language" value="EN"> <input type="hidden" name="currency" value="INR"> <input type="hidden" name="redirect_url" value="http://www.pakainfo.com/pay-now/"> <input type="hidden" name="cancel_url" value="http://www.pakainfo.com/pay-now/"> <div class="group_holder"> <input type="text" name="amount" class="form-field form-field-full" placeholder="Enter your Amount" required> </div> <div class="group_holder"> <input type="text" name="billing_name" value="" class="form-field" Placeholder="Enter your Billing Name" required> <input type="text" name="billing_address" value="" class="form-field" Placeholder="Enter your Billing Address" required> </div> <div class="group_holder"> <input type="text" name="billing_state" value="" class="form-field" Placeholder="Enter your State" required> <input type="text" name="billing_zip" value="" class="form-field" Placeholder="Enter your Zipcode" required> </div> <div class="group_holder"> <input type="text" name="billing_country" value="" class="form-field" Placeholder="Enter your Country" required> <input type="text" name="billing_tel" value="" class="form-field" Placeholder="Phone" required> </div> <div class="group_holder"> <input type="text" name="billing_email" value="" class="form-field" Placeholder="Enter your Email" required> <input type="url" name="merchant_param1" value="" class="form-field" Placeholder="URL" required> </div> <div class="group_holder"> <button class="btn-payment" type="submit">Pay Now</button> </div> </form> </div> </body> </html>
ConvertFile.php
<?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) { $bigingmdata = mcrypt_generic($openMode, $plainPad); mcrypt_generic_deinit($openMode); } return bin2hex($bigingmdata); } function decrypt($bigingmdata,$key) { $secretKey = hextobin(md5($key)); $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f); $bigingmdata=hextobin($bigingmdata); $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', ''); mcrypt_generic_init($openMode, $secretKey, $initVector); $finalStrData = mdecrypt_generic($openMode, $bigingmdata); $finalStrData = rtrim($finalStrData, "\0"); mcrypt_generic_deinit($openMode); return $finalStrData; } 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; } ?>
config.php
Here added your live or test version CCavenue MERCHANT ID, ACCESS CODE, WORKING KEY.
<?php define("CCA_MERCHANT_ID", ""); define("CCA_ACCESS_CODE", ""); define("CCA_WORKING_KEY", "");. ?>
ccavResponseHandler.php
<?php include('ConvertFile.php');?> <?php error_reporting ( 0 ); $workingKey = CCA_WORKING_KEY; $encResponse = $_POST ["encResp"]; $rcvdString = decrypt ( $encResponse, $workingKey ); $order_status = ""; $decryptValues = explode ( '&', $rcvdString ); $dataSize = sizeof ( $decryptValues ); for($i = 0; $i < $dataSize; $i ++) { $information = explode ( '=', $decryptValues [$i] ); $responseMap [$information [0]] = $information [1]; } $order_status = $responseMap ['order_status']; $liveOrdObject = new PymtOrder (); $paymentOrder = $liveOrdObject->getPaymentOrderByOrderId ( $responseMap ['order_id'] ); // this is to fool-proof check - checking if the paymentstatus is already posted // this can happen on page refresh in success page. $paymentStatus = $liveOrdObject->getPaymentStatusByOrderId ( $responseMap ['order_id'] ); if (empty ( $paymentStatus )) { $liveOrdObject->addPymtStatus ( $responseMap ['order_id'], $rcvdString, $responseMap ['order_status'], $responseMap ['amount'] ); } ?> <?php require_once("common/SessionValidate.php"); ?> <?php $pageTitle = "Live Payment Status "; $menuGroup = "Live Payment Status "; $menuPage = "Live Payment Status "; ?> <!doctype html> <html class="no-js" lang=""> <head> <title><?php echo $pageTitle; ?></title> <meta name="description" content=""> <?php require_once('view/header_line.php'); ?> <link rel="stylesheet" href="<?php echo BASE_PATH; ?>view/styles/style.css"> </head> <body> <div class="app layout-fixed-header"> <?php require_once("view/sidebar.php"); ?> <div class="main-panel"> <?php require_once("view/header.php"); ?> <div class="main-content"> <div class="panel"> <div class="panel-heading border"> <ol class="breadcrumb mb0 no-padding"> <li><?php echo $menuGroup; ?></li> <li class="active">Good Luck, Thank You!</li> </ol> </div> <div class="row"> <div class="col-md-10"> <div class="widget bg-white"> <div class="row row-margin"> <span class="col-md-10"> <?php if ($order_status === "Success") { $institutionObj = new Institution (); if (empty ( $paymentStatus )) { $staffObj = new Staff (); $numberOfSms = $responseMap ['amount'] / SMS_COST; $newSmsCredit = $numberOfSms + $currentInstitution [0] ["sms_credit"]; $institutionObj->updateSmsCredit ( $newSmsCredit, $currentInstitution [0] ["id"] ); $liveOrdObject = new PymtOrder (); $liveOrdObject->updateSmsCredit ( $newSmsCredit, $responseMap ["order_id"] ); } $instNow = $institutionObj->getByID ( $currentInstitution [0] ["id"]); echo "Thank you for shopping with us. Your transaction is successful and the Order ID is " . $responseMap ['order_id'] . ". Your current SMS credit balance is " . $instNow [0] ["sms_credit"]."."; } else if ($order_status === "Aborted") { echo "Thank you for shopping with us. We will keep you posted regarding the status of your order."; } else if ($order_status === "Failure") { echo "Thank you for shopping with us. However, the transaction has been declined."; } else { echo "Security Error. Illegal access detected"; } ?> </span> </div> </div> </div> </div> </div> </div> </div> <?php require_once("view/footer.php"); ?> </div> <?php require_once("view/common-html-body-end.php"); ?> <script src="<?php echo BASE_PATH; ?>view/scripts/pages/dashboard.js"></script> </body> </html>
ccavRequestHandler.php
<html> <head> <title> CCAvenue Payment Gateway Integration kit - www.pakainfo.com</title> </head> <body> <center> <?php include('ConvertFile.php')?> <?php require_once "config.php"; ?> <?php error_reporting(0); $all_criendtials=''; $working_key = CCA_WORKING_KEY; $access_code = CCA_ACCESS_CODE; foreach ($_POST as $key => $value){ $all_criendtials.=$key.'='.$value.'&'; } $orderId=uniqid() . date("Hisu"); $all_criendtials .= "order_id=".$orderId; $encrypted_data=encrypt($all_criendtials,$working_key); //echo "<pre>"; //print_r($all_criendtials); ?> <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>
I hope you get an idea about how to get response from ccavenue in php?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโt forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.