Laravel 8 Razorpay Payment Gateway Integration Example

Hello Artisan,

In this Razorpay integration Laravel example tutorial, I will show you step by step that how we can integrate the Razorpay payment gateway in the Laravel 8 application. This tutorial will work in Laravel 5, 6, 7, 8 applications. So from this Razorpay payment gateway integration in Laravel tutorial, you will learn it from scratch.

By following this tutorial, we can easily integrate Razorpay payment gateway in Laravel 5, laravel 6, Laravel 7, and Laravel 8 applications. You know that Razorpay payment gateway is a complete package for online payment in India. So if you don't know how to integrate this Razorpay payment gateway then this example is for you.


Step 1: Download Laravel

As we are going to start from scratch, so we need a fresh Laravel application. So download a fresh Laravel application. 

composer create-project --prefer-dist laravel/laravel blog


Step 2: Create Razorpay Account

First, you need to create an account on Razorpay. then you can easily get the account key id and key secret. Create an Account from here: 

After registering successfully. you need to go below link and get id and secret as below from this link

Now update your .env like that:




Step 3: Install razorpay/razorpay Package

Having completed the above step, we need to install razorpay/razorpay composer package to use Razorpay API. so let's run bellow command:

composer require razorpay/razorpay


Step 4: Create Route

Now we will create one route for calling our example, so let's add a new route to the web.php file as bellow:


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RazorpayPaymentController;
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
Route::get('razorpay-payment', [RazorpayPaymentController::class, 'index']);
Route::post('razorpay-payment', [RazorpayPaymentController::class, 'store'])->name('');


Step 5: Create Controller

In this step, we will create a controller and write payment logic like below:


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Razorpay\Api\Api;
use Session;
use Exception;
class RazorpayPaymentController extends Controller
     * Write code on Method
     * @return response()
    public function index()
        return view('razorpayView');
     * Write code on Method
     * @return response()
    public function store(Request $request)
        $input = $request->all();
        $api = new Api(env('RAZORPAY_KEY'), env('RAZORPAY_SECRET'));
        $payment = $api->payment->fetch($input['razorpay_payment_id']);
        if(count($input)  && !empty($input['razorpay_payment_id'])) {
            try {
                $response = $api->payment->fetch($input['razorpay_payment_id'])->capture(array('amount'=>$payment['amount'])); 
            } catch (Exception $e) {
                return  $e->getMessage();
                return redirect()->back();
        Session::put('success', 'Payment successful');
        return redirect()->back();


Step 6: Create Blade File

All are almost set to go. Just now we need to add a blade file. so let's create razorpayView.blade.php file and put bellow code:



Visit this link and you can get a testing card for Razorpay from here: Click Here


Read also: How to Integrate PayPal in Laravel 8 Tutorial


Hope this Razorpay payment gateway integration tutorial will help you.


Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js