Course Content
Introduction to CodeIgniter
CodeIgniter is a powerful PHP framework built for developers who need a simple and elegant toolkit to create full-featured web applications.
MVC (Model-View-Controller)
MVC stands for Model-View-Controller. MVC is an application design model consisting of three interconnected parts. They include the model (data), the view (user interface), and the controller (processes that handle input).
The Session class allows you to maintain a user’s "state" and track their activity while they browse your site.
URI Routing
There is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
Forms and Input
Forms provide a way for users to interact with the application and submit data.
Composer is dependency manager in PHP. it allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
You can enable CSRF protection by modifying your application/config/config.php file
Working with Database
Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides a rich set of functionalities to interact with the database.
DataTables is a table enhancing plug-in for the jQuery Javascript library that helps in adding sorting, paging, and filtering abilities to plain HTML tables with minimal effort. The main goal is to enhance the accessibility of data in normal HTML tables.
PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. Importing Excel and CSV into MySQL help to save the user time and avoid repetitive work.
Payment Gateway
Razorpay and PayTM Payment Gateway
WhatsApp Chatbot and Telegram Chatbot
CodeIgniter 3
About Lesson

RazorPay is a well-known payment gateway platform in India. Razorpay provides clean, secure, and fast payments services with hassle-free integration with developer-friendly APIs. It supports various payment modes such as Cards, Net-banking, Wallets & UPI.

Setup RazorPay Account

1. Add the following lines in config/autoload.php

$autoload['libraries'] = array('session', 'table', 'upload');
$autoload['helper'] = array('url', 'form', 'html', 'date');

2. Create a controller file Checkout.php in the applications/controllers/ directory.

defined('BASEPATH') OR exit('No direct script access allowed');

class Razorpay extends CI_Controller {

