Integrate Razorpay Payment Gateway in Laravel 11

Hello developers! In this guide, we'll see how to integrate the razorpay payment gateway in laravel 11. Here, we'll learn about the laravel 11 razorpay payment gateway with step by step guide. Additionally, we'll use razorpay/razorpay composer package.

Razorpay is the only payment solution in India that allows businesses to accept, process, and disburse payments with its product suite. Razorpay provides many functionalities like payments, banking, payroll, etc.

Additionally, you have multiple choices of payment such as credit card, debit card, UPI, net banking, etc.

Integrate Razor Payment Gateway in Laravel 11


Step 1: Install Laravel 11 Application

In this step, we'll install the laravel 11 application using the following command.

composer create-project laravel/laravel laravel-11-razorpay


Step 2: Create a Razorpay Account

Then, create a Razorpay account and get a secret key and a public key.

Create a Razorpay Account:

After that, get the ID and key from the given link:

Laravel 11 Razorpay Payment Gateway API Key




Step 3: Install razorpay/razorpay Package

 Next, we'll install razorpay/razorpay package using the composer command.

composer require razorpay/razorpay



Step 4: Define Route

Then, we'll define routes into the web.php file


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RazorpayPaymentController;
Route::get('razorpay-payment', [RazorpayPaymentController::class, 'index']);
Route::post('razorpay-payment', [RazorpayPaymentController::class, 'store'])->name('');


Step 5: Create Controller

Now, we'll create a controller using the following command.

php artisan make:controller RazorpayPaymentController


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Razorpay\Api\Api;
use Exception;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
class RazorpayPaymentController extends Controller
     * Write code on Method
     * @return response()
    public function index(): View
        return view('razorpay');
     * Write code on Method
     * @return response()
    public function store(Request $request): RedirectResponse
        $input = $request->all();
        $api = new Api(env('RAZORPAY_KEY'), env('RAZORPAY_SECRET'));
        $payment = $api->payment->fetch($input['razorpay_payment_id']);
        if(!empty($input['razorpay_payment_id'])) {

            try {
                $response = $api->payment->fetch($input['razorpay_payment_id'])
            } catch (Exception $e) {
                return redirect()->back()
                                 ->with('error', $e->getMessage());

        return redirect()->back()
                         ->with('success', 'Payment successful');


Step 6: Create Blade File

Next, create razorpay.blade.php file. and add the HTML code Razorpay payment gateway.


<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Integrate Razorpay Payment Gateway in Laravel 11 - Techsolutionstuff</title>
    <script src="" crossorigin="anonymous"></script>
    <link href="" rel="stylesheet" crossorigin="anonymous">

<div class="container">

    <div class="card mt-5">
        <h3 class="card-header p-3">Integrate Razorpay Payment Gateway in Laravel 11 - Techsolutionstuff</h3>
        <div class="card-body">

                <div class="alert alert-danger" role="alert"> 
                    {{ $value }}

                <div class="alert alert-success" role="alert"> 
                    {{ $value }}

            <form action="{{ route('') }}" method="POST" class="text-center">
                <script src=""
                        data-key="{{ env('RAZORPAY_KEY') }}"
                        data-buttontext="Pay 10 INR"
                        data-description="razorpay payment testing"
                        data image=""



Step 7: Run the Laravel 11 Application

Now, run the laravel 11 application using the following command.

php artisan serve
Visa Card No: 4111111111111111

Mobile No: 9876543210

OTP No: *****


Razorpay payment gateway dashboard



You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.