Laravel 8 - How to integrate Stripe Payment Gateway API with Example

Today we learn Stripe payment gateway integration in Laravel example. In this tutorial, we will show you how to utilize stripe payment gateway in laravel.

You will learn step by step integrate stripe payment gateway in laravel 8.

Stripe payment gateway is the most popular payment gateway which is integrated into many websites, Stripe payment is facile to integrate any website like e-commerce, etc. Stripe is a very simple and most puissant and flexible payment gateway.

Stripe Payment Gateway Integration In Laravel 8 With example

  • Step 1: Install Laravel 8 App
  • Step 2: Install stripe Package
  • Step 3: Stripe Configuration
  • Step 4: Make Route
  • Step 5: Create Controller
  • Step 6: Create a Blade View file
  • Step 7: Run Development Server

Step 1: Install Laravel 8 App

In this step, execute the following command on the terminal to install Laravel 8 app. So, Open the command prompt and execute the following command:

composer create-project --prefer-dist laravel/laravel stripe_payment_gateway

Step 2: Install Stripe Package

Install Stripe-php integration Laravel package in laravel 8 project by executing the following command on terminal:

composer require stripe/stripe-php

After that, you need to set the stripe key and secret. So, visit on Stripe website and create a development stripe account. And get key and secret from

Step 3: Stripe Configuration

Now open the .evn file and set the secret credential provided by a stripe payment gateway


Next step, you need to set up the Stripe API key, open or create the config/services.php file, and add or update the 'stripe' array:

'stripe' => [
     'secret' => env('STRIPE_SECRET'),

Step 4: Make Route

In this step, open the web.php file, which is placed inside the routes directory. And add the following routes into it:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StripeController;
| 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('stripe', [StripeController::class, 'stripe']);
Route::post('stripe', [StripeController::class, 'stripePost'])->name('');

Step 5: Create Controller

In this step, execute the following command on the terminal to create the controller name StripeController. We learn Stripe-php integration Laravel.

php artisan make:controller StripeController

Then go app/Http/Controllers/ directory and open StripeController. Then add the following code into StripeController.php.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Session;
use Stripe;
class StripeController extends Controller
     * success response method.
     * @return \Illuminate\Http\Response
    public function stripe()
        return view('stripe');
     * success response method.
     * @return \Illuminate\Http\Response
    public function stripePost(Request $request)
        Stripe\Charge::create ([
                "amount" => 100 * 100,
                "currency" => "usd",
                "source" => $request->stripeToken,
                "description" => "This payment is tested purpose"
        Session::flash('success', 'Payment successful!');
        return back();

Step 6: Create Blade View File

In this step, Visit app/resources/views/ and create one blade view file name stripe.blade.php. Then add the following code into the Stripe.blade.php file:

<!DOCTYPE html>
      <title>Stripe Payment Page - HackTheStuff</title>
      <link rel="stylesheet" href="">
      <script src=""></script>
      <style type="text/css">
         .panel-title {
         display: inline;
         font-weight: bold;
         .display-table {
         display: table;
         .display-tr {
         display: table-row;
         .display-td {
         display: table-cell;
         vertical-align: middle;
         width: 61%;
      <div class="container">
         <h1>Stripe Payment Page - HackTheStuff</h1>
         <div class="row">
            <div class="col-md-6 col-md-offset-3">
               <div class="panel panel-default credit-card-box">
                  <div class="panel-heading display-table" >
                     <div class="row display-tr" >
                        <h3 class="panel-title display-td" >Payment Details</h3>
                        <div class="display-td" >                            
                           <img class="img-responsive pull-right" src="">
                  <div class="panel-body">
                     @if (Session::has('success'))
                     <div class="alert alert-success text-center">
                        <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                        <p>{{ Session::get('success') }}</p>
                        action="{{ route('') }}"
                        data-stripe-publishable-key="{{ env('STRIPE_KEY') }}"
                        <div class='form-row row'>
                           <div class='col-xs-12 form-group required'>
                              <label class='control-label'>Name on Card</label> <input
                                 class='form-control' size='4' type='text'>
                        <div class='form-row row'>
                           <div class='col-xs-12 form-group card required'>
                              <label class='control-label'>Card Number</label> <input
                                 autocomplete='off' class='form-control card-number' size='20'
                        <div class='form-row row'>
                           <div class='col-xs-12 col-md-4 form-group cvc required'>
                              <label class='control-label'>CVC</label> <input autocomplete='off'
                                 class='form-control card-cvc' placeholder='ex. 311' size='4'
                           <div class='col-xs-12 col-md-4 form-group expiration required'>
                              <label class='control-label'>Expiration Month</label> <input
                                 class='form-control card-expiry-month' placeholder='MM' size='2'
                           <div class='col-xs-12 col-md-4 form-group expiration required'>
                              <label class='control-label'>Expiration Year</label> <input
                                 class='form-control card-expiry-year' placeholder='YYYY' size='4'
                        <div class='form-row row'>
                           <div class='col-md-12 error form-group hide'>
                              <div class='alert-danger alert'>Please correct the errors and try
                        <div class="row">
                           <div class="col-xs-12">
                              <button class="btn btn-primary btn-lg btn-block" type="submit">Pay Now ($100)</button>
   <script type="text/javascript" src=""></script>
   <script type="text/javascript">
      $(function() {
    var $form = $(".require-validation");
    $('form.require-validation').bind('submit', function(e) {
        var $form = $(".require-validation"),
            inputSelector = ['input[type=email]', 'input[type=password]',
                'input[type=text]', 'input[type=file]',
            ].join(', '),
            $inputs = $form.find('.required').find(inputSelector),
            $errorMessage = $form.find('div.error'),
            valid = true;
        $inputs.each(function(i, el) {
            var $input = $(el);
            if ($input.val() === '') {
        if (!$'cc-on-file')) {
                number: $('.card-number').val(),
                cvc: $('.card-cvc').val(),
                exp_month: $('.card-expiry-month').val(),
                exp_year: $('.card-expiry-year').val()
            }, stripeResponseHandler);
    function stripeResponseHandler(status, response) {
        if (response.error) {
        } else {
            /* token contains id, last4, and card type */
            var token = response['id'];
            $form.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");

Step 7: Run Development Server

In this step, execute the PHP artisan serve command on the terminal to start the development server:

php artisan serve

If you want to run the project different port so use this below command

php artisan serve --port=8080

Testing Card Credential

Card No: 4242424242424242
Month: any future month
Year: any future Year
CVV: 123

Stripe payment gateway integration in laravel 8 tutorial with example, you have learned how to integrate the stripe payment gateway in laravel 8.

i hope you like this article.