Stripe Connect
Below are the php codes to implement the stripe connect process in any platform.
Please add the following routes.
Route::get('/stripe/connect', [StripeController::class, 'viewStripeConnectPage'])->name('stripe.connect');
Route::get('/create/stripe/connect', [StripeController::class, 'generateStripeConnect'])->name('create.stripe.connect');
Route::get('/stripe/connect/refresh', [StripeController::class, 'stripeConnectRefresh'])->name('stripe.connect.refresh');
Route::get('/stripe/connect/return', [StripeController::class, 'stripeConnectReturn'])->name('stripe.connect.return');
StripeController
will look like below.
<?php
namespace App\Http\Controllers\Services;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
class StripeController extends Controller
{
public function generateStripeConnect()
{
$stripe = new \Stripe\StripeClient('sk_test_51MmGiGHMOCsDa4DfO8dHJ8nP0D4S07GVFknrZgSUqNoJkaCGCZ28NHYkc6QfqtU33JY513NipZivmqd4vtubFjKH00aVYBrOrk');
$account = $stripe->accounts->create(['type' => 'standard']);
$accountLinks = $stripe->accountLinks->create([
'account' => $account->id,
'refresh_url' => route('stripe.connect.refresh'),
'return_url' => route('stripe.connect.return'),
'type' => 'account_onboarding',
]);
if(isset($accountLinks->url))
{
$accountUrl = $accountLinks->url;
return redirect($accountUrl);
}
}
public function viewStripeConnectPage()
{
return view('public.stripe-connect');
}
public function stripeConnectRefresh()
{
Session::flash('message', 'Stripe link expired. Please generate again!');
Session::flash('alert-class', 'alert-danger');
return redirect()->route('stripe.connect');
}
public function stripeConnectReturn()
{
Session::flash('message', 'On boarded successfully! You can login now');
Session::flash('alert-class', 'alert-success');
return redirect()->route('stripe.connect');
}
}
Stripe connect view page will be in the following structure.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blink</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
@if(Session::has('message'))
<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>
@endif
<div class="card">
<div class="card-body">
<h4 class="card-title">Stripe connect</h4>
<p class="card-text">Stripe onboarding</p>
<a href="{{ route('create.stripe.connect') }}" class="card-link">Connect stripe account</a>
<a href="https://dashboard.stripe.com/login" class="card-link">Stripe Login</a>
</div>
</div>
</div>
</body>
</html>
Â