Logo

Arcocia Tech Unipessoal LDA is Loading ...

Have Patience

Integrate Stripe Payment Gateway in Laravel Application

Integrate Stripe Payment Gateway in Laravel Application

How to integrate Stripe Payment Gateway in Laravel 8? Well, if you want to know, then you are in the right place. In this tutorial, we are about to use a stripe/stripe-php module to handle payment gateway integration. It offers a robust solution for making flawless payments in PHP based applications.

 

Laravel 8 Stripe Payment Gateway

 

 

 

 

 

 

 

 

I believe at the end of this Stripe payment gateway tutorial, i will be able to explain all the Nitty-Gritty adequately.

Stipe is a noted and authentic payment gateway used for making online payments throughout the world. Managing things in Stripe is easy; it’s user-centric dashboard allows you to handle situations pretty quickly.

It doesn’t make you are solicitous when it comes to handling transactions and payment. It also gives you access for the testing account and prevents real payment from deteriorating.

However, there are many other payment gateways available. On one i made the tutorial earlier, How to Integrate Paypal Payment Gateway in Laravel.

I reckon on this stripe payment gateway, without wasting much time, let’s start this tutorial.

Laravel Stripe Payment Gateway Example

Please follow all the processes respectively to know the nitty-gritty of how to integrate Stripe Payment Gateway in the Laravel 8 application.

Evoke Laravel Application

In general, we start by installing a fresh new laravel application. You need to execute the below command to manifest the new laravel application.

composer create-project laravel/laravel laravel-stripe-example --prefer-dist
 

Afterward, move inside the newly installed application.

cd laravel-stripe-example
 

Establish stripe-php Package

This is a required step of this tutorial, and you must have composer installed on your development machine. We have to install the stripe-php plugin for making easy payments in laravel.

composer require stripe/stripe-php
 

Configure Stripe Public & Secret API Keys

To make the connection between laravel and Stripe payment gateway,
we have to define the Stripe Publishable and Secret key inside the .env file. As we register the Stripe API keys in the env file, consensus will be made between them.

  • Go to the Stripe website, register, and create your development account.
  • Get the Public and Secret API key from your account.
  • To restrain from making the real transaction, operate with a test account.
STRIPE_KEY=pk_test_51H7bbSE2RcKvfXD4DZhuhig
STRIPE_SECRET=sk_test_51H7bbSE2RcKvfXD4zKzr
 

Configure Routes

We have to create the two routes that simultaneously handle GET and POST requests in the Laravel Stripe controller for managing Stripe Payments.

name('stripe.payment');
 

Set Up Stripe Payment Controller

Run command to create a StripeController, in here we will write the entire memoir for handling the payments.

php artisan make:controller StripeController
 

Insert the following code in app/Http/Controllers/StripeController.php file.

 100 * 150,
                "currency" => "inr",
                "source" => $request->stripeToken,
                "description" => "Making test payment." 
        ]);
  
        Session::flash('success', 'Payment has been successfully processed.');
          
        return back();
    }
}
 

Create Stipe Form and Validation

In this final step, we will be creating the form that accepts the card details along with the some validation rules to validate the card information.

Create a home.blade.php file, in here insert the following code altogether.


Laravel - Integrate Stripe Payment Gateway Example
	
        .container {
            margin-top: 40px;
        }
        .panel-heading {
        display: inline;
        font-weight: bold;
        }
        .flex-table {
            display: table;
        }
        .display-tr {
            display: table-row;
        }
        .display-td {
            display: table-cell;
            vertical-align: middle;
            width: 55%;
        }
    Payment Details@if (Session::has('success'))×{{ Session::get('success') }}@endif@csrfName on Card Card Number CVC Expiration Month Expiration Year Fix the errors before you begin.Pay Now (₹100)
 

To run the application you have to evoke the following command:

php artisan serve
 

Once the application invoked, you can test the app with the following URL:

http://127.0.0.1:8000/stripe-payment
 

You can use the following card details for testing purpose, if all this is not enough then you can test more card numbers and other information to make sure your integration works as planned.

Number Brand CVC Date
4242424242424242 Visa Any 3 digits Any future date
4000056655665556 Visa (debit) Any 3 digits Any future date
5555555555554444 Mastercard Any 3 digits Any future date
2223003122003222 Mastercard (2-series) Any 3 digits Any future date
5200828282828210 Mastercard (debit) Any 3 digits Any future date
5105105105105100 Mastercard (prepaid) Any 3 digits Any future date
378282246310005 American Express Any 4 digits Any future date
371449635398431 American Express Any 4 digits Any future date
6011111111111117 Discover Any 3 digits Any future date
6011000990139424 Discover Any 3 digits Any future date
3056930009020004 Diners Club Any 3 digits Any future date
36227206271667 Diners Club (14 digit card) Any 3 digits Any future date
3566002020360505 JCB Any 3 digits Any future date
6200000000000005 UnionPay Any 3 digits Any future date

The Final Words

Eventually, without any recklessness, we have finished this basic tutorial of Laravel and Stripe Payment Gateway. In this tutorial, we have learned things on three basic levels, creating a laravel app from starting, registering stripe public and secret API key in laravel and, integrating stripe payment gateway in laravel application.

Theoretically, we unfolded only a few chapters of payment gateway integration in this tutorial. However, there are many things yet to be done. But one thing is for sure you are good to go with this, especially if you are a beginner.

If you liked my intensive efforts, then please do share this tutorial with others as well, I would be grateful to you. Have a good day. Keep coding.

Source: Positronx
Share: