Click Below to subscribe

How to Integrate Stripe Connect with Laravel 2022

Stripe Connect integrates quickly with any payment platform to easily accept money and payout third parties.

In this article, we will integrate stripe connect with our laravel project.

1. Let's create a new laravel project.

composer create-project laravel/laravel laravel-stripe-connect

2. Install stripe-php package.

composer require stripe/stripe-php

3. Create a stripe.php file inside the config folder and add this code.


return [
    'api_keys' => [
        'secret_key' => env('STRIPE_SECRET_KEY', null)  // Secret KEY:
    'client_id' => env('STRIPE_CLIENT_ID', null),       // Client ID:
    'redirect_uri' => env('STRIPE_REDIRECT_URI', null), // Redirect Uri
    'authorization_uri' => ''

4. In your environment file(.env). create these environment variables.


5. Now, we need to update these environment variables. let's go to stripe Settings and add your redirect url in the Redirects section. copy your client id and update it in your .env file. 

Note:- For sandbox client id, click on test mode option on the stripe dashboard.

6. Now, in the stripe dashboard click on Developers. here click on API keys. Copy your secret key and update it in your .env file.

Note:- For sandbox keys, click on test mode option on the stripe dashboard.

7. Next we need to create a button for authorization. create a file index.blade.php inside resources/views directory.

<div class='row'>
    <div class='col d-flex align-items-center justify-content-center'>
        <div class='card mt-5' style='width: 18rem;'>
            <a href='{{ $connectUri }}'>
                <img src="{{ asset('images/connect-purple.png') }}" class='img-thumbnail' alt='Connect With Stripe' />

Note:- Checkout github repo -

8. Create a Controller

php artisan make:controller PaymentController



namespace App\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Stripe\OAuth;
use Stripe\Stripe;
use Stripe\StripeClient;

class PaymentController extends Controller
    private $stripe;
    public function __construct()
        $this->stripe = new StripeClient(config('stripe.api_keys.secret_key'));

    public function index()
        $queryData = [
            'response_type' => 'code',
            'client_id' => config('stripe.client_id'),
            'scope' => 'read_write',
            'redirect_uri' => config('stripe.redirect_uri')
        $connectUri = config('stripe.authorization_uri').'?'.http_build_query($queryData);
        return view('index', compact('connectUri'));

    public function redirect(Request $request)
        $token = $this->getToken($request->code);
        if(!empty($token['error'])) {
            $request->session()->flash('danger', $token['error']);
            return response()->redirectTo('/');
        $connectedAccountId = $token->stripe_user_id;
        $account = $this->getAccount($connectedAccountId);
        if(!empty($account['error'])) {
            $request->session()->flash('danger', $account['error']);
            return response()->redirectTo('/');
        return view('account', compact('account'));

    private function getToken($code)
        $token = null;
        try {
            $token = OAuth::token([
                'grant_type' => 'authorization_code',
                'code' => $code
        } catch (Exception $e) {
            $token['error'] = $e->getMessage();
        return $token;

    private function getAccount($connectedAccountId)
        $account = null;
        try {
            $account = $this->stripe->accounts->retrieve(
        } catch (Exception $e) {
            $account['error'] = $e->getMessage();
        return $account;

9. Open routes/web.php


use App\Http\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;

| 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('/',         [PaymentController::class, 'index']);
Route::get('/redirect', [PaymentController::class, 'redirect']);

10.  Finally open your project in the browser and click on the button.


Checkout my full Stripe Connect example.

If you facing any issues. please post a comment. I will be happy to help you,

Leave Your Comment