    public function index() {

    public function checkout() {
        $data['title']              = 'Checkout payment | Infovistar';  
        $data['callback_url']       = base_url().'razorpay/callback';
        $data['surl']               = base_url().'razorpay/success';;
        $data['furl']               = base_url().'razorpay/failed';;
        $data['currency_code']      = 'INR';
        $this->load->view('razorpay/checkout', $data);

    // initialized cURL Request
    private function curl_handler($payment_id, $amount)  {
        $url            = ''.
        $key_id         = "YOUR KEY ID";
        $key_secret     = "YOUR KEY SECRET";
        $fields_string  = "amount=$amount";
        //cURL Request
        $ch = curl_init();
        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERPWD, $key_id.':'.$key_secret);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        return $ch;
    // callback method
    public function callback() {   
        if (!empty($this->input->post('razorpay_payment_id')) && 
        !empty($this->input->post('merchant_order_id'))) {
            $razorpay_payment_id = $this->input->post('razorpay_payment_id');
            $merchant_order_id = $this->input->post('merchant_order_id');
            $currency_code = 'INR';
            $amount = $this->input->post('merchant_total');
            $success = false;
            $error = '';
            try {                
                $ch = $this->curl_handler($razorpay_payment_id, $amount);
                //execute post
                $result = curl_exec($ch);
                $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                if ($result === false) {
                    $success = false;
                    $error = 'Curl error: '.curl_error($ch);
                } else {
                    $response_array = json_decode($result, true);
                        //Check success response
                        if ($http_status === 200 and 
                            isset($response_array['error']) === false) {
                            $success = true;
                        } else {
                            $success = false;
                            if (!empty($response_array['error']['code'])) {
                                $error = $response_array['error']['code'].':'.
                            } else {
                                $error = 'RAZORPAY_ERROR:Invalid Response <br/>'.
                //close curl connection
            } catch (Exception $e) {
                $success = false;
                $error = 'Request to Razorpay Failed';
            if ($success === true) {
                if(!empty($this->session->userdata('ci_subscription_keys'))) {
                if (!$order_info['order_status_id']) {
                } else {

            } else {
        } else {
            echo 'An error occured. Contact site administrator, please!';
    public function success() {
        $data['title'] = 'Razorpay Success | TechArise';
        echo "<h4>Your transaction is successful</h4>";  
        echo "<br/>";
        echo "Transaction ID: ".$this->session->flashdata('razorpay_payment_id');
        echo "<br/>";
        echo "Order ID: ".$this->session->flashdata('merchant_order_id');
    public function failed() {
        $data['title'] = 'Razorpay Failed | TechArise';  
        echo "<h4>Your transaction got Failed</h4>";            
        echo "<br/>";
        echo "Transaction ID: ".$this->session->flashdata('razorpay_payment_id');
        echo "<br/>";
        echo "Order ID: ".$this->session->flashdata('merchant_order_id');

3. Create a checkout.php file in the applications/views/ directory.

<!DOCTYPE html>
<title>Razorpay Payment Gateway</title>

$description        = "Product Description";
$txnid              = date("YmdHis");     
$key_id             = "YOUR KEY ID";
$currency_code      = $currency_code;            
$total              = (1* 100); // 100 = 1 indian rupees
$amount             = 1;
$merchant_order_id  = "ABC-".date("YmdHis");
$card_holder_name   = 'Junaid Shaikh';
$email              = '';
$phone              = '9000000001';
$name               = "RazorPay Infovistar";

    <form name="razorpay-form" id="razorpay-form" 
    action="<?php echo $callback_url; ?>" method="POST">
        <input type="hidden" name="razorpay_payment_id" 
        id="razorpay_payment_id" />
        <input type="hidden" name="merchant_order_id" 
        id="merchant_order_id" value="<?php echo $merchant_order_id; ?>"/>
        <input type="hidden" name="merchant_trans_id" 
id="merchant_trans_id" value="<?php echo $txnid; ?>"/> <input type="hidden" name="merchant_product_info_id" id="merchant_product_info_id" value="<?php echo $description; ?>"/> <input type="hidden" name="merchant_surl_id" id="merchant_surl_id" value="<?php echo $surl; ?>"/> <input type="hidden" name="merchant_furl_id" id="merchant_furl_id" value="<?php echo $furl; ?>"/> <input type="hidden" name="card_holder_name_id" id="card_holder_name_id" value="<?php echo $card_holder_name; ?>"/> <input type="hidden" name="merchant_total" id="merchant_total" value="<?php echo $total; ?>"/> <input type="hidden" name="merchant_amount" id="merchant_amount" value="<?php echo $amount; ?>"/> </form> <table> <tr> <th>No.</th> <th>Product Name</th> <th>Cost</th> </tr> <tr> <td>1</td> <td>HeadPhones</td> <td>1 Rs</td> </tr> </table> <input id="pay-btn" type="submit" onclick="razorpaySubmit(this);" value="Pay Now" class="btn btn-primary" /> <script src=""> </script> <script> var options = { key: "<?php echo $key_id; ?>", amount: "<?php echo $total; ?>", name: "<?php echo $name; ?>", description: "Order # <?php echo $merchant_order_id; ?>", netbanking: true, currency: "<?php echo $currency_code; ?>", // INR prefill: { name: "<?php echo $card_holder_name; ?>", email: "<?php echo $email; ?>", contact: "<?php echo $phone; ?>" }, notes: { soolegal_order_id: "<?php echo $merchant_order_id; ?>", }, handler: function (transaction) { document.getElementById('razorpay_payment_id').value = transaction.razorpay_payment_id; document.getElementById('razorpay-form').submit(); }, "modal": { "ondismiss": function(){ location.reload() } } }; var razorpay_pay_btn, instance; function razorpaySubmit(el) { if(typeof Razorpay == 'undefined') { setTimeout(razorpaySubmit, 200); if(!razorpay_pay_btn && el) { razorpay_pay_btn = el; el.disabled = true; el.value = 'Please wait...'; } } else { if(!instance) { instance = new Razorpay(options); if(razorpay_pay_btn) { razorpay_pay_btn.disabled = false; razorpay_pay_btn.value = "Pay Now"; } }; } } </script> </body> </html>