Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Codeigniter Razorpay payment gateway Integrate Example

Codeigniter Razorpay payment gateway Integrate Example

Posted on June 13, 2018December 17, 2022 By XpertPhp No Comments on Codeigniter Razorpay payment gateway Integrate Example

In this tutorial, we will tell you how to integrate Razorpay payment gateway in Codeigniter Framework(Codeigniter Razorpay payment gateway integrate example).

The Razorpay payment gateway is a popular payment gateway method in India and it is easily used for the project. so many developers prefer that payment gateway method.

Razorpay provides two environments for the user like a Test mode and a lives mode and it allows online payment transactions like Cards, Net-banking, Wallets & UPI. Developer Friendly API, Fast On-boarding, and No Setup.

Overview

Step 1: Create Database Tables
Step 2: Connect to Database
Step 3: Get and Set RAZOR API Key and SECRET
Step 4: Create Controller
Step 5: Create View File

Step 1: Create Database Tables
In this step, we have to create a table in the database, so we will create a database using the below code.

1
2
3
4
5
6
7
8
CREATE TABLE `orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`payment_id` int(11) NOT NULL,
`amount` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Step 2: Connect to Database
Go to the config folder and open database.php file some changes in this file like hostname, database username, database password, and database name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'enter here database name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

Step 3: Get and Set RAZOR API Key and SECRET
In this step, we have to need the API Key and SECRET Key. so we will go to the official Razor site and after then login gets API Key and SECRET Key.
Step 3: Create Controller

In this step, we will create a Razor.php file in the “application/controller” directory and paste the below code in this controller.
application/controller/Razor.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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
  
class Razor extends CI_Controller {
  
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper(array('url','html','form'));
            
    }
  
    public function index()
    {
        $this->load->view('product_list');
    }  
    public function razor_payment_success()
    {
     $data = [
               'user_id' => '1',
               'product_id' => $this->input->post('product_id'),
               'payment_id' => $this->input->post('razorpay_payment_id'),
               'amount' => $this->input->post('totalAmount')
            ];
     $insert = $this->db->insert('payments', $data);
     $arr = array('msg' => 'Payment successfully credited', 'status' => true);  
    }
    public function razor_payment_thankyou()
    {
$this->load->view('razor_thankyou');
    }
}

Step 4: Create View File

So finally, we will create the product_list.php and razor_thankyou.php file in the “application/views/” directory.
application/views/product_list.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
<!DOCTYPE html>
<html lang="en">
<head>
  <title>how to Integrate Razorpay payment gateway in Codeigniter - XpertPhp</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.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-4">
        <h4>Product 1</h4>
        <h5>500 Rs.</h5>
     <a href="javascript:void(0)" class="btn btn-sm btn-primary buy_now" data-amount="500" data-id="1" data-product="Product 1">Order Now</a>
    </div>
    <div class="col-sm-4">
        <h4>Product 2</h4>
        <h5>1000 Rs.</h5>
     <a href="javascript:void(0)" class="btn btn-sm btn-primary buy_now" data-amount="1000" data-id="2" data-product="Product 2">Order Now</a>
    </div>
    <div class="col-sm-4">
        <h4>Product 3</h4>
        <h5>1500 Rs.</h5>
     <a href="javascript:void(0)" class="btn btn-sm btn-primary buy_now" data-amount="1500" data-id="3" data-product="Product 3">Order Now</a>
    </div>
  </div>
</div>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
$('body').on('click', '.buy_now', function(e){
    var totalAmount = $(this).attr("data-amount");
    var product_id =  $(this).attr("data-id");
    var product_name =  $(this).attr("data-product");
    var options = {
    "key": "YOUR_KEY_ID",
    "currency": "INR",
    "amount": totalAmount,
    "name": product_name,
    "description": "Test Transaction",
    "handler": function (response){
          $.ajax({
            url: '<?php echo base_url() ?>'+'payment/razorPaySuccess',
            type: 'post',
            dataType: 'json',
            data: {
                razorpay_payment_id: response.razorpay_payment_id , totalAmount : totalAmount ,product_id : product_id,
            },
            success: function (msg) {
               window.location.href = '<?php echo base_url() ?>'+'payment/RazorThankYou';
            }
        });
    },
    "theme": {
        "color": "#F37254"
    }
};
var rzp1 = new Razorpay(options);
document.getElementById('rzp-button1').onclick = function(e){
    rzp1.open();
    e.preventDefault();
}
</script>
</body>
</html>
See also  Autocomplete Textbox in CodeIgniter using Typeahead

application/views/razor_thankyou.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<html lang="en">
<head>
  <title>how to Integrate Razorpay payment gateway in Codeigniter - XpertPhp</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.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-12">
<h2 style="text-align:center;">Thank You For Payment</h2>
    </div>
  </div>
</div>
</body>
</html>

Codeigniter, MySql

Post navigation

Previous Post: PHP Image Upload With Validation Example
Next Post: PHP number_format() Function

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Angular 15 CRUD Application Example Tutorial
  • Laravel 10 Form Validation Example Tutorial
  • Angular 15 Custom Form Validation Example
  • Laravel 10 Send Email Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com