Razorpay Payment Gateway Integration in Laravel 12 (2026) Step-by-Step Guide

  • 17-03-2026
  • 128
  • Laravel 12
  • Haresh Chauhan

Razorpay Payment Gateway Integration in Laravel; In this post, we will integrate Razorpay in our Laravel application. Razorpay is one of the most popular payment gateway platforms in India that allows developers to easily integrate secure online payments into their web applications. It supports UPI, Credit Card, Debit Card, Net Banking, and Wallet payments.

To integrate the Razorpay payment gateway into a Laravel application, you need to create a Razorpay account and get API credentials such as Key ID and Key Secret from the Razorpay dashboard.

Razorpay provides a powerful API (Application Programming Interface) that helps developers accept payments, capture transactions, and manage refunds easily. Integrating Razorpay into your Laravel project enables seamless digital payment processing.

Below, I will explain step-by-step how to integrate Razorpay Payment Gateway into a Laravel application:

Step 1. Install Razorpay Package

First, install Razorpay PHP SDK in your Laravel project using Composer:

composer require razorpay/razorpay

Step 2. Make Routes

Create routes in your web.php file to handle payment request and response:

routes/web.php
use App\Http\Controllers\RazorpayController;

Route::get('razorpay', [RazorpayController::class, 'index']);
Route::post('razorpay-payment', [RazorpayController::class, 'payment'])->name('razorpay.payment');

Step 3. Create Controller

Create RazorpayController using the artisan command:

php artisan make:controller RazorpayController

Now add the following code in your controller file:

app\Http\Controllers\RazorpayController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Razorpay\Api\Api;

class RazorpayController extends Controller
{
    public function index()
    {
        return view('razorpay');
    }

    public function payment(Request $request)
    {
        $api = new Api(env('RAZORPAY_KEY'), env('RAZORPAY_SECRET'));

        $payment = $api->payment->fetch($request->razorpay_payment_id);

        if(count($request->all())  && !empty($request->razorpay_payment_id)) {
            try {
                $response = $api->payment->fetch($request->razorpay_payment_id)->capture([
                    'amount' => $payment['amount']
                ]);

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

            } catch (\Exception $e) {
                return redirect()->back()->with('error',$e->getMessage());
            }
        }
    }
}

Step 4. Create Blade File

Create a Razorpay payment button in your Blade file:

resources/views/razorpay.blade.php
<form action="{{ route('razorpay.payment') }}" method="POST">
    @csrf
    <script src="https://checkout.razorpay.com/v1/checkout.js"
            data-key="{{ env('RAZORPAY_KEY') }}"
            data-amount="50000"
            data-buttontext="Pay Now"
            data-name="Your Company"
            data-description="Test Payment"
            data-theme.color="#3399cc">
    </script>
</form>

Step 5. Add API Keys

Add Razorpay credentials in your .env file:

RAZORPAY_KEY=your_key_here
RAZORPAY_SECRET=your_secret_here

After completing all steps, you can test the payment gateway using Razorpay test mode. Once everything works fine, switch to live mode.

Razorpay integration in Laravel is very simple and secure. You can extend this functionality to subscriptions, refunds, and webhooks.

I hope you like this Razorpay Payment Gateway Integration tutorial in Laravel.


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :