Laravel 8 razorpay payment gateway integration example. In this tutorial, you will learn how to integrate a razorpay payment gateway in laravel 8 app.
In this laravel 8 razorpay payment gateway example tutorial, will use the javascript lib of the razorpay payment gateway for payment deduction.
And as well as, will implement a simple script code for payment deduction and payment success.
Before start tutorial, you need to create razorpay account and get secret app key from razorpay app. So, you can visit this link and create razorpay app.
In this step, download or install the latest laravel 8 app by using the following command, so open terminal and execute the following command:
composer create-project --prefer-dist laravel/laravel RazorpayDemo
In this step, visit laravel 8 app root directory and open .env file. Then add the database details:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here
In this step, create table name Payment and it’s migration file. use the below command.
php artisan make:model Payment -m
It command will create one model name Payment and also create one migration file for the Payment table. After successfully run the command go to database/migrations/Payments.php file and replace function, below here :
public function up()
{
Schema::create('payments', function (Blueprint $table) {
$table->increments('id');
$table->string('r_payment_id');
$table->string('product_id');
$table->string('user_id');
$table->string('amount');
$table->timestamps();
});
}
Next, migrate the table using the below command. It will create two new tables in the database.
php artisan migrate
In this step, create three routes and add on this routes in web.php file. So, visit /routes/web.php file and add the following routes in web.php:
use App\Http\Controllers\RazorpayController;
Route::get('product', [RazorpayController::class, 'index']);
Route::get('paysuccess', [RazorpayController::class, 'razorPaySuccess']);
Route::get('razor-thank-you', [RazorpayController::class, 'RazorThankYou']);
#laravel #javascript #php #web-development #developer