Laravel 9 Stripe Payment Gateway Integration Example
Integration of the Stripe payment gateway in Laravel 9; I'll demonstrate how to include Stripe payment gateway into Laravel 9 apps in this tutorial.
For payment deduction in this tutorial's Laravel 9 application, I'll utilize the jQuery, ajax, and stripe JavaScript libraries. Additionally, the Laravel 9 app will make an ajax request to deduct money and store payment details in the database.
Step 1 – Installing Laravel 9 Application
Step 2 – Create account in Stripe and generate key and secret
Step 3 – Install Stripe package And Configure
Step 4 – Database and Stripe Key Configuration
Step 5 – Creating Payment Model & Migration
Step 6 – Create Routes
Step 7 – Creating Stripe Controller
Step 8 – Create Directory and Blade View
Step 9 – Start Development Server
Step 10 – Run This App On Browser
Step 1 – Installing Laravel 9 Application
Launch your terminal and use the following command to browse to your local web server directory:
//for windows user
cd xampp/htdocs
//for ubuntu user
cd var/www/html
the most recent Laravel application by running the command:
composer create-project --prefer-dist laravel/laravel blog
Step 2 – Create account in Stripe and generate key and secret
Create a Stripe account in step two. then create a secret and key.
Step 3 – Install Stripe package And Configure
Launch the terminal and enter the following command to install the Stripe package in the Laravel application:
composer require cartalyst/stripe-laravel
Then, in app.php, which is found in the config directory, configure the stripe package:
'providers' => ,
'aliases' => ,
Step 4 – Database and Stripe Key Configuration
In step 4, launch the Laravel app you downloaded into any text editor. Then locate the .env file and specify the database information, the stripe key, and the secret as follows:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db name
DB_USERNAME=db user name
DB_PASSWORD=db password
STRIPE_KEY=pk_test_xxxxxxxxxxxxxxxxxxx
STRIPE_SECRET=sk_test_xxxxxxxxxxxxxx
The Stripe API key needs to be configured next; to do this, edit or create the config/services.php file and add or update the'stripe' array:
'stripe' => ,
Step 5 – Creating Payment Model & Migration
use the terminal to run the following command to create the model and migration file:
php artisan make:model Payment -m
The aforementioned command will produce two files in the following locations in your laravel stripe payment gateway integration tutorial app:
- /app/Models/Payment.php
- /database/migrations/create_payments_table.php
Consequently, locate the create payments table.php file in the migrations directory of your database. Open this file, and then add the following code to the method up().
public function up()
{
Schema::create('payments', function (Blueprint $table) {
$table->id();
$table->string('s_payment_id'); // stripe payment id
$table->string('user_id');
$table->string('product_id');
$table->string('amount');
$table->timestamps();
});
}
Open your terminal once more, and then type the following command on cmd to create tables in the database of your choice:
php artisan migrate
Open your web.php file, which may be found in the routes directory, in step 6. Add the following routes to the web.php file after that:
use AppHttpControllersStripeController;
Route::get('stripe', );
Route::post('payment-process', );
Step 7 – Creating Stripe Controller
The command to create a Stripe Payment Controller is:
php artisan make:controller StripeController
The StripeController.php file, which is found in the /app/Http/Controllers/ directory, will be created by the aforementioned command.
Enter the following code into the StripeController.php file by opening it:
Read the full article