Laravel Stripe Payment Gateway Integration Example Tutorial

Laravel Stripe Payment Gateway Integration Example Tutorial

Laravel 6 stripe payment gateway integration example tutorial. This tutorial demonstrates to you, how you can integrate stripe payment gateway in your laravel based projects or application. This example tutorial also work with laravel 7.x version.

In this tutorial, we’ll discuss step by step how to integrate stripe payment gateway in our laravel version 6 based project. Stripe is the most popular payment gateway which is integrated into many websites, Stripe payment is easy to integrate and use. Stripe is a very simple and most powerful and flexible tool.

Laravel Stripe Payment Gateway Integration Example Tutorial

Just follow the below steps and you can easily integrate stripe payment gateway in your laravel based application:

  • Install Laravel Fresh Setup
  • Install stripe Package
  • Set Secret Credential
  • Generate Migration and Create Model
  • Make Route
  • Create Controller
  • Create Blade View file
  • Conclusion

Install Laravel Fresh Project

We need to install Laravel fresh application using below command, Open your command prompt and run the below command :

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

Install Stripe package

composer require cartalyst/stripe-laravel

After that, we need to register the provider and aliases. Go to the app/config/app.php and put the below lines here :

‘providers’ => [
‘aliases’ => [
 'Stripe' => Cartalyst\Stripe\Laravel\Facades\Stripe::class 

Set Secret Credential

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


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

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

Make Route

 Route::get('stripe', '[email protected]');
 Route::post('store', '[email protected]'); 

Create Controller

In this step, we need to create the controller name StripeController using the below command.

php artisan make:controller StripeController

Go to app/Http/Controller/StripeController and put the below code :

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Redirect,Response,Stripe;
class StripeController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index()
        return view('stripe');
     * Store a newly created resource in storage.
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
    public function store(Request $request)
        $stripe = Stripe::charges()->create([
            'source' => $request->get('tokenId'),
            'currency' => 'USD',
            'amount' => $request->get('amount') * 100
        return $stripe;

Create Blade View file

We need to create blade views file, Go to app/resources/views/ and create one file name stripe.blade.php. After that you can put your publisher key id in views file:

<!DOCTYPE html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <title>Laravel 6 Stripe Payment Gateway Integration -</title>
  <link rel="stylesheet" href="" />
  <script src=""></script>
    padding: 0.5%;
  <div class="container">
   <div class="row">
      <div class="col-md-12"><pre id="token_response"></pre></div>
    <div class="row">
      <div class="col-md-4">
        <button class="btn btn-primary btn-block" onclick="pay(10)">Pay $10</button>
      <div class="col-md-4">
        <button class="btn btn-success btn-block" onclick="pay(50)">Pay $50</button>
      <div class="col-md-4">
        <button class="btn btn-info btn-block" onclick="pay(100)">Pay $100</button>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script type="text/javascript">
  $(document).ready(function () {  
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  function pay(amount) {
    var handler = StripeCheckout.configure({
      key: 'pk_test_5f6jfFP2ZV5U9TXQYG0vtqFJ00eFVWNoRX', // your publisher key id
      locale: 'auto',
      token: function (token) {
        // You can access the token ID with ``.
        // Get the token ID to your server-side code for use.
        console.log('Token Created!!');
          url: '{{ url("store") }}',
          method: 'post',
          data: { tokenId:, amount: amount },
          success: (response) => {
          error: (error) => {
            alert('Oops! Something went wrong')
      name: 'Demo Site',
      description: '2 widgets',
      amount: amount * 100

In this tutorial, we will use the Striped JS library to create a token. When the user hits any of the above buttons our payment () function is called and here we will initialize the striped object and open the stripe popup. Popup will be the default popup of Stripe. You do not have to worry about verification and the security bar will handle everything for you.

Run Development Server

In this step, we will use the PHP artisan serve command. It will start your server locally

php artisan serve

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

php artisan serve --port=8080

Now we are ready to run our example so run bellow command to quick run.


Or direct hit in your browser


Testing Card Credential

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


In this tutorial, We have successfully integrated the stripe payment gateway in laravel 6 Application. Our examples run quickly.

You may like

  1. Razorpay Payment Gateway Integration In Laravel 6
  2. Laravel 6 Instamojo Payment Gateway Integration Example
  3. Laravel 6 Paytm Payment Gateway Integration E.g. Tutorial
  4. Angular 8 – Stripe Payment Gateway Example

If you have any questions or thoughts to share, use the comment form below to reach us.

Leave a Reply

Your email address will not be published. Required fields are marked *