Laravel 5.8 Razorpay Payment Gateway Integration

In this tutorial you will learn about the Laravel 5.8 Razorpay Payment Gateway Integration and its application with practical example.

Laravel 5.8 Razorpay Payment Gateway Integration

In this tutorial, you will learn to integrate Razorpay payment gateway in your laravel 5.8 project. Before starting with this tutorial you would require a Razorpay developer account, from there you will get the api key and secret key require for the integration. After the successful integration you will be able to collect payment via simple payment form which allow customer to provide card information like card number, expiry date and a CVC code. Follow this step by step tutorial to learn Razorpay payment gateway integration in laravel 5.8.

Install Laravel 5.8

First of all we need to create a fresh laravel project, download and install Laravel 5.8 using the below command

Configure Database In .env file

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.


Generate Application Key

Open terminal and switch to the project directory and run the following command to generate application key and configure cache.

Set Default String Length

Locate the file “app/Providers/AppServiceProvider”, and add following line of code to the top of the file

and inside the boot method set a default string length as given below –

So this is how “app/Providers/AppServiceProvider” file looks like –

Create Model and Migration

Now, we require to create a Payment tables to keep the payment records. so let’s run the following command to generate Payment model along with a migration file to create Payment table in our database.

Once the above command is executed a migration file Payments.php file is created, open the database/migrations/Payments.php file and put the following code in it.

Now, use the command to run migration –

Create Routes

After this, we need to add following routes in “routes/web.php” to display product listing, to store payment form and to payment acknowledgement. Lets open “routes/web.php” file and add following route.


Here, first route is for product listing, second is to store payments_id and users information provided by razorpay payment gateway.

Create Controller

Next, we have to create a controller to handle payments. Create a controller named RazorpayController using command given below –

Once the above command executed, it will create a controller file PaymentController.php in app/Http/Controllers/razorpay directory. Open the razorpay/PaymentController.php file and put the following code in it.


In this controller, we have following methods –

show_products() :- It lists Store Items

pay_success() :- To handle payment

thank_you() :- Payment Acknowledgement

Create Blade / View Files

In this step, we will create view/blade file to accept razorpay payment. Lets create two blade files “payment.blade.php” and “thankyou.blade.php” in “resources/views/razorpay/” directory and put the following code in it respectively.


You must replace secret key that you get from razorpay payment gateway here –


Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –




Click “Order Now” for any product of your choice



Use the following test card details to test the payment.

Test Credit Card Info :-

Card No :- 4242424242424242 / 4012888888881881
Month :- Any future month
Year :- Any future Year
CVV :- Any 3 digit Number

In this tutorial we have learn about the Laravel 5.8 Razorpay Payment Gateway Integration and its application with practical example. I hope you will like this tutorial.