Laravel 10 Razorpay Payment Gateway Integration Example

By Hardik Savani November 5, 2023 Category : Laravel

Hey Friends,

Today, I will let you know example of razorpay payment gateway integration in laravel 10. I would like to show you laravel 10 razorpay pay payment example. It's a simple example of laravel 10 razorpay integration. you will learn razorpay integration in laravel 10. Alright, let us dive into the details.

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.

so if you want to implement Razorpay integration in your laravel app then you can do it by following below few steps. you can see the below preview too:


Step 1: Install Laravel 10

This is optional; 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 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 new route to 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 RazorpayPaymentController and write send sms logic, so let's add new route to web.php file as bellow:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Razorpay\Api\Api;

use Session;

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('razorpayView');



* 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(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

now we need to add blade file. so let's create razorpayView.blade.php file and put bellow code:


<!DOCTYPE html>

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">


<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- CSRF Token -->

<meta name="csrf-token" content="{{ csrf_token() }}">

<title>Laravel - Razorpay Payment Gateway Integration</title>

<script src="" crossorigin="anonymous"></script>

<link rel="stylesheet" href="" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">



<div id="app">

<main class="py-4">

<div class="container">

<div class="row">

<div class="col-md-6 offset-3 col-md-offset-6">

@if($message = Session::get('error'))

<div class="alert alert-danger alert-dismissible fade in" role="alert">

<button type="button" class="close" data-dismiss="alert" aria-label="Close">

<span aria-hidden="true">×</span>


<strong>Error!</strong> {{ $message }}



@if($message = Session::get('success'))

<div class="alert alert-success alert-dismissible fade {{ Session::has('success') ? 'show' : 'in' }}" role="alert">

<button type="button" class="close" data-dismiss="alert" aria-label="Close">

<span aria-hidden="true">×</span>


<strong>Success!</strong> {{ $message }}



<div class="card card-default">

<div class="card-header">

Laravel - Razorpay Payment Gateway Integration


<div class="card-body text-center">

<form action="{{ route('') }}" method="POST" >


<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...