---
title: "How to Integrate Razorpay Payment Gateway in Laravel?"
url: "https://magecomp.com/blog/integrate-razorpay-payment-gateway-laravel/"
date: "2024-04-11T18:09:13+00:00"
modified: "2025-01-03T14:01:30+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "Laravel"
word_count: 542
reading_time: "3 min read"
summary: "Payment gateways have become an integral integration business nowadays in the digital age with which any business can make sure to complete online transactions perfectly. Among all the features, La..."
description: "Learn How to Integrate Razorpay Payment Gateway in Laravel"
keywords: "Laravel"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Laravel Introducing a New Utility Class: Number"
    url: "https://magecomp.com/blog/laravel-introducing-a-new-utility-class-number/"
  - title: "Laravel DDD: Implementing Domain-Driven Design Principles"
    url: "https://magecomp.com/blog/laravel-ddd-domain-driven-design-principles/"
  - title: "Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide"
    url: "https://magecomp.com/blog/generating-thumbnails-with-spatie-media-library-laravel-11/"
---

# How to Integrate Razorpay Payment Gateway in Laravel?

_Published: April 11, 2024_  
_Author: Bharat Desai_  

![How to Integrate Razorpay Payment Gateway in Laravel](https://magecomp.com/blog/wp-content/uploads/2024/04/How-to-Integrate-Razorpay-Payment-Gateway-in-Laravel-1024x512.webp)

Payment gateways have become an integral integration business nowadays in the digital age with which any business can make sure to complete online transactions perfectly. Among all the features, Laravel is known to handle multiple payment gateways very strongly. Out of all available options, one of the popular and developer-friendly payment gateway solutions for Indian businesses would be Razorpay. It guides through each and every step of integrating a payment gateway, Razorpay in the Laravel application to make the payment operation smooth and secure.
[![Laravel Development Services](https://magecomp.com/blog/wp-content/uploads/2024/12/Laravel-Development-Services-4.webp)](https://magecomp.com/services/laravel-development-services/)

## Steps to Integrate Razorpay Payment Gateway in Laravel:
### Step 1: Setting Up Razorpay Account
If you haven’t registered yet, register for your Razorpay account from first. After that registration, you’ll find API keys (Key ID and Key Secret) from your Razorpay dashboard. The API keys authenticate your Laravel application with the Razorpay services.
### Step 2: Installing Razorpay Package
With community-contributed packages, integration of Razorpay becomes a lot easier in Laravel. One such package is anandsiddharth/laravel-razorpay, which is a wrapper around Razorpay’s PHP SDK. You can install it via Composer:
```
composer require anandsiddharth/laravel-razorpay
```

After installation, don’t forget to publish the configuration file:
```
php artisan vendor:publish –provider="AnandLaravelRazorpayProvidersRazorpayServiceProvider"
```

### Step 3: Configuration
Open config/razorpay.php and enter your Razorpay API Key ID and Secret Key obtained from the Razorpay dashboard.
### Step 4: Creating Routes and Controllers
Set up routes to handle payment initiation and success/failure callbacks. For instance:
```
Route::post('/payment', 'PaymentController@create')->name('payment.create');
Route::post('/payment/success', 'PaymentController@success')->name('payment.success');
Route::post('/payment/failure', 'PaymentController@failure')->name('payment.failure');
```

Create a PaymentController using Artisan command:
```
php artisan make:controller PaymentController
```

Implement methods create, success, and failure in the PaymentController to handle payment initiation, success callback, and failure callback, respectively.
[![Hire laravel Developer](https://magecomp.com/blog/wp-content/uploads/2024/12/Hire-Laravel-Expert-Now-3.webp)](https://magecomp.com/services/hire-laravel-developer/)

### Step 5: Initiating Payment
In the create method of PaymentController, initiate the payment using Razorpay API:
```
use RazorpayApiApi;

public function create(Request $request)
{
    $api = new Api(config('razorpay.key'), config('razorpay.secret'));

    $order = $api->order->create([
        'receipt'         => 'order_rcptid_' . rand(),
        'amount'          => $request->amount * 100, // Amount in paisa
        'currency'        => 'INR',
        'payment_capture' => 1 // Auto capture payment
    ]);

    return view('payment')->with([
        'order' => $order,
        'key' => config('razorpay.key')
    ]);
}
```

### Step 6: Integrating Razorpay Checkout
Create a view (e.g., payment.blade.php) to render the payment form. Include Razorpay’s JavaScript SDK and initiate payment using the order ID obtained from the controller.
```
<form action="{{ route('payment.success') }}" method="POST">
    <script src="https://checkout.razorpay.com/v1/checkout.js" data-key="{{ $key }}"></script>
    <input type="hidden" name="order_id" value="{{ $order->id }}">
    <button type="submit">Pay Now</button>
</form>
```

### Step 7: Handling Callbacks
In the success and failure methods of PaymentController, handle the payment success and failure callbacks respectively.
## Conclusion:
Using a Razorpay payment gateway allows you to integrate it to your Laravel application, in an easy and safe way in online payments for your customers. The following steps will assist you with the smooth integration of Razorpay with your Laravel project and also kickstart hassle-free online payments through that app.
[![Contact Us](https://magecomp.com/blog/wp-content/uploads/2024/12/Contact-Us-3.webp)](https://magecomp.com/contact)

[**Connect with Laravel Developers**](https://magecomp.com/hire-laravel-developer.html) to seamlessly integrate payment methods for your web application.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/integrate-razorpay-payment-gateway-laravel/](https://magecomp.com/blog/integrate-razorpay-payment-gateway-laravel/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 08:49:09 UTC_  
