Today, laravel 8 stripe integration is our main topic. We will use stripe payment gateway integration in laravel 8. you will learn laravel 8 stripe payment gateway example. step by step explain laravel 8 payment integration stripe example.

You need to create stripe developer account and need to get api key and secret from there. Then we will use stripe/stripe-php composer library for stripe payment gateway in laravel 8. I write step by step integration for stripe payment gateway.

Stripe is a very popular and secure internet payment gateway company which helps to accept payment worldwide. Stripe provide really nice development interface to start and you don’t have to pay subscription charges to learn it provides free developer account, before starting to code in your app.

I will give you example from scratch to implement stripe payment gateway in laravel 8 application. You just need to follow few step to get full example to pay.

Step 1: Install Laravel 8

I am going to explain step by step from scratch so, we need to get fresh Laravel 8 application using bellow command, So open your terminal OR command prompt and run bellow command:

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

Step 2: Install stripe-php Package

In this step we need to install stripe-php via the Composer package manager, so one your terminal and fire bellow command:

composer require stripe/stripe-php

Step 3: Set Stripe API Key and SECRET

Now, we need to set stripe key and secret. so first you can go on Stripe website and create development stripe account key and secret and add bellow:

.env

STRIPE_KEY=pk_test_reFxwbsm9cdCKASdTfxAR
STRIPE_SECRET=sk_test_oQMFWteJiPd4wj4AtgApY

Step 4: Create Routes

In this step, we will create two routes for get request and another for post request. So, let’s add new route on that file.

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\StripePaymentController;

/*
|--------------------------------------------------------------------------
| 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', [StripePaymentController::class, 'stripe']);
Route::post('stripe', [StripePaymentController::class, 'stripePost'])->name('stripe.post');

Step 5: Create Controller File

in next step, now we have create new controller as StripePaymentController and write both method on it like as bellow, So let’s create both controller:

app/Http/Controllers/StripePaymentController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use Stripe;

class StripePaymentController 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\Stripe::setApiKey(env('STRIPE_SECRET'));
        Stripe\Charge::create ([
                "amount" => 100 * 100,
                "currency" => "usd",
                "source" => $request->stripeToken,
                "description" => "Test payment from itsolutionstuff.com." 
        ]);

        Session::flash('success', 'Payment successful!');

        return back();
    }
}

#laravel #php #web-development #stripe #programming

Laravel 8 Stripe Payment Gateway Integration Example
47.15 GEEK