Free Upi Payment Gateway-Implementing Paytm Payment Gateway Integration in CodeIgniter for Indian Transactions
Integrating the Paytm Payment Gateway in a CodeIgniter application involves several steps. Below is a high-level overview of the process, followed by a sample implementation.
### High-Level Steps:
1. **Registration with Paytm**: You need to register on the Paytm website and obtain your merchant ID and other credentials.
2. **Download SDK**: Paytm provides SDKs and libraries for various platforms. For CodeIgniter, you can use the PHP library provided by Paytm.
3. **Configure Paytm**: Set up your Paytm configuration file with the necessary credentials such as merchant ID, merchant key, website name, and industry type.
4. **Create a Payment Page**: Develop a controller and view in CodeIgniter to initiate the payment process.
5. **Generate Checksum**: Before making a transaction request, generate a checksum using the Paytm library.
6. **Redirect to Paytm**: Post the payment details along with the checksum to the Paytm payment URL.
7. **Handle Response**: After the transaction is completed, Paytm sends a response to a specified URL (callback URL). You need to handle this response to update the transaction status in your database.
8. **Order Status Verification**: After the payment, verify the order status by sending a request to the Paytm server with the necessary parameters.
### Sample Implementation:
Below is a simplified example of how you might integrate Paytm in a CodeIgniter application.
#### 1. Configuration:
Create a configuration file `paytm_config.php` in the `application/config` directory with the following content:
“`php
library(‘Paytm_lib’);
$this->load->helper(‘form’);
}
public function index()
{
$this->load->view(‘paytm_form’);
}
public function pay()
{
$data = array(
‘amount’ => $this->input->post(‘amount’),
‘currency’ => ‘INR’,
‘product_info’ => ‘Product Description’,
‘order_id’ => ‘YOUR_ORDER_ID’,
‘customer_id’ => ‘CUSTOMER_ID’,
’email’ => ‘CUSTOMER_EMAIL’,
‘mobile’ => ‘CUSTOMER_MOBILE’
);
$this->paytm_lib->generateChecksum($data);
redirect($this->paytm_lib->getPaytmURL());
}
}
“`
#### 3. Library:
Create a library `Paytm_lib.php` in `application/libraries/Paytm_lib.php`:
“`php
CI = & get_instance();
$this->CI->load->config(‘paytm_config’);
}
public function generateChecksum($data)
{
// Include the Paytm library for checksum generation
require_once(APPPATH.’third_party/Paytm/checksum.php’);
$paytmParams = array(
“MID” => $this->CI->config->item(‘merchant_id’),
“ORDER_ID” => $data[‘order_id’],
“CUST_ID” => $data[‘customer_id’],
“TXN_AMOUNT” => $data[‘amount’],
“CHANNEL_ID” => “WEB”,
“WEBSITE” => $this->CI->config->item(‘website_name’),
“INDUSTRY_TYPE_ID” => $this->CI->config->item(‘industry_type’),
“CALLBACK_URL” => base_url(‘paytm/callback’),
);
$checksum = generateChecksum($paytmParams, $this->CI->config->item(‘merchant_key’));
return $checksum;
}
public function getPaytmURL()
{
// Return the Paytm payment URL
return $this->CI->config->item(‘paytm_url’);
}
// Add more methods as needed for handling response, etc.
}
“`
#### 4. View:
Create a view `paytm_form.php` in `application/views/paytm_form.php`:
“`html
“`
#### 5. Callback URL:
Create a controller method to handle the callback from Paytm:
“`php
public function callback()
{
// Handle the response from Paytm
// Verify the checksum and update the order status in your database
}
“`
### Notes:
– The actual implementation will require more detailed error handling and security checks.
– The Paytm library (`Paytm/checksum.php`) should be included in the `application/third_party` directory.
– The `YOUR_MERCHANT_ID`, `YOUR_MERCHANT_KEY`, `YOUR_WEBSITE_NAME`, `YOUR_INDUSTRY_TYPE`, `YOUR_ORDER_ID`, `CUSTOMER_ID`, `CUSTOMER_EMAIL`, and `CUSTOMER_MOBILE` placeholders should be replaced with actual values provided by Paytm.
– The `callback` method should be implemented to handle the response from Paytm and update the order status accordingly.
Remember to follow the guidelines and best practices provided by Paytm for secure integration.