CCAvenue Payment Gateway Integration in PHP
Introduction about CCAvenue payment gateway
The CCAvenue is known as Common Service Provider. Master Merchant allows authorized Sub Merchants to accept payment from their customers. The Master Merchant has to be authorized with CCAvenue to make a commercial web application to process payment.
CCAvenue Payment gateway Integration is similar to other payment gateway method like PayPal, Stripe and more in terms of process flow. Integrating this payment gateway with a web application is used to enable payment processing via CCAvenue.
This is one of the popularly used payment gateway for the Indian web applications. It supports online payments via credit card, debit card, internet banking and more.
Advantages of using CCAvenue payment gateway
There are many advantages of using this payment gateway method.
- It is one of the secured payment gateway which promises a protected payment cycle with your application.
- CCAvenue supports most of the eBusinesses regardless of its size.
- This type of payment gateway provides high level SSL encryption other security certifications.
- It promises secured link between customers, CCAvenue payment gateway, application, financial mediates during the payment flow.
CCAvenue payment gateway integration methods
There are four type of integration methods supported by CCAvenue to provide payment interface to collect information. Those are listed and explained below.
- CCAvenue billing page – A customizable billing page is provided by CCAvenue with an interface to collect billing and shipping information from the user.
- CCAvenue iFrame checkout – A predefined form used to get and validate the payment data from the user. This methods handles PCI compliance.
- Custom checkout form – Using this method the Merchant has to get and send the payment information to CCAvenue via a custom built form.
- CCAvenue shopping cart – CCAvenue supports product management and shopping cart customization. This will save the your effort to create and manage product and cart by your own.
CCAvenue payment flow diagram
In this flow diagram, it displays the payment flow between CCAvenue and the PHP web application in which this payment gateway is integrated.
In this flow diagram, it shows the possible ways of payments supported by CCAvenue. As we have already seen, it supports net banking, credit / debit card payments as shown in the figure.
Steps to integrate CCAvenue Payment Gateway
These are the steps required for the CCAvenue payment gateway integration in PHP.
- Create Merchant Account.
- Login to Merchant Dashboard and download CCAvenue payment integration kit.
- get Security keys (Merchant id, Access Code, Working key).
- Configure CCAvenue security keys and (test/live) endpoint in your PHP application.
- Create Payment form and deploy request / response handlers and with the guidance of the integration kit.
- Create return pages for handling payment notification on success or cancel.
The following screenshot shows the CCAvenue merchant signup form used to create a new account as the first step of this payment integration.
Download CCAvenue payment gateway integration kit
The CCAvenue payment gateway integration kit is client library provided by CCAvenue. This integration kit is available for mobile and web application.
CCAvenue provides the integration kit for many programming environment PHP, Python, ASP.Net and more.
By logging in with the approved Merchant account we can see the menu navigation in the header to see the integration kit downloads. After login, navigate through Resources > Web Integration Kit > Download Integration Kit > Download PHP to get the integration kit for the PHP.
When you download the integration kit from the CCAvenue merchant dashboard, it contains request response payment handler files. The integration kit is also contains Crypto.php with the collection of functions to to encrypt decrypt merchant data.
How to get the CCAvenue Merchant ID, Access Code and Working Key
Fore implementing CCAvenue payment gateway integration, the merchant id, access code and the working key are the prime information to be passed with the payment request. For getting these code and keys you need to have CCAvenue Merchant account.
Once we logged in with CCAvenue by using Merchant account, we can see the dashboard with menu options access the resources and keys.
By navigating via Settings > API keys the CCavenue API keys page will be shown. This page will display the Merchant Id, Access Code and Working key.
The list of Access Code and Working keys are shown for the corresponding registered URLs. So, we need to copy the right secret keys and use them in the right origin to send payment request.
Payment gateway PHP example integration with a website
In this section, we are going to see an example for integrating CCavenue payment gateway in an PHP application.
Configure the Merchant id, Access Code and Working key with your PHP application. In this example, I have created config.php file to contain these security keys used for payment initiation and processing.
In the PHP payment integration kit downloaded from the CCAvenue resources has the ccavRequestHandler.php, ccavResponseHandler.php, Crypto.php and a test file which contains the sample payment form with required inputs.
CCAvenue Payment Form HTML
A standard payment form has to be submitted for initiating the payment request. This form will contain inputs with merchant id, language, amount, currency and more payment details. It also contains customer’s billing information with name and address.
The following HTML shows the sample payment form used in this PHP CCAvenue payment gateway integration example. The form action is pointed to the PHP endpoint ccavRequestHandler.php to which the payment details will be posted.
CCAvenue Payment Gateway Intgration
ccavRequestHandler.php
In this file, it receives the payment data posted via the HTML form. The posted data are are encrypted in this file. The working key taken from the CCAvenue Merchant dashboard is used as the encryption key.
After encrypting these form input the encrypted details are concatenated and sent to the CCAvenue server with the access code.
The following script shows how it is going to be implemented in the ccavRequestHandler.php file. This code points the CCAvenue test environment for testing the payment flow initially.
CCAvenue Payment Gateway Integration kit
$value){ $merchant_data.=$key.'='.$value.'&'; } $merchant_data .= "order_id=".$orderId; $encrypted_data=encrypt($merchant_data,$working_key); ?>
"; echo ""; ?>
Crypto.php
This file contains the functions to encrypt or decrypt the payment information posted via the HTML form. It also includes util functions for padding and conversion.
Note: This file uses the deprecated function mcrypt_ function. These functions are deprecated as of PHP version 5.5.0 and it will not work in PHP 7. If you want a alternate for the encrypt decrypt utilities to be supported in latest PHP version, the following code will be helpful.
CCAvenue test environment
Once this payment gateway integration is completed, the code must be tested in the sandbox environment. CCAvenue provides a test environment to test the payment flow before put the application in production.
In the CCAvenue test environment the payment transactions will not be processed. This is the sandbox mode of testing the payment request and response flow.
The example code in this article targets the test environment URL in the payment form action attribute.
Go Live
After testing the CCAvenue payment gateway integration with the PHP application, you can go live by moving it to the production.
For going live and use the CCAvenue secure production environment, the https://test.ccavenue.com target should be replaced with https://secure.ccavenue.com.
CCAvenue payment form output
For initiating the CCavenue payment request, we need to build the standard payment form for your PHP application. This form should contain payment details like payment callback URLs, amount, currency, item number and more information.
Below screenshot shows the CCAvenue payment form fields to collect the billing information from the user. The other payment details like the notify URL, return URL are sent via form’s hidden fields.
Conclusion
As a popularly used payment gateway method, it provides great support for it sub merchants and thereby facilitate consumers with protected payment environment. Most of the Indian applications use CCAvenue as a payment gateway for providing options to its customer to make payments.
With the clear integration procedure, the CCAvenue API simplifies the developers effort on payment gateway integration with the PHP application. It supports the integration kit not only for PHP but also for many platform like .Net, Python, iOS and more.
Hope this article helps you to understand how to integrate CCAvenue Payment gateway with a PHP web application. The downloadable source code contains the sample payment form code with the CCAvenue payment request and response handlers. For running this example, you need to create a Merchant account in CCAvenue and replace the configurable API key constants in this example.
Contact : support@erps.in (OR) uma@f5craft.com / +91 87784 09644 (OR) +91 93443 88665
click here and download the project source code :