How to integrate Stripe payment gateway in laravel

How to integrate Stripe payment gateway in laravel

Hello Laravel enthusiasts, welcome back. Here I am going to discuss something very exciting. You will know how to integrate Stripe payment gateway in Laravel applications.

Working Demo      Project on Github

You can also watch the video on YouTube here

Why Stripe?

There are so many payment gateways available, one of the most popular gateways is PayPal, but Stripe has some advantages over PayPal –  simple, hassle-free, easier integration, setup, maintenance, and the seamless checkout experience. Moreover integrating stripe with Laravel is a breeze.

We just need a payment form which collects card information like card number, expiry date, and a CVC code. When these details are sent to stripe it validates and returns a token which is used to process the payment.

I also made a post on PayPal payment gateway integration, check how to integrate PayPal payment gateway integration here.

Getting started with Stripe

  • First, we need to register with stripe, go to and register yourself there.
  • Now get the public and private keys from your account which are provided in your account settings.
  • Make sure you set your account as a test account so that real transactions do not occur.

So now let’s install stripe in our Laravel app,  here I will install it using composer.

While in test mode, we cannot use genuine card information, so it provides us with some test cards,


Payment form

As said earlier, we need a form to collect some data. There are many ready-made awesome stripe payment form, we will grab one and use it here.

The form I used here is from

We modify this form a bit to fit Laravel environment. The form is as below,

Double the learning and saving. Buy 1 Get 1 on premium e-degrees


We place the public key of our stripe account in the data attribute which we use later for processing the payment process.

Validation part

The payment form which we used, has some validation to it,



Working Demo      Project on Github

Generate a token

Here, when the submit button is clicked, we do not actually submit the form, we first generate a stripe token which processes the payment and then uses that token to Charge the user with the specified amount.

Now we get the card number, expiry month, expiry year and CVC code and with these details, the stripe generates a token.

Now in this stripeResponseHandler function, append the token which we got to the form input field,

now the form gets submitted and will call to the action specified in the form action.

Stripe Charge

When the form is submitted, it calls the following action.

We show, if any, success and error messages and redirect back to the main page.

As we show in the form that we charge $300, here we set the currency to 300 * 100. We multiply by 100 because the default currency unit in Stripe is cent.

Here this tutorial is just a simple tutorial, so we set a static amount, also did not use any database to save the transaction details.

If we need to save those details we can save then in the above function and also can get the amount value from the form.



This is how the dashboard looks,


Working Demo      Project on Github

Videos: Working Demo and Code Explanation

You can watch this playlist on YouTube here.

Also please feel free to look at other payment gateway implementations like PayPal payment gateway Integration and all other posts here.

5 thoughts on “How to integrate Stripe payment gateway in laravel”

  • 1
    Steve Shaw on April 3, 2019 Reply

    Thanks for this excellent tutorial, Avinash—looking forward to putting it into action. Do you have any info on using Stripe for subscription payments, rather than one-off payments?

  • 2 on June 19, 2019 Reply

    hello, thanks for this tutorial, these cards are still working ?

  • 3
    Michael Babowal on January 1, 2020 Reply

    Can you integrate both PayPal and Stripe into Laravel and allow the admin to select which payment processor they want to use?

    • 4
      avinash on January 2, 2020 Reply

      Yes, it is possible.
      First integrate both of them, now based upon the option enabled use the respective gateway to proceed with a transaction.

  • 5
    paresh on September 17, 2020 Reply

    How can we add the Google Pay,Apple Pay and net-banking option into this code? please suggest.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.