Laravel 11 Razorpay Payment Gateway Integration Example

By Hardik Savani April 26, 2024 Category : Laravel

In this tutorial, we will learn how to use the Razorpay payment gateway in laravel 11 application.

Razorpay is an Indian online payment gateway company that offers a range of payment processing solutions for businesses of all sizes. It was founded in 2014 and has quickly become one of the most popular payment gateway providers in India. Razorpay provides businesses with a simple and secure way to accept online payments through various payment channels such as credit cards, debit cards, net banking, UPI, and digital wallets. They also offer easy integration with popular e-commerce platforms such as Shopify, WooCommerce, Magento, and more.

In this example, we will simply install the "razorpay/razorpay" composer package for payment API. Then we will create one form with a "Pay 10 INR" button, and the user will pay by clicking on the button. After payment is successful, the user will see a success message on the page. So, let's follow the below steps:


laravel 11 install razorpay

Step for How to use Razorpay Payment Gateway in Laravel 11?

  • Step 1: Install Laravel 11
  • Step 2: Create Razorpay Account
  • Step 3: Install razorpay/razorpay Package
  • Step 4: Create Route
  • Step 5: Create Controller
  • Step 6: Create Blade File
  • Run Laravel App

Step 1: Install Laravel 11

This step is not required; however, if you have not created the Laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 2: Create Razorpay Account

First you need to create account on razorpay. then you can easily get account key id and key secret.

Create Account from here:

After register successfully. you need to go bellow link and get id and secret as bellow screen shot:

Go Here:

Next you can get account key id and secret and add on .env file as like bellow:



Step 3: Install razorpay/razorpay Package

In this step, we need to install the Razorpay/Razorpay Composer package to use the Razorpay API. So let's run the below 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 below:


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

In this step, we will create RazorpayPaymentController and write send SMS logic, so let's add a new route to the web.php file as below:


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

Now we need to add a Blade file. So let's create a `razorpay.blade.php` file and put the code below:


<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel - Razorpay Payment Gateway Integration</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">Laravel 11 Razorpay Payment Gateway Integration -</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"

Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:



you can get testing card for razorpay from here: Click Here

Now you can run and check.

I hope it can help you...