Create a controller to manage on-boarding process. The example below registers an Express account for the store and is for platforms with the frontend hosted within Laravel. API led applications would take a slightly different approach.
namespaceApp\Http\Controllers;useApp\Http\Controllers\Controller;useApp\Models\Store;useIlluminate\Http\RedirectResponse;useIlluminate\Http\Request;useURL;classStripeControllerextendsController{/** * Creates an onboarding link and redirects the store there. * * @paramRequest $request * @returnRedirectResponse */publicfunctionboard(Request $request):RedirectResponse {return$this->handleBoardingRedirect($request->store()); }/** * Handles returning from completing the onboarding process. * * @paramRequest $request * @returnRedirectResponse */publicfunctionreturning(Request $request):RedirectResponse {return$this->handleBoardingRedirect($request->store()); }/** * Handles refreshing of onboarding process. * * @paramRequest $request * @returnRedirectResponse */publicfunctionrefresh(Request $request):RedirectResponse {return$this->handleBoardingRedirect($request->store()); }/** * Handles the redirection logic of Stripe onboarding for the given store. Will * create account and redirect store to onboarding process or redirect to account * dashboard if they have already completed the process. * * @paramStore $Store * @returnRedirectResponse */privatefunctionhandleBoardingRedirect(Store $Store):RedirectResponse {// Redirect to dashboard if onboarding is already completed.if ($store->hasStripeAccount()&& $store->hasCompletedOnboarding()) {return $store->redirectToAccountDashboard(); }// Delete account if already exists and create new express account with // weekly payouts. $store->deleteAndCreateStripeAccount('express', ['settings'=> ['payouts'=> [ 'schedule'=> [ 'interval'=>'weekly','weekly_anchor'=>'friday', ] ] ] ]);// If you wish to acceess the new connected account via the related model// you must refresh the model using the refresh() model method. $store->refresh();// Redirect to Stripe account onboarding, with return and refresh url, otherwise.return $store->redirectToAccountOnboarding(URL::to('/api/stripe/return?api_token='. $store->api_token),URL::to('/api/stripe/refresh?api_token='. $store->api_token)); }}
JSON API Approach
If your application is powered by a JSON API and your redirects will be happening on a separate SPA Frontend, then this approach is the one to use